Skip to content

Commit a69fb45

Browse files
authored
make backend as default parser (#1140)
1 parent 412e547 commit a69fb45

14 files changed

+368
-184
lines changed

.changeset/lemon-sloths-play.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'grafana-infinity-datasource': major
3+
---
4+
5+
Set the backend parser as the default parser for new queries. Existing queries with frontend parser should work as before. If broken, setting the parser to `Frontend` may help.

pkg/models/query.go

+6
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ func ApplyDefaultsToQuery(ctx context.Context, query Query, settings InfinitySet
195195
query.Source = "url"
196196
}
197197
}
198+
// if the parser is already set, we should respect that
199+
// if the root_selector is already set, overriding the parser type will break the queries with frontend parsing. So we should leave as it is
200+
// if the query have columns defined, overriding the parser type will break the queries with frontend parsing. So we should leave as it is
201+
if query.Parser == "" && strings.TrimSpace(query.RootSelector) == "" && len(query.Columns) == 0 && query.Type != QueryTypeUQL && query.Type != QueryTypeGROQ && query.Type != QueryTypeGSheets {
202+
query.Parser = InfinityParserBackend
203+
}
198204
if query.Type == QueryTypeJSON && query.Source == "inline" && query.Data == "" {
199205
query.Data = "[]"
200206
}

pkg/testsuite/golden/csv_default_url_default.jsonc

+39-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// "body_graphql_variables": ""
2525
// },
2626
// "data": "",
27-
// "parser": "",
27+
// "parser": "backend",
2828
// "filterExpression": "",
2929
// "summarizeExpression": "",
3030
// "summarizeBy": "",
@@ -62,9 +62,15 @@
6262
// "executedQueryString": "###############\n## URL\n###############\n\nhttp://127.0.0.1:8080\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: text/csv; charset=utf-8' -H 'Accept-Encoding: gzip' 'http://127.0.0.1:8080'"
6363
// }
6464
// Name: response
65-
// Dimensions: 0 Fields by 0 Rows
66-
// +
67-
// +
65+
// Dimensions: 2 Fields by 2 Rows
66+
// +-----------------+-----------------+
67+
// | Name: age | Name: name |
68+
// | Labels: | Labels: |
69+
// | Type: []*string | Type: []*string |
70+
// +-----------------+-----------------+
71+
// | 123 | foo |
72+
// | 456 | bar |
73+
// +-----------------+-----------------+
6874
//
6975
//
7076
// 🌟 This was machine generated. Do not edit. 🌟
@@ -98,7 +104,7 @@
98104
"body_graphql_variables": ""
99105
},
100106
"data": "",
101-
"parser": "",
107+
"parser": "backend",
102108
"filterExpression": "",
103109
"summarizeExpression": "",
104110
"summarizeBy": "",
@@ -135,10 +141,36 @@
135141
},
136142
"executedQueryString": "###############\n## URL\n###############\n\nhttp://127.0.0.1:8080\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: text/csv; charset=utf-8' -H 'Accept-Encoding: gzip' 'http://127.0.0.1:8080'"
137143
},
138-
"fields": []
144+
"fields": [
145+
{
146+
"name": "age",
147+
"type": "string",
148+
"typeInfo": {
149+
"frame": "string",
150+
"nullable": true
151+
}
152+
},
153+
{
154+
"name": "name",
155+
"type": "string",
156+
"typeInfo": {
157+
"frame": "string",
158+
"nullable": true
159+
}
160+
}
161+
]
139162
},
140163
"data": {
141-
"values": []
164+
"values": [
165+
[
166+
"123",
167+
"456"
168+
],
169+
[
170+
"foo",
171+
"bar"
172+
]
173+
]
142174
}
143175
}
144176
]

pkg/testsuite/golden/json_default_url_default.jsonc

+25-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// "body_graphql_variables": ""
2525
// },
2626
// "data": "",
27-
// "parser": "",
27+
// "parser": "backend",
2828
// "filterExpression": "",
2929
// "summarizeExpression": "",
3030
// "summarizeBy": "",
@@ -64,9 +64,14 @@
6464
// "executedQueryString": "###############\n## URL\n###############\n\nhttp://127.0.0.1:8080\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: application/json;q=0.9,text/plain' -H 'Accept-Encoding: gzip' 'http://127.0.0.1:8080'"
6565
// }
6666
// Name: response
67-
// Dimensions: 0 Fields by 0 Rows
68-
// +
69-
// +
67+
// Dimensions: 1 Fields by 1 Rows
68+
// +-----------------+
69+
// | Name: message |
70+
// | Labels: |
71+
// | Type: []*string |
72+
// +-----------------+
73+
// | ok |
74+
// +-----------------+
7075
//
7176
//
7277
// 🌟 This was machine generated. Do not edit. 🌟
@@ -100,7 +105,7 @@
100105
"body_graphql_variables": ""
101106
},
102107
"data": "",
103-
"parser": "",
108+
"parser": "backend",
104109
"filterExpression": "",
105110
"summarizeExpression": "",
106111
"summarizeBy": "",
@@ -139,10 +144,23 @@
139144
},
140145
"executedQueryString": "###############\n## URL\n###############\n\nhttp://127.0.0.1:8080\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: application/json;q=0.9,text/plain' -H 'Accept-Encoding: gzip' 'http://127.0.0.1:8080'"
141146
},
142-
"fields": []
147+
"fields": [
148+
{
149+
"name": "message",
150+
"type": "string",
151+
"typeInfo": {
152+
"frame": "string",
153+
"nullable": true
154+
}
155+
}
156+
]
143157
},
144158
"data": {
145-
"values": []
159+
"values": [
160+
[
161+
"ok"
162+
]
163+
]
146164
}
147165
}
148166
]

pkg/testsuite/golden/remote/csv_query.jsonc

+36-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// "body_graphql_variables": ""
2525
// },
2626
// "data": "",
27-
// "parser": "",
27+
// "parser": "backend",
2828
// "filterExpression": "",
2929
// "summarizeExpression": "",
3030
// "summarizeBy": "",
@@ -62,9 +62,14 @@
6262
// "executedQueryString": "###############\n## URL\n###############\n\nhttp://bar\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: text/csv; charset=utf-8' -H 'Accept-Encoding: gzip' 'http://bar'"
6363
// }
6464
// Name: q1
65-
// Dimensions: 0 Fields by 0 Rows
66-
// +
67-
// +
65+
// Dimensions: 2 Fields by 1 Rows
66+
// +-----------------+-----------------+
67+
// | Name: a | Name: b |
68+
// | Labels: | Labels: |
69+
// | Type: []*string | Type: []*string |
70+
// +-----------------+-----------------+
71+
// | a1 | b1 |
72+
// +-----------------+-----------------+
6873
//
6974
//
7075
// 🌟 This was machine generated. Do not edit. 🌟
@@ -98,7 +103,7 @@
98103
"body_graphql_variables": ""
99104
},
100105
"data": "",
101-
"parser": "",
106+
"parser": "backend",
102107
"filterExpression": "",
103108
"summarizeExpression": "",
104109
"summarizeBy": "",
@@ -135,10 +140,34 @@
135140
},
136141
"executedQueryString": "###############\n## URL\n###############\n\nhttp://bar\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: text/csv; charset=utf-8' -H 'Accept-Encoding: gzip' 'http://bar'"
137142
},
138-
"fields": []
143+
"fields": [
144+
{
145+
"name": "a",
146+
"type": "string",
147+
"typeInfo": {
148+
"frame": "string",
149+
"nullable": true
150+
}
151+
},
152+
{
153+
"name": "b",
154+
"type": "string",
155+
"typeInfo": {
156+
"frame": "string",
157+
"nullable": true
158+
}
159+
}
160+
]
139161
},
140162
"data": {
141-
"values": []
163+
"values": [
164+
[
165+
"a1"
166+
],
167+
[
168+
"b1"
169+
]
170+
]
142171
}
143172
}
144173
]

pkg/testsuite/golden/remote/json_query.jsonc

+29-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// "body_graphql_variables": ""
2525
// },
2626
// "data": "",
27-
// "parser": "",
27+
// "parser": "backend",
2828
// "filterExpression": "",
2929
// "summarizeExpression": "",
3030
// "summarizeBy": "",
@@ -66,9 +66,16 @@
6666
// "executedQueryString": "###############\n## URL\n###############\n\nhttp://foo\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: application/json;q=0.9,text/plain' -H 'Accept-Encoding: gzip' 'http://foo'"
6767
// }
6868
// Name: q1
69-
// Dimensions: 0 Fields by 0 Rows
70-
// +
71-
// +
69+
// Dimensions: 1 Fields by 3 Rows
70+
// +------------------+
71+
// | Name: q1 |
72+
// | Labels: |
73+
// | Type: []*float64 |
74+
// +------------------+
75+
// | 1 |
76+
// | 2 |
77+
// | 3 |
78+
// +------------------+
7279
//
7380
//
7481
// 🌟 This was machine generated. Do not edit. 🌟
@@ -102,7 +109,7 @@
102109
"body_graphql_variables": ""
103110
},
104111
"data": "",
105-
"parser": "",
112+
"parser": "backend",
106113
"filterExpression": "",
107114
"summarizeExpression": "",
108115
"summarizeBy": "",
@@ -143,10 +150,25 @@
143150
},
144151
"executedQueryString": "###############\n## URL\n###############\n\nhttp://foo\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: application/json;q=0.9,text/plain' -H 'Accept-Encoding: gzip' 'http://foo'"
145152
},
146-
"fields": []
153+
"fields": [
154+
{
155+
"name": "q1",
156+
"type": "number",
157+
"typeInfo": {
158+
"frame": "float64",
159+
"nullable": true
160+
}
161+
}
162+
]
147163
},
148164
"data": {
149-
"values": []
165+
"values": [
166+
[
167+
1,
168+
2,
169+
3
170+
]
171+
]
150172
}
151173
}
152174
]

0 commit comments

Comments
 (0)