diff options
2 files changed, 25 insertions, 1 deletions
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 b61583d0da..667ff649d1 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 @@ -69,7 +69,7 @@ private[this] object JsonPathParser extends RegexParsers { // parse `.name` or `['name']` child expressions def named: Parser[List[PathInstruction]] = for { - name <- '.' ~> "[^\\.\\[]+".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 3b0e90824b..618b8b29e8 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 @@ -43,6 +43,30 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper { """{"price":19.95,"color":"red"}""") } + test("$['store'].bicycle") { + checkEvaluation( + GetJsonObject(Literal(json), Literal("$['store'].bicycle")), + """{"price":19.95,"color":"red"}""") + } + + test("$.store['bicycle']") { + checkEvaluation( + GetJsonObject(Literal(json), Literal("$.store['bicycle']")), + """{"price":19.95,"color":"red"}""") + } + + test("$['store']['bicycle']") { + checkEvaluation( + GetJsonObject(Literal(json), Literal("$['store']['bicycle']")), + """{"price":19.95,"color":"red"}""") + } + + test("$['key with spaces']") { + checkEvaluation(GetJsonObject( + Literal("""{ "key with spaces": "it works" }"""), Literal("$['key with spaces']")), + "it works") + } + test("$.store.book") { checkEvaluation( GetJsonObject(Literal(json), Literal("$.store.book")), |