![](/img/trans.png)
[英]Apply aggregate function to certain columns using SQL in Apache Druid
[英]Apache Druid GroupBy Virtual columns
我正在嘗試在 Druid 本機查詢中執行 groupby 虛擬列,如下所示...
{
"queryType": "groupBy",
"dataSource": "trace_info",
"granularity": "none",
"virtualColumns": [
{
"type": "expression",
"name": "tenant",
"expression": "replace(array_offset(tags, array_offset_of(tagNames, 'tenant')), 'tenant:', '')"
},
{
"type": "expression",
"name": "rc",
"expression": "replace(array_offset(tags, array_offset_of(tagNames, 'row_count')), 'row_count:', '')"
}
],
"dimensions": [
"tenant"
],
"aggregations": [
{
"type": "longSum",
"name": "trc",
"fieldName": "rc"
}
],
...
...
...
"intervals": [
"..."
]
}
這給出了所有 row_counts 的 longsum 的單行,就好像 groupBy 列是 null。
我的用法是正確的還是德魯伊中的一個已知問題。 文檔說虛擬列可以像普通尺寸一樣使用,但是對於如何甚至缺少工作示例並不是很清楚。
謝謝! 帕尼
最新編輯...
進一步挖掘發現問題在於虛擬列上缺少“outputType”屬性。 奇怪,因為聚合器能夠自動檢測時間並正確計算長和,即使按結果分組是錯誤的。
"virtualColumns": [
{
"type": "expression",
"name": "tenant",
"expression": "replace(array_offset(tags, array_offset_of(tagNames, 'tenant')), 'tenant:', '')",
"outputType": "STRING"
},
{
"type": "expression",
"name": "rc",
"expression": "replace(array_offset(tags, array_offset_of(tagNames, 'row_count')), 'row_count:', '')"
"outputType": "LONG"
}
],
見上文(下文可能是解決問題的一種非高效方式)。
經過一些試驗和錯誤,我有一個使用提取尺寸的解決方法。 雖然不確定,但我懷疑這是 Druid 0.18.1 中的臨時問題。 希望對 VC 進行分組將在未來的構建中像宣傳的那樣工作。
{
"queryType": "groupBy",
"dataSource": "trace_info",
"granularity": "none",
"virtualColumns": [
{
"type": "expression",
"name": "tenant",
"expression": "replace(array_offset(tags, array_offset_of(tagNames, 'tenant')), 'tenant:', '')"
},
{
"type": "expression",
"name": "rc",
"expression": "replace(array_offset(tags, array_offset_of(tagNames, 'row_count')), 'row_count:', '')"
}
],
"dimensions": [
{
"type": "extraction",
"dimension": "tenant",
"outputName": "t",
"extractionFn": {
"type" : "substring", "index" : 1
}
}
],
"aggregations": [
{
"type": "longSum",
"name": "trc",
"fieldName": "rc"
}
],
...
...
...
"intervals": [
"..."
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.