grafadruid/druid-grafana

Not able to run a scan query

Closed this issue · 4 comments

I'm trying to calculate PSI (Population Stability Index) and have got a query which works in druid and I'm trying to get the same one to work in grafana (using druid-grafana plugin) but I'm getting json unmarshall error:
json: cannot unmarshal string into Go value of type struct { Typ string "json:\"type,omitempty\"" }

Here is the query I'm using:

{
	"queryType": "scan",
	"dataSource": {
		"type": "join",
		"rightPrefix": "model2.",
		"condition": "TIME_FOR_JOIN == \"model2.TIME_FOR_JOIN\"",
		"joinType": "INNER",
		"left": {
			"type": "query",
			"query": {
				"queryType": "timeseries",
				"dataSource": {
					"type": "query",
					"query": {
						"queryType": "topN",
						"dataSource": "dc_94b4f5fdfde940979b79c50539d8322a_b42fde98efed4e638a0016b34b3c10cf_dataset_pre",
						"granularity": "day",
						"dimension": "string_value",
						"intervals": "2022-10-07T00:00:00Z/P1W",
						"threshold": 100,
						"metric": "count",
						"aggregations": [{
							"type": "longSum",
							"fieldName": "count",
							"name": "count"
						}],
						"filter": {
							"type": "and",
							"fields": [{
									"type": "selector",
									"dimension": "__truera_split_name__",
									"value": "prod"
								},
								{
									"type": "selector",
									"dimension": "column_name",
									"value": "addressState"
								},
								{
									"type": "interval",
									"dimension": "__time",
									"intervals": [
										"2022-10-07T00:00:00Z/P1W"
									]
								},
								{
									"type": "selector",
									"dimension": "__truera_model_id__",
									"value": "296f8b0c-1ffe-419d-9d5c-4b6b94fff50e"
								}
							]
						}
					}
				},
				"intervals": "2022-10-07T00:00:00Z/P1W",
				"granularity": "day",
				"aggregations": [{
						"type": "expression",
						"name": "count_arr_model1",
						"fields": [
							"count"
						],
						"accumulatorIdentifier": "__acc",
						"initialValue": "ARRAY<LONG>[]",
						"initialCombineValue": "ARRAY<LONG>[]",
						"fold": "array_append(\"__acc\", \"count\")",
						"combine": "array_concat(\"__acc\", \"count_arr_model1\")",
						"maxSizeBytes": 1024
					},
					{
						"type": "expression",
						"name": "cat_arr_model1",
						"fields": [
							"string_value"
						],
						"accumulatorIdentifier": "__acc",
						"initialValue": "ARRAY<STRING>[]",
						"initialCombineValue": "ARRAY<STRING>[]",
						"fold": "array_append(\"__acc\", \"string_value\")",
						"combine": "array_concat(\"__acc\", \"cat_arr_model1\")",
						"maxSizeBytes": 1024
					}
				],
				"postAggregations": [{
					"type": "expression",
					"name": "TIME_FOR_JOIN",
					"expression": "timestamp_format(timestamp_floor(\"time\",'P1D',null,'UTC'))"
				}],
				"context": {
					"timestampResultField": "time"
				}
			}
		},
		"right": {
			"type": "query",
			"query": {
				"queryType": "timeseries",
				"dataSource": {
					"type": "query",
					"query": {
						"queryType": "topN",
						"dataSource": "dc_94b4f5fdfde940979b79c50539d8322a_b42fde98efed4e638a0016b34b3c10cf_dataset_pre",
						"granularity": "day",
						"dimension": "string_value",
						"intervals": "2022-10-07T00:00:00Z/P1W",
						"threshold": 100,
						"metric": "count",
						"aggregations": [{
							"type": "longSum",
							"fieldName": "count",
							"name": "count"
						}],
						"filter": {
							"type": "and",
							"fields": [{
									"type": "selector",
									"dimension": "__truera_split_name__",
									"value": "prod"
								},
								{
									"type": "selector",
									"dimension": "column_name",
									"value": "addressState"
								},
								{
									"type": "interval",
									"dimension": "__time",
									"intervals": [
										"2022-10-07T00:00:00Z/P1W"
									]
								},
								{
									"type": "selector",
									"dimension": "__truera_model_id__",
									"value": "36057d82-d387-47cf-ba88-4f4b01ec6b9d"
								}
							]
						}
					}
				},
				"intervals": "2022-10-07T00:00:00Z/P1W",
				"granularity": "day",
				"aggregations": [{
						"type": "expression",
						"name": "count_arr_model2",
						"fields": [
							"count"
						],
						"accumulatorIdentifier": "__acc",
						"initialValue": "ARRAY<LONG>[]",
						"initialCombineValue": "ARRAY<LONG>[]",
						"fold": "array_append(\"__acc\", \"count\")",
						"combine": "array_concat(\"__acc\", \"count_arr_model2\")",
						"maxSizeBytes": 1024
					},
					{
						"type": "expression",
						"name": "cat_arr_model2",
						"fields": [
							"string_value"
						],
						"accumulatorIdentifier": "__acc",
						"initialValue": "ARRAY<STRING>[]",
						"initialCombineValue": "ARRAY<STRING>[]",
						"fold": "array_append(\"__acc\", \"string_value\")",
						"combine": "array_concat(\"__acc\", \"cat_arr_model2\")",
						"maxSizeBytes": 1024
					}
				],
				"postAggregations": [{
					"type": "expression",
					"name": "TIME_FOR_JOIN",
					"expression": "timestamp_format(timestamp_floor(\"time\",'P1D',null,'UTC'))"
				}],
				"context": {
					"timestampResultField": "time"
				}
			}
		}
	},
	"intervals": "2022-10-07T00:00:00Z/P1W",
	"granularity": "day",
	"virtualColumns": [{
		"type": "expression",
		"name": "psi",
		"expression": "categoricalDrift(\"cat_arr_model1\", \"model2.cat_arr_model2\", \"count_arr_model1\", \"model2.count_arr_model2\", 'PSI')",
		"outputType": "DOUBLE"
	}]
}

Can someone look into this query and suggest the change/mistake made by me?

@jbguerraz - Can you help here?

Liked issue from go-druid: grafadruid/go-druid#77

Hello @saketbairoliya2
I've answered on grafadruid/go-druid#77
Maybe we can close this one ?