Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix](Planner) remove json -> operator convert to json_extract #24679

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ BIGINT json_extract_bigint(JSON j, VARCHAR json_path)
LARGEINT json_extract_largeint(JSON j, VARCHAR json_path)
DOUBLE json_extract_double(JSON j, VARCHAR json_path)
STRING json_extract_string(JSON j, VARCHAR json_path)
VARCHAR json_str->json_path
```

json_extract functions extract field specified by json_path from JSON. A series of functions are provided for different datatype.
Expand Down Expand Up @@ -128,22 +127,6 @@ mysql> SELECT json_extract('{"id": 123, "name": "doris"}', '$.aaa', '$.name');
| [null,"doris"] |
+-----------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT '{"id": 123, "name": "doris"}'->'$.name';
+--------------------------------------------------------+
| json_extract('{"id": 123, "name": "doris"}', '$.name') |
+--------------------------------------------------------+
| "doris" |
+--------------------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT '{"k1": "v1", "k2": { "k21": 6.6, "k22": [1, 2, 3] } }'->'$.k2.k22[2]';
+--------------------------------------------------------------------------------------+
| json_extract('{"k1": "v1", "k2": { "k21": 6.6, "k22": [1, 2, 3] } }', '$.k2.k22[2]') |
+--------------------------------------------------------------------------------------+
| 3 |
+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ BIGINT json_extract_bigint(JSON j, VARCHAR json_path)
LARGEINT json_extract_largeint(JSON j, VARCHAR json_path)
DOUBLE json_extract_double(JSON j, VARCHAR json_path)
STRING json_extract_string(JSON j, VARCHAR json_path)
VARCHAR json_str->json_path
```


Expand Down Expand Up @@ -104,22 +103,6 @@ mysql> SELECT json_extract('{"id": 123, "name": "doris"}', '$.aaa', '$.name');
| [null,"doris"] |
+-----------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT '{"id": 123, "name": "doris"}'->'$.name';
+--------------------------------------------------------+
| json_extract('{"id": 123, "name": "doris"}', '$.name') |
+--------------------------------------------------------+
| "doris" |
+--------------------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT '{"k1": "v1", "k2": { "k21": 6.6, "k22": [1, 2, 3] } }'->'$.k2.k22[2]';
+--------------------------------------------------------------------------------------+
| json_extract('{"k1": "v1", "k2": { "k21": 6.6, "k22": [1, 2, 3] } }', '$.k2.k22[2]') |
+--------------------------------------------------------------------------------------+
| 3 |
+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

### keywords
Expand Down
8 changes: 0 additions & 8 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,6 @@ precedence left KW_OVER;
precedence left KW_COLLATE;
precedence left KW_PARTITION;
precedence left KW_PARTITIONS;
precedence left ARROW;
precedence right KW_TEMPORARY;
precedence right LBRACKET;
precedence right LBRACE;
Expand Down Expand Up @@ -6723,13 +6722,6 @@ non_pred_expr ::=
{:
RESULT = new FunctionCallExpr("concat", exprs);
:}
| expr:e ARROW expr:index
{:
ArrayList<Expr> exprs = new ArrayList<>();
exprs.add(e);
exprs.add(index);
RESULT = new FunctionCallExpr("json_extract", new FunctionParams(exprs));
:}
| cast_expr:c
{: RESULT = c; :}
| case_expr:c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,6 @@ DORIS
-- !sql --
[6.6,[1,2,3],2]

-- !sql --
"doris"

-- !sql --
\N

-- !sql --
{"k21":6.6,"k22":[1,2,3]}

-- !sql --
3

-- !sql --
[1,2,3]

-- !sql --
doris

-- !sql --
123

-- !sql --
true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ suite("test_json_function") {
qt_sql "SELECT json_extract('{\"k1\": \"v1\", \"k2\": { \"k21\": 6.6, \"k22\": [1, 2, 3] } }', '\$.k1', '\$.k2');"
qt_sql "SELECT json_extract('{\"k1\": \"v1\", \"k2\": { \"k21\": 6.6, \"k22\": [1, 2, 3] } }', '\$.k2.k21', '\$.k2.k22', '\$.k2.k22[1]');"

qt_sql "SELECT '{\"id\": 123, \"name\": \"doris\"}'->'\$.name';"
qt_sql "SELECT null->'\$.id';"
qt_sql "SELECT '{\"k1\": \"v1\", \"k2\": { \"k21\": 6.6, \"k22\": [1, 2, 3] } }'->'\$.k2';"
qt_sql "SELECT '{\"k1\": \"v1\", \"k2\": { \"k21\": 6.6, \"k22\": [1, 2, 3] } }'->'\$.k2.k22[2]';"
qt_sql "SELECT '{\"k1\": \"v1\", \"k2\": { \"k21\": 6.6, \"k22\": [1, 2, 3] } }'->'\$.k2'->'\$.k22'"
qt_sql "SELECT json_unquote('{\"id\": 123, \"name\": \"doris\"}'->'\$.name');"
qt_sql "SELECT json_extract('{\"id\": 123, \"name\": \"doris\"}', '\$.id', '\$.name')->'\$.[0]';"

qt_sql "SELECT JSON_CONTAINS('{\"a\": 1, \"b\": 2, \"c\": {\"d\": 4}}','1','\$.a');"
qt_sql "SELECT JSON_CONTAINS('{\"a\": 1, \"b\": 2, \"c\": {\"d\": 4}}','1','\$.b');"
qt_sql "SELECT JSON_CONTAINS('{\"a\": 1, \"b\": 2, \"c\": {\"d\": 4}}','{\"d\": 4}','\$.a');"
Expand Down