Github user brkyvz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16929#discussion_r104253014
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
 ---
    @@ -480,23 +480,45 @@ case class JsonTuple(children: Seq[Expression])
     }
     
     /**
    - * Converts an json input string to a [[StructType]] with the specified 
schema.
    + * Converts an json input string to a [[StructType]] or [[ArrayType]] with 
the specified schema.
      */
     case class JsonToStruct(
    -    schema: StructType,
    +    schema: DataType,
         options: Map[String, String],
         child: Expression,
         timeZoneId: Option[String] = None)
       extends UnaryExpression with TimeZoneAwareExpression with 
CodegenFallback with ExpectsInputTypes {
       override def nullable: Boolean = true
     
    -  def this(schema: StructType, options: Map[String, String], child: 
Expression) =
    +  def this(schema: DataType, options: Map[String, String], child: 
Expression) =
         this(schema, options, child, None)
     
    +  override def checkInputDataTypes(): TypeCheckResult = schema match {
    +    case _: StructType | ArrayType(_: StructType, _) =>
    +      super.checkInputDataTypes()
    +    case _ => TypeCheckResult.TypeCheckFailure(
    +      s"Input schema ${schema.simpleString} must be a struct or an array 
of structs.")
    +  }
    +
    +  @transient
    +  lazy val rowSchema = schema match {
    +    case st: StructType => st
    +    case ArrayType(st: StructType, _) => st
    +  }
    +
    +  // This converts parsed rows to the desired output by the given schema.
    +  @transient
    +  lazy val converter = schema match {
    +    case _: StructType =>
    +      (rows: Seq[InternalRow]) => if (rows.length == 1) rows.head else null
    --- End diff --
    
    this breaks previous behavior. I would still return the first element. Feel 
free to push back. Also wonder what @marmbrus  thinks


---
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]

Reply via email to