Как добавить поля значения Post Aggregation в качестве Metric в Druid io

Я использую друид IO 0.9.0. Я пытаюсь добавить поле после агрегации в качестве метрической спецификации. Мое намерение состоит в том, чтобы показать значение поля после агрегации, аналогичное показу метрики (меры) (в Druid io с использованием Pivot).

Мой файл схемы 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));

Можно ли указать на мою ошибку?

1 ответ

Я не знаю, можете ли вы сделать это в своей спецификации приема (я бы на самом деле хотел знать, можем ли мы!), Но вы можете добавить свои пост-агрегаты в конфигурацию сводки. Из того, что я понимаю, пост-агрегации на самом деле являются частью запроса друида.

Сначала создайте файл конфигурации с помощью 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)

Наконец, запустите Pivot с --config флаг

pivot --config config.yaml

Надеюсь, это поможет немного!:)

Другие вопросы по тегам