【问题标题】:Druid - Order data by timestamp columnDruid - 按时间戳列排序数据
【发布时间】:2017-09-10 06:10:39
【问题描述】:

我已经设置了一个Druid 集群来从Kafka 提取实时数据。

问题

  1. Druid 是否支持获取按timestamp 排序的数据?例如,假设我需要从数据源 X 中检索最新的 10 个条目。我可以使用包含时间戳字段的LimitSpec(在Query JSON 中)来执行此操作吗?还是有其他更好的选择支持Druid

提前致谢。

【问题讨论】:

    标签: time-series apache-kafka druid


    【解决方案1】:

    获取未聚合的行

    要获取未聚合的行,您可以使用"queryType: "select" 进行查询。

    选择查询在需要分页时也很有用 - 它们允许您设置页面大小,并自动返回分页标识符以供将来查询使用。

    在这个例子中,如果我们只想要前 10 行,我们可以传入"pagingSpec": { "pageIdentifiers": {}, "threshold": 10 }

    按时间戳排序

    要按“时间戳”对这些行进行排序,您可以传入"descending": "true"。 看起来大多数 Druid 查询类型都支持 descending 属性。

    示例查询:

    {
      "queryType": "select",
      "dataSource": "my_data_source",
      "granularity": "all",
      "intervals": [ "2017-01-01T00:00:00.000Z/2017-12-30T00:00:00.000Z" ],
      "descending": "true",
      "pagingSpec": { "pageIdentifiers": {}, "threshold": 10 }
    }
    

    Docs on "select" type queries

    【讨论】:

      【解决方案2】:

      您可以使用 group by 查询来执行此操作,因此按 __time 分组为 extraction function 然后将粒度设置为 all 并使用 limitSpec 进行排序/限制这将起作用。现在,如果您想使用时间序列查询,获取最新的 10 则更加棘手。一种方法是将粒度设置为所需的粒度,例如小时,然后从最近的点开始将间隔设置为 10H时间。这听起来说起来容易做起来难。除非您遇到重大的性能问题,否则我将采用第一种方式。

          {
        "queryType": "groupBy",
        "dataSource": "wikiticker",
        "granularity": "all",
        "dimensions": [
          {
            "type": "extraction",
            "dimension": "__time",
            "outputName": "extract_time",
            "extractionFn": {
              "type": "timeFormat"
            }
          },
        ],
        "limitSpec": {
          "type": "default",
          "limit": 10,
          "columns": [
            {
              "dimension": "extract_time",
              "direction": "descending"
            }
          ]
        },
        "aggregations": [
          {
            "type": "count",
            "name": "$f2"
          },
          {
            "type": "longMax",
            "name": "$f3",
            "fieldName": "added"
          }
        ],
        "intervals": [
          "1900-01-01T00:00:00.000/3000-01-01T00:00:00.000"
        ]
      }
      

      【讨论】:

      • Slim 你能写一个示例查询吗?
      猜你喜欢
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-06
      • 2011-08-22
      • 2012-10-18
      相关资源
      最近更新 更多