簡體   English   中英

使用查詢時,Druid Native Query 和 Druid SQL 之間存在計數差異

[英]There's a count difference between Druid Native Query and Druid SQL when using query

我對德魯伊查詢有疑問。

我想以小時為單位獲取數據計數。

所以,我像這樣使用了德魯伊 SQL。

SELECT TIME_FLOOR(__time, 'PT1H') AS t, count(1) AS cnt FROM mydatasource GROUP BY 1

然后我得到了這樣的回應。

[
  {
    "t": "2022-08-31T09:00:00.000Z",
    "cnt": 12427
  },
  {
    "t": "2022-08-31T10:00:00.000Z",
    "cnt": 16693
  },
  {
    "t": "2022-08-31T11:00:00.000Z",
    "cnt": 16694
  },
  ...

但是,當使用這樣的本機查詢時,

{
  "queryType": "timeseries",
  "dataSource": "mydatasource",
  "intervals": "2022-08-31T07:01Z/2022-09-01T07:01Z",
  "granularity": {
    "type": "period",
    "period": "PT1H",
    "timeZone": "Etc/UTC"
  },
  "aggregations": [
    {
      "name": "count",
      "type": "longSum",
      "fieldName": "count"
    }
  ],
  "context": {
    "skipEmptyBuckets": "true"
  }
}

有不同的結果。

[
  {
    "timestamp": "2022-08-31T09:00:00.000Z",
    "result": {
        "count": 1288965
    }
  },
  {
    "timestamp": "2022-08-31T10:00:00.000Z",
    "result": {
        "count": 1431215
    }
  },
  {
    "timestamp": "2022-08-31T11:00:00.000Z",
    "result": {
        "count": 1545258
    }
  },
  ...

我想使用 Native Query 的結果。

我的德魯伊 SQL 查詢有什么問題?

如何創建查詢以獲取本機查詢結果?


我發現有什么不同。

使用 longSum 類型聚合時,我得到的結果類似於本機查詢。

所以,我想知道如何使用 sql 查詢如下聚合。

"aggregations": [
  {
    "type": "longSum",
    "name": "count",
    "fieldName": "count"
  }
]

我找到了解決方案。

像這樣查詢。

SELECT TIME_FLOOR(__time, 'PT1H') AS t, sum("count") AS cnt FROM mydatasource GROUP BY 1

鑒於您的數據源有一個“計數”列,我假設它來自使用匯總的攝取。 這意味着原始原始行已被聚合,並且“計數”列包含匯總到每個聚合行中的原始行數。

本機查詢在“count”列上使用 longSum function。 您使用的原始 SQL 只是計算聚合行。

所以是的,獲取原始行數的正確方法是SUM("count")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM