Skip to content

Commit

Permalink
[FLINK-35216] Support for RETURNING clause of JSON_QUERY
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidwys committed May 23, 2024
1 parent 4f1427c commit 0737220
Show file tree
Hide file tree
Showing 20 changed files with 11,089 additions and 74 deletions.
8 changes: 5 additions & 3 deletions docs/data/sql_functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -820,12 +820,12 @@ json:
-- "right"
JSON_VALUE('{"contains blank": "right"}', 'strict $.[''contains blank'']' NULL ON EMPTY DEFAULT 'wrong' ON ERROR)
```
- sql: JSON_QUERY(jsonValue, path [ { WITHOUT | WITH CONDITIONAL | WITH UNCONDITIONAL } [ ARRAY ] WRAPPER ] [ { NULL | EMPTY ARRAY | EMPTY OBJECT | ERROR } ON EMPTY ] [ { NULL | EMPTY ARRAY | EMPTY OBJECT | ERROR } ON ERROR ])
table: STRING.jsonQuery(path [, JsonQueryWrapper [, JsonQueryOnEmptyOrError, JsonQueryOnEmptyOrError ] ])
- sql: JSON_QUERY(jsonValue, path [RETURNING <dataType>] [ { WITHOUT | WITH CONDITIONAL | WITH UNCONDITIONAL } [ ARRAY ] WRAPPER ] [ { NULL | EMPTY ARRAY | EMPTY OBJECT | ERROR } ON EMPTY ] [ { NULL | EMPTY ARRAY | EMPTY OBJECT | ERROR } ON ERROR ])
table: STRING.jsonQuery(path [, returnType [, JsonQueryWrapper [, JsonQueryOnEmptyOrError, JsonQueryOnEmptyOrError ] ] ])
description: |
Extracts JSON values from a JSON string.
The result is always returned as a `STRING`. The `RETURNING` clause is currently not supported.
The result is returned as a `STRING` or `ARRAY<STRING>`. This can be controlled with the `RETURNING` clause.
The `wrappingBehavior` determines whether the extracted value should be wrapped into an array,
and whether to do so unconditionally or only if the value itself isn't an array already.
Expand All @@ -844,6 +844,8 @@ json:
-- '["c1","c2"]'
JSON_QUERY('{"a":[{"c":"c1"},{"c":"c2"}]}',
'lax $.a[*].c')
-- ['c1','c2']
JSON_QUERY('{"a":[{"c":"c1"},{"c":"c2"}]}', 'lax $.a[*].c' RETURNING ARRAY<STRING>)
-- Wrap result into an array
-- '[{}]'
Expand Down
2 changes: 1 addition & 1 deletion flink-python/pyflink/table/tests/test_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_expression(self):
JsonValueOnEmptyOrError.DEFAULT, 42,
JsonValueOnEmptyOrError.ERROR, None)))

self.assertEqual("JSON_QUERY('{}', '$.x', WITHOUT_ARRAY, NULL, EMPTY_ARRAY)",
self.assertEqual("JSON_QUERY('{}', '$.x', STRING, WITHOUT_ARRAY, NULL, EMPTY_ARRAY)",
str(lit('{}').json_query('$.x', JsonQueryWrapper.WITHOUT_ARRAY,
JsonQueryOnEmptyOrError.NULL,
JsonQueryOnEmptyOrError.EMPTY_ARRAY)))
Expand Down
3 changes: 2 additions & 1 deletion flink-table/flink-sql-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ under the License.
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<type>jar</type>
<overWrite>true</overWrite>
<!-- this lets us overwrite some of the Calcite's methods -->
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/</outputDirectory>
<includes>**/Parser.jj</includes>
</artifactItem>
Expand Down
Loading

0 comments on commit 0737220

Please sign in to comment.