代码之家  ›  专栏  ›  技术社区  ›  Pratik Khadloya

Apache Druid sql查询转换为基于json的查询

  •  6
  • Pratik Khadloya  · 技术社区  · 6 年前

    我正在尝试将下面的druid sql查询转换为druid json查询,因为我的一列是一个多值维度,druid不支持sql样式的查询。

    我的sql查询:

    SELECT date_dt, source, type_labels, COUNT(DISTINCT unique_p_hll)
      FROM "test"
    WHERE 
      type_labels = 'z' AND
      (a_id IN ('a', 'b', 'c') OR b_id IN ('m', 'n', 'p'))
    GROUP BY date_dt, source, type_labels;
    

    unique_p_hll 是带有uniques的hll列。

    我提出的druid json查询如下:

    {
      "queryType": "groupBy",
      "dataSource": "test",
      "granularity": "day",
      "dimensions": ["source", "type_labels"],
      "limitSpec": {},
      "filter": {
        "type": "and",
        "fields": [
          { "type": "selector", "dimension": "type_labels", "value": "z" },   
          { "type": "or", "fields": [
            { "type": "in", "dimension": "a_id", "values": ["a", "b", "c"] },
            { "type": "in", "dimension": "b_id", "values": ["m", "n", "p"] }
          ]}
        ]
      },
      "aggregations": [
        { "type": "longSum", "name": "unique_p_hll", "fieldName": "p_id" }
      ],
      "intervals": [ "2018-08-01/2018-08-02" ]
    }
    

    但是json查询似乎返回了空结果集。 我可以在Pivot UI中正确地看到输出。通过数组列 type_labels 值显示为 {"array_element": "z"} 而不是简单地 "z" .

    1 回复  |  直到 6 年前
        1
  •  0
  •   yurmix    5 年前

    查询是返回空字符串,还是返回带零记录的格式化JSON?

    如果是前者,我可以建议调试此问题的几条线索:

    1. 确保查询已正确发送到代理,如中所示 Druid's query tutorial :

    curl -X 'POST' -H 'Content-Type:application/json' -d @query-file.json http://<BROKER-IP>:<BROKER-PORT>/druid/v2?pretty

    1. 此外,请查看代理的日志以了解错误。
    推荐文章