bojana-db commented on code in PR #59097:
URL: https://github.com/apache/spark/pull/59097#discussion_r4249909084


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:
##########
@@ -368,14 +369,35 @@ object VariantPathParser extends RegexParsers {
 
   override def skipWhitespace: Boolean = false
 
-  // Parse key segment like `.name`, `['name']`, or `["name"]`.
+  // Parse a key segment: `.name`, `['name']`, or `["name"]`. Dot notation is 
taken literally;
+  // both bracket forms are unescaped by `unescapeQuotedKey`.
   private def key: Parser[VariantPathSegment] =
-    for {
-      key <- '.' ~> "[^\\.\\[]+".r | "['" ~> "[^']*".r <~ "']" |
-        "[\"" ~> """[^"]*""".r <~ "\"]"
-    } yield {
-      ObjectExtraction(key)
-    }
+    '.' ~> "[^\\.\\[]+".r ^^ ObjectExtraction |
+      "['" ~> """(?:\\[\s\S]|[^'\\])*""".r <~ "']" ^^ { k =>
+        ObjectExtraction(unescapeQuotedKey(k))

Review Comment:
   Fixed.



##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/variant/VariantExpressionSuite.scala:
##########
@@ -737,6 +737,23 @@ class VariantExpressionSuite extends SparkFunSuite with 
ExpressionEvalHelper {
     // scalastyle:on nonascii
     testVariantGet("[1, 2, 3]", "$[2147483647]", IntegerType, null)
 
+    // `['...']` decodes escapes: `\'` -> quote, `"` literal, both quotes in 
one key.
+    testVariantGet("""{"a'b": 1}""", """$['a\'b']""", IntegerType, 1)
+    testVariantGet("""{"a\"b": 2}""", """$['a"b']""", IntegerType, 2)
+    testVariantGet("""{"a'\"b": 3}""", """$['a\'"b']""", IntegerType, 3)
+    // `\\` -> backslash, and the short control escapes.

Review Comment:
   Added.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to