[improve](jsonb)Invalid json path prompts an error instead of null (#19646)

1. Invalid json path prompts an error instead of null:
before:
```sql
mysql> SELECT jsonb_extract('[{"k1":"v41","k2":400},1,"a",3.14]', '$[a]');
+-------------------------------------------------------------+
| jsonb_extract('[{"k1":"v41","k2":400},1,"a",3.14]', '$[a]') |
+-------------------------------------------------------------+
| NULL                                                        |
+-------------------------------------------------------------+
1 row in set (0.01 sec)
```
now
```sql
mysql> SELECT jsonb_extract('[{"k1":"v41","k2":400},1,"a",3.14]', '$[a]');
ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[INVALID_ARGUMENT]Json path error: Invalid Json Path for value: $[a]
```
2. fix some problem: https://github.com/apache/doris/pull/19185
   a. support negative numbers
```sql
mysql> SELECT jsonb_extract('[{"k1":"v41","k2":400},1,"a",3.14]', '$[-2]');
+--------------------------------------------------------------+
| jsonb_extract('[{"k1":"v41","k2":400},1,"a",3.14]', '$[-2]') |
+--------------------------------------------------------------+
| "a"                                                          |
+--------------------------------------------------------------+
1 row in set (0.02 sec)
```
  b. Avoid using unnecessary memory
3. Supplementary regression test
This commit is contained in:
Liqf
2023-06-30 14:29:21 +08:00
committed by GitHub
parent 8809cca74a
commit d76fa427a3
10 changed files with 3651 additions and 267 deletions

View File

@ -559,15 +559,16 @@ TEST(FunctionJsonbTEST, JsonbExtractTest) {
{{STRING("null"), STRING("$[0]")}, Null()},
{{STRING("true"), STRING("$[0]")}, Null()},
{{STRING("false"), STRING("$[0]")}, Null()},
{{STRING("100"), STRING("$[0]")}, Null()}, //int8
{{STRING("10000"), STRING("$[0]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0]")}, Null()}, // string
{{STRING("{}"), STRING("$[0]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0]")}, Null()}, // object
{{STRING("[]"), STRING("$[0]")}, Null()}, // empty array
{{STRING("100"), STRING("$[0]")}, Null()}, //int8
{{STRING("10000"), STRING("$[0]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0]")}, Null()}, // string
{{STRING("{}"), STRING("$[0]")}, STRING("{}")}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0]")},
STRING(R"({"k1":"v31","k2":300})")}, // object
{{STRING("[]"), STRING("$[0]")}, Null()}, // empty array
{{STRING("null"), STRING("$[1]")}, Null()},
{{STRING("true"), STRING("$[1]")}, Null()},
{{STRING("false"), STRING("$[1]")}, Null()},
@ -620,17 +621,18 @@ TEST(FunctionJsonbTEST, JsonbExtractTest) {
{{STRING("null"), STRING("$[0].k1")}, Null()},
{{STRING("true"), STRING("$[0].k1")}, Null()},
{{STRING("false"), STRING("$[0].k1")}, Null()},
{{STRING("100"), STRING("$[0].k1")}, Null()}, //int8
{{STRING("10000"), STRING("$[0].k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0].k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0].k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0].k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0].k1")}, Null()}, // string
{{STRING("{}"), STRING("$[0].k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0].k1")}, Null()}, // object
{{STRING("[]"), STRING("$[0].k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0].k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0].k1")}, Null()}, // string array
{{STRING("100"), STRING("$[0].k1")}, Null()}, //int8
{{STRING("10000"), STRING("$[0].k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0].k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0].k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0].k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0].k1")}, Null()}, // string
{{STRING("{}"), STRING("$[0].k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0].k1")},
STRING(R"("v31")")}, // object
{{STRING("[]"), STRING("$[0].k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0].k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0].k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0].k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0].k1")},
@ -702,15 +704,16 @@ TEST(FunctionJsonbTEST, JsonbExtractStringTest) {
{{STRING("null"), STRING("$[0]")}, Null()},
{{STRING("true"), STRING("$[0]")}, Null()},
{{STRING("false"), STRING("$[0]")}, Null()},
{{STRING("100"), STRING("$[0]")}, Null()}, //int8
{{STRING("10000"), STRING("$[0]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0]")}, Null()}, // string
{{STRING("{}"), STRING("$[0]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0]")}, Null()}, // object
{{STRING("[]"), STRING("$[0]")}, Null()}, // empty array
{{STRING("100"), STRING("$[0]")}, Null()}, //int8
{{STRING("10000"), STRING("$[0]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0]")}, Null()}, // string
{{STRING("{}"), STRING("$[0]")}, STRING("{}")}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0]")},
STRING(R"({"k1":"v31","k2":300})")}, // object
{{STRING("[]"), STRING("$[0]")}, Null()}, // empty array
{{STRING("null"), STRING("$[1]")}, Null()},
{{STRING("true"), STRING("$[1]")}, Null()},
{{STRING("false"), STRING("$[1]")}, Null()},
@ -763,17 +766,17 @@ TEST(FunctionJsonbTEST, JsonbExtractStringTest) {
{{STRING("null"), STRING("$[0].k1")}, Null()},
{{STRING("true"), STRING("$[0].k1")}, Null()},
{{STRING("false"), STRING("$[0].k1")}, Null()},
{{STRING("100"), STRING("$[0].k1")}, Null()}, //int8
{{STRING("10000"), STRING("$[0].k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0].k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0].k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0].k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0].k1")}, Null()}, // string
{{STRING("{}"), STRING("$[0].k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0].k1")}, Null()}, // object
{{STRING("[]"), STRING("$[0].k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0].k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0].k1")}, Null()}, // string array
{{STRING("100"), STRING("$[0].k1")}, Null()}, //int8
{{STRING("10000"), STRING("$[0].k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0].k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0].k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0].k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0].k1")}, Null()}, // string
{{STRING("{}"), STRING("$[0].k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0].k1")}, STRING(R"(v31)")}, // object
{{STRING("[]"), STRING("$[0].k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0].k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0].k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0].k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0].k1")},