我正在使用德鲁伊创建用于生成报告的UI。对于脚本,我使用以下代码:
{
"type" : "doubleSum",
"name" : "impressions",
"fieldName" : "impressions"
},
{
"type" : "doubleSum",
"name" : "clicks",
"fieldName" : "clicks"
},
{
"type" : "doubleSum",
"name" : "pvconversions",
"fieldName" : "pvconversions"
},
{
"type" : "doubleSum",
"name" : "pcconversions",
"fieldName" : "pcconversions"
}
我还需要两个字段:
Total Conversions = pvconversions+pcconversions
CTR = Clicks / Impressions
我无法找到关于如何编写它们的任何事情。 任何人都可以提供帮助。
谢谢
答案 0 :(得分:4)
您的问题可以使用聚合和postAggregations解决,如下面的代码段:
{
"queryType":"timeseries",
"dataSource":"data",
"granularity":"hour",
"descending":"false",
"aggregations":[
{"type":"doubleSum", "name":"sum-pvconversions", "fieldName":"pvconversions"},
{"type":"doubleSum", "name":"sum-pcconversions", "fieldName":"pcconversions"},
{"type":"doubleSum", "name":"sum-clicks", "fieldName":"clicks"},
{"type":"doubleSum", "name":"sum-impressions", "fieldName":"impressions"}
],
"postAggregations":[
{
"type":"arithmetic",
"name":"Conversions",
"fn":"+",
"fields":[
{"type":"fieldAccess", "name":"postAgg-proceed", "fieldName":"sum-pvconversions"},
{"type":"fieldAccess", "name":"postAgg-numbers", "fieldName":"sum-pcconversions"}
]
},
{
"type":"arithmetic",
"name":"CTR",
"fn":"/",
"fields":[
{"type":"fieldAccess", "name":"postAgg-click", "fieldName":"sum-clicks"},
{"type":"fieldAccess", "name":"postAgg-impression", "fieldName":"sum-impressions"}
]
}
],
"intervals":["2016-08-22T01/2016-08-29T03"],
"context":{
"skipEmptyBuckets":"true"
}
}
答案 1 :(得分:1)
您可以在timeseries查询中使用聚合来完成此操作。这不是你想要的吗?
答案 2 :(得分:0)
您必须在查询中使用帖子聚合。 来自德鲁伊的文件
后聚合是指在聚合值上发生的处理规范,因为它们来自德鲁伊。如果您将后聚合作为查询的一部分包含在内,请确保包含后聚合器所需的所有聚合器
例如,要计算点击率,这里是帖子聚合:
"postAggregations" : [{
"type" : "arithmetic",
"name" : "average",
"fn" : "*",
"fields" : [
{ "type" : "arithmetic",
"name" : "CTR",
"fn" : "/",
"fields" : [
{ "type" : "fieldAccess", "name" : "clicks", "fieldName" : "clicks" },
{ "type" : "fieldAccess", "name" : "impressions", "fieldName" : "impressions" }
]
}
答案 3 :(得分:0)
Druid中的聚合只能用于聚合查询,如timeseries,topN和groupBy。
如果您只是将列中的值与时间进行聚合,最简单的方法是编写时间序列查询。
例如,
{
"queryType": "timeseries",
"dataSource": "<datasource name>",
"granularity": "day",
"aggregations": [
<Your aggregations here>
],
"intervals": [ <Time interval (from/to)> ]
}