mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 23:32:30 +08:00
SQL Expressions: Add JSON support (#103157)
- Support bi-directional mapping of frame JSON fields and GMS (go-mysql-server) columns - Permit GMS json functions Co-authored-by: Kyle Brandt <kyle@grafana.com>
This commit is contained in:
@ -67,6 +67,11 @@ func TestAllowQuery(t *testing.T) {
|
||||
q: `SELECT __value__, SUBSTRING_INDEX(name, '.', -1) AS code FROM A`,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
name: "json functions",
|
||||
q: example_json_functions,
|
||||
err: nil,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
@ -239,3 +244,15 @@ SELECT
|
||||
FROM sample_data
|
||||
GROUP BY name, value, created_at
|
||||
LIMIT 10`
|
||||
|
||||
var example_json_functions = `SELECT
|
||||
JSON_OBJECT('key1', 'value1', 'key2', 10) AS json_obj,
|
||||
JSON_ARRAY(1, 'abc', NULL, TRUE) AS json_arr,
|
||||
JSON_EXTRACT('{"id": 123, "name": "test"}', '$.id') AS json_ext,
|
||||
JSON_UNQUOTE(JSON_EXTRACT('{"name": "test"}', '$.name')) AS json_unq,
|
||||
JSON_CONTAINS('{"a": 1, "b": 2}', '{"a": 1}') AS json_contains,
|
||||
JSON_SET('{"a": 1}', '$.b', 2) AS json_set,
|
||||
JSON_REMOVE('{"a": 1, "b": 2}', '$.b') AS json_remove,
|
||||
JSON_LENGTH('{"a": 1, "b": {"c": 3}}') AS json_len,
|
||||
JSON_SEARCH('{"a": "xyz", "b": "abc"}', 'one', 'abc') AS json_search,
|
||||
JSON_TYPE('{"a": 1}') AS json_type`
|
||||
|
Reference in New Issue
Block a user