I have the following Apache druid native query:
{
“dimensions”: [“idChat”,“messageId”, “noteChatId”,“countMessage”,“dateFinish”],
“intervals”: “2020-09-01T06:00:00/2020-12-02T05:59:59”,
“granularity”: “all”,
“queryType”: “groupBy”,
“dataSource”: {
“type”: “join”,
“left”:“reporte_detalle_resumen_chat”
“right”:{
“type”:“query”,
“query”:{
“dataSource”: “reporte_detalle_resumen_chat”,
“dimensions”: [“idChat”,“messageId”],
“intervals”: “2020-09-01T06:00:00/2020-12-02T05:59:59”,
“granularity”: “all”,
“queryType”: “groupBy”,
“aggregations”: [{ “type”: “count”, “name”: “count_m”, “fieldName”: “idChat”}],
“filter”: {“type”: “in”, “dimension”: “idCampaign”, “values”: [12]}
},
“limitSpec”: { “type”: “default”, “limit”: 5000, “columns”: [“idChat”] },
},
“rightPrefix”: “r.”,
“condition”: “idChat == “r.idChat””,
“joinType”: “INNER”
},
“aggregations”: [{ “type”: “count”, “name”: “count_m”, “fields”: [“r.count_m”],“round”: true}],
“limitSpec”: { “type”: “default”, “limit”: 5000, “columns”: [“idChat”] },
“filter”: {
“type”: “and”,
“fields”: [
{“type”: “in”, “dimension”: “idCampaign”, “values”: [12]},
{“type”: “in”, “dimension”: “idCampaign”, “values”: [12]},
// { “type”:“not”, “field”:{“type”: “columnComparison”, “dimensions”: [“count_m”, “countMessage”]} }
]
},
“postAggregations”:[{
“type”: “expression”, “name”: “average_hits_per_page”, “expression”: “count_m / countMessage”
}],
“having”:
{
“type”: “not”,
“havingSpec”:
{
“type”: “equalTo”,
“aggregation”: “average_hits_per_page”,
“value”: 2
}
}
}
and want to take it to Pydruid
aggregator = {"count_m":count("r.count_m")}
filter_campaign = Filter(type="in", dimension="idCampaign", values=campaigns)
postaggregation = {'average':(Field("count_m")/Field("countMessage"))}
having = Having(**{
"type": "not",
"havingSpec":
{
"type": "equalTo",
"aggregation": "average",
"value": 1
}
})
aggregator_count = {"count_m":count("idChat")}
load_data_source().groupby(
dimensions=["idChat", "messageId", "noteChatId", "countMessage", "dateFinish"],
intervals=intervals,
granularity="all",
datasource={
'type': 'join',
'left': 'reporte_detalle_resumen_chat',
'right': load_data_source().groupby(
datasource='reporte_detalle_resumen_chat',
dimensions=["idChat", "messageId"],
granularity='all',
intervals=intervals,
filter=filter_campaign,
aggregations=aggregator_count
).query_dict,
'rightPrefix': 'r.',
'condition': 'idChat== \'r.idChat\'',
'joinType': 'INNER'
},
aggregations=aggregator,
filter=filter_campaign,
post_aggregations=postaggregation,
having=having
)
and it gives me the following error: