You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by gu...@apache.org on 2024/03/13 07:17:15 UTC
(spark) branch master updated: [SPARK-46761][SQL] Quoted strings in a JSON path should support ? characters
This is an automated email from the ASF dual-hosted git repository.
gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new a5d0c3778fd6 [SPARK-46761][SQL] Quoted strings in a JSON path should support ? characters
a5d0c3778fd6 is described below
commit a5d0c3778fd6fa724f238ba3e21745c3205719a5
Author: Pablo Langa <so...@gmail.com>
AuthorDate: Wed Mar 13 16:17:01 2024 +0900
[SPARK-46761][SQL] Quoted strings in a JSON path should support ? characters
### What changes were proposed in this pull request?
If there is a JSON with a ? character in the key like
```
{"?":"QUESTION"}
```
This PR allow to add this character in the JSON path
```
get_json_object(json, '$['?']')
```
This character is now explicitly avoided in the regular expression but there seem to be no restrictions on this in the specification (https://goessner.net/articles/JsonPath/) and no tests fail with this change.
### Why are the changes needed?
Improve the support of ? character in json parh
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Unit testing
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #45420 from planga82/bugfix/spark46761_json_path_question_mark.
Authored-by: Pablo Langa <so...@gmail.com>
Signed-off-by: Hyukjin Kwon <gu...@apache.org>
---
.../apache/spark/sql/catalyst/expressions/jsonExpressions.scala | 2 +-
.../spark/sql/catalyst/expressions/JsonExpressionsSuite.scala | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
index 890ab5541985..9fca09b46a99 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
@@ -76,7 +76,7 @@ private[this] object JsonPathParser extends RegexParsers {
// parse `.name` or `['name']` child expressions
def named: Parser[List[PathInstruction]] =
for {
- name <- '.' ~> "[^\\.\\[]+".r | "['" ~> "[^\\'\\?]+".r <~ "']"
+ name <- '.' ~> "[^\\.\\[]+".r | "['" ~> "[^\\']+".r <~ "']"
} yield {
Key :: Named(name) :: Nil
}
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/JsonExpressionsSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/JsonExpressionsSuite.scala
index 9b651ef8762e..a23e7f44a48d 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/JsonExpressionsSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/JsonExpressionsSuite.scala
@@ -899,4 +899,11 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with
)
}
}
+
+ test("SPARK-46761: support ? characters") {
+ checkEvaluation(
+ GetJsonObject(Literal(s"""{"?":"QUESTION"}"""), Literal("$['?']")),
+ "QUESTION"
+ )
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org