Java 如何在Druid io中添加聚合后值字段作为度量

Java 如何在Druid io中添加聚合后值字段作为度量,java,druid,Java,Druid,我正在使用德鲁伊io 0.9.0。我试图添加一个聚合后字段作为度量规范。我的意图是显示聚合后字段的值,类似于度量(度量)的显示方式(在使用Pivot的Druid io中) 我的Druid io模式文件是 { "dataSources" : { "NPS1112" : { "spec" : { "dataSchema" : { "dataSource" : "NPS1112",

我正在使用德鲁伊io 0.9.0。我试图添加一个聚合后字段作为度量规范。我的意图是显示聚合后字段的值,类似于度量(度量)的显示方式(在使用Pivot的Druid io中)

我的Druid io模式文件是

    {
      "dataSources" : {
        "NPS1112" : {
          "spec" : {
            "dataSchema" : {
              "dataSource" : "NPS1112",
              "parser" : {
                "type" : "string",
                "parseSpec" : {
                  "timestampSpec" : {
                    "column" : "timestamp",
                    "format" : "auto"
                  },
                  "dimensionsSpec" : {
                    "dimensions" : ["dimension1","dimension2","dimension3"],
                     "dimensionExclusions" : [
                      "timestamp",
                      "OverallRating",
                      "DeliveryTimeRating",
                      "ItemQualityRating",
                      "isPromoter",
                      "isDetractor"
                    ]
                  },
                  "format" : "json"
                }
              },
              "granularitySpec" : {
                "type" : "uniform",
                "segmentGranularity" : "hour",
                "queryGranularity" : "none"
              },
             "aggregations" : [
             { "type" : "count", "name" : "rows"},
             { "type" : "doubleSum", "name" : "CountOfPromoters", "fieldName" : "isPromoter" },
             { "type" : "doubleSum", "name" : "CountOfDetractor", "fieldName" : "isDetractor" }
            ],
            "postAggregations" : [
            { "type"   : "arithmetic",
              "name"   : "PromoterPercentage",
              "fn"     : "/",
              "fields" : [
                   { "type" : "fieldAccess", "name" : "CountOfPromoters", "fieldName" : "CountOfPromoters" },
                   { "type" : "fieldAccess", "name" : "rows", "fieldName" : "rows" }
                  ]
             },
             { "type"   : "arithmetic",
              "name"   : "DetractorPercentage",
              "fn"     : "/",
              "fields" : [
                   { "type" : "fieldAccess", "name" : "CountOfDetractor", "fieldName" : "CountOfDetractor" },
                   { "type" : "fieldAccess", "name" : "rows", "fieldName" : "rows" }
                  ]
             },
             { "type"   : "arithmetic",
              "name"   : "NPS",
              "fn"     : "-",
              "fields" : [
                   { "type" : "fieldAccess", "name" : "PromoterPercentage", "fieldName" : "PromoterPercentage" },
                   { "type" : "fieldAccess", "name" : "DetractorPercentage", "fieldName" : "DetractorPercentage" }
                  ]
             }
             ],
              "metricsSpec" : [
                {
                  "type" : "count",
                  "name" : "CountOfResponses"
                },
                {
                  "type" : "fieldAccess",
                  "name" : "CountOfPromoters"
                }
              ]
            },
            "ioConfig" : {
              "type" : "realtime"
            },
            "tuningConfig" : {
              "type" : "realtime",
              "maxRowsInMemory" : "10000",
              "intermediatePersistPeriod" : "PT10M",
              "windowPeriod" : "PT10M"
            }
          },
          "properties" : {
            "task.partitions" : "1",
            "task.replicants" : "1"
          }
        }
      },
      "properties" : {
        "zookeeper.connect" : "localhost",
        "druid.discovery.curator.path" : "/druid/discovery",
        "druid.selectors.indexing.serviceName" : "druid/overlord",
        "http.port" : "8200",
        "http.threads" : "4"
      }
    }
我使用java客户端发送字段的代码

          final Map<String,Object> obj = new HashMap<String, Object>();

          obj.put("timestamp", new DateTime().toString());

          obj.put("OverallRating", (ran.nextInt(high-low) + low));
          obj.put("DeliveryTimeRating", (ran.nextInt(high-low) + low));
          obj.put("ItemQualityRating", (ran.nextInt(high-low) + low));
          obj.put("isPromoter", ((ran.nextInt(high-low) + low)%2) == 0 ? 1 : 0);
          obj.put("isDetractor", ((ran.nextInt(high-low) + low)%2) == 0 ? 1 : 0);

          obj.put("dimension1", "dimension1-"+ (ran.nextInt(high-low) + low));
          obj.put("dimension2", "dimension2-"+ (ran.nextInt(high-low) + low));
          obj.put("dimension3", "dimension3-"+ (ran.nextInt(high-low) + low));
final Map obj=new HashMap();
对象put(“timestamp”,new DateTime().toString());
obj.put(“总体增长率”),(ran.nextInt(高-低)+低);
obj.put(“DeliveryTimeRating”,(ran.nextInt(高-低)+低));
obj.put(“ItemQualityRating”,(ran.nextInt(高-低)+低));
对象put(“isPromoter”,((ran.nextInt(高-低)+low)%2)==0?1:0);
对象put(“isDetractor”,((ran.nextInt(高-低)+低)%2)==0?1:0);
对象放置(“维度1”,“维度1-”+(ran.nextInt(高-低)+低));
对象放置(“维度2”,“维度2-”+(ran.nextInt(高-低)+低));
对象put(“dimension3”,“dimension3-”+(ran.nextInt(高-低)+低));

有人能指出我的错误吗。

我不知道你是否能在你的摄入规范中做到这一点(我真的想知道我们是否能做到!),但是你可以在pivot配置中添加你的帖子聚合。据我所知,帖子聚合实际上是druid查询的一部分

首先,使用pivot生成一个配置文件:

pivot --druid your.druid.broker.host:8082 --print-config --with-comments > config.yaml
然后修改config.yaml。语法非常不同,但是您可以非常轻松地组合聚合器。下面是config.yaml文件中提供的示例:

  # This is the place where you might want to add derived measures (a.k.a Post Aggregators).
  #
  # Here are some examples of possible derived measures:
  #
  # - name: ecpm
  #   title: eCPM
  #   expression: $main.sum($revenue) / $main.sum($impressions) * 1000
  #
  # - name: usa_revenue
  #   title: USA Revenue
  #   expression: $main.filter($country == 'United States').sum($revenue)
最后,使用
--config
标志运行pivot

pivot --config config.yaml
希望能有点帮助!:)