Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/7485#discussion_r36110763
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/GetJsonObject.scala
---
@@ -0,0 +1,326 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.catalyst.expressions
+
+import java.io.{StringWriter, ByteArrayOutputStream}
+
+import com.fasterxml.jackson.core._
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.codegen.CodegenFallback
+import org.apache.spark.sql.types.{StringType, DataType}
+import org.apache.spark.unsafe.types.UTF8String
+
+import scala.util.parsing.combinator.RegexParsers
+
+private[this] sealed trait PathInstruction
+private[this] object PathInstruction {
+ private[expressions] case object Subscript extends PathInstruction
+ private[expressions] case object Wildcard extends PathInstruction
+ private[expressions] case object Key extends PathInstruction
+ private[expressions] case class Index(index: Long) extends
PathInstruction
+ private[expressions] case class Named(name: String) extends
PathInstruction
+}
+
+private[this] sealed trait WriteStyle
+private[this] object WriteStyle {
+ private[expressions] case object RawStyle extends WriteStyle
+ private[expressions] case object QuotedStyle extends WriteStyle
+ private[expressions] case object FlattenStyle extends WriteStyle
+}
+
+private[this] object JsonPathParser extends RegexParsers {
+ import PathInstruction._
+
+ def root: Parser[Char] = '$'
+
+ def long: Parser[Long] = "\\d+".r ^? {
+ case x => x.toLong
+ }
+
+ // parse `[*]` and `[123]` subscripts
+ def subscript: Parser[List[PathInstruction]] =
+ for {
+ operand <- '[' ~> ('*' ^^^ Wildcard | long ^^ Index) <~ ']'
+ } yield {
+ Subscript :: operand :: Nil
+ }
+
+ // parse `.name` or `['name']` child expressions
+ def named: Parser[List[PathInstruction]] =
+ for {
+ name <- '.' ~> "[^\\.\\[]+".r | "[\\'" ~> "[^\\'\\?]+" <~ "\\']"
+ } yield {
+ Key :: Named(name) :: Nil
+ }
+
+ // child wildcards: `..`, `.*` or `['*']`
+ def wildcard: Parser[List[PathInstruction]] =
+ (".*" | "['*']") ^^^ List(Wildcard)
+
+ def node: Parser[List[PathInstruction]] =
+ wildcard |
+ named |
+ subscript
+
+ val expression: Parser[List[PathInstruction]] = {
+ phrase(root ~> rep(node) ^^ (x => x.flatten))
+ }
+
+ def parse(str: String): Option[List[PathInstruction]] = {
+ this.parseAll(expression, str) match {
+ case Success(result, _) =>
+ Some(result)
+
+ case NoSuccess(msg, next) =>
+ None
+ }
+ }
+}
+
+private[this] object GetJsonObject {
+ private val jsonFactory = new JsonFactory()
+
+ // Enabled for Hive compatibility
+ jsonFactory.enable(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS)
+}
+
+case class GetJsonObject(
+ jsonExpression: Expression,
+ pathExpression: Expression)
+ extends Expression
--- End diff --
it could extends BinaryExpression
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]