feat: UDF json_get with user specified return type (#7554)

* feat: add return_field_from_args

* feat: add JsonGetWithType

* port json_get_float and json_get_bool to new implementation, add
json_get with third argument accepting a scalar value for type.

* fix: lint fix

* chore: add sqlness tests

* chore: update tests
This commit is contained in:
Ning Sun
2026-01-26 17:53:45 +08:00
committed by GitHub
parent 085e9dfc7b
commit 079ee8615f
6 changed files with 690 additions and 226 deletions

View File

@@ -293,6 +293,78 @@ SELECT json_get_int(json_get_object(j, '[9]'), 'a.i') FROM jsons;
| |
+----------------------------------------------------------------+
SELECT json_get(j, '[0]', 'int') FROM jsons;
+-------------------------------------------+
| json_get(jsons.j,Utf8("[0]"),Utf8("int")) |
+-------------------------------------------+
| |
| 1 |
| 1 |
| |
| |
+-------------------------------------------+
SELECT json_get(j, '[0]', 'float') FROM jsons;
+---------------------------------------------+
| json_get(jsons.j,Utf8("[0]"),Utf8("float")) |
+---------------------------------------------+
| |
| 1.0 |
| 1.0 |
| 1.2 |
| |
+---------------------------------------------+
SELECT json_get(j, '[1]', 'int') FROM jsons;
+-------------------------------------------+
| json_get(jsons.j,Utf8("[1]"),Utf8("int")) |
+-------------------------------------------+
| |
| 0 |
| 0 |
| |
| |
+-------------------------------------------+
SELECT json_get(j, '[1]', 'float') FROM jsons;
+---------------------------------------------+
| json_get(jsons.j,Utf8("[1]"),Utf8("float")) |
+---------------------------------------------+
| |
| 0.0 |
| 0.0 |
| 3.141592653589793 |
| |
+---------------------------------------------+
SELECT json_get(j, '[2]', 'bool') FROM jsons;
+--------------------------------------------+
| json_get(jsons.j,Utf8("[2]"),Utf8("bool")) |
+--------------------------------------------+
| |
| false |
| |
| |
| |
+--------------------------------------------+
SELECT json_get(j, '[3]', 'string') FROM jsons;
+--------------------------------------------------------+
| json_get(jsons.j,Utf8("[3]"),Utf8("string")) |
+--------------------------------------------------------+
| Long time ago, there is a little pig flying in the sky |
| false |
| 2147483648 |
| 1e100 |
| |
+--------------------------------------------------------+
DROP TABLE jsons;
Affected Rows: 0

View File

@@ -73,6 +73,18 @@ SELECT json_get_int(json_get_object(j, '[0]'), 'a.i') FROM jsons;
SELECT json_get_int(json_get_object(j, '[9]'), 'a.i') FROM jsons;
SELECT json_get(j, '[0]', 'int') FROM jsons;
SELECT json_get(j, '[0]', 'float') FROM jsons;
SELECT json_get(j, '[1]', 'int') FROM jsons;
SELECT json_get(j, '[1]', 'float') FROM jsons;
SELECT json_get(j, '[2]', 'bool') FROM jsons;
SELECT json_get(j, '[3]', 'string') FROM jsons;
DROP TABLE jsons;
-- test functions in WHERE clause --