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

    https://github.com/apache/spark/pull/15354#discussion_r85583061
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
 ---
    @@ -494,3 +495,46 @@ case class JsonToStruct(schema: StructType, options: 
Map[String, String], child:
     
       override def inputTypes: Seq[AbstractDataType] = StringType :: Nil
     }
    +
    +/**
    + * Converts a [[StructType]] to a json output string.
    + */
    +case class StructToJson(options: Map[String, String], child: Expression)
    +  extends Expression with CodegenFallback with ExpectsInputTypes {
    +  override def nullable: Boolean = true
    +
    +  @transient
    +  lazy val writer = new CharArrayWriter()
    +
    +  @transient
    +  lazy val gen =
    +    new JacksonGenerator(child.dataType.asInstanceOf[StructType], writer)
    +
    +  override def dataType: DataType = StringType
    +  override def children: Seq[Expression] = child :: Nil
    +
    +  override def checkInputDataTypes(): TypeCheckResult = {
    +    if (StructType.acceptsType(child.dataType)) {
    +      try {
    --- End diff --
    
    Sorry, one final comment as I'm looking at this more closely.  I don't 
think we should use exceptions for control flow in the common case.  
Specifically, `verifySchema` should work the same way as `acceptsType` above 
and return a boolean.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to