Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/18875#discussion_r137986264
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
---
@@ -677,14 +696,25 @@ case class StructsToJson(
override def checkInputDataTypes(): TypeCheckResult = child.dataType
match {
case _: StructType | ArrayType(_: StructType, _) =>
try {
- JacksonUtils.verifySchema(rowSchema)
+ JacksonUtils.verifySchema(rowSchema.asInstanceOf[StructType])
+ TypeCheckResult.TypeCheckSuccess
+ } catch {
+ case e: UnsupportedOperationException =>
+ TypeCheckResult.TypeCheckFailure(e.getMessage)
+ }
+ case _: MapType | ArrayType(_: MapType, _) =>
+ // TODO: let `JacksonUtils.verifySchema` verify a `MapType`
+ try {
+ val st = StructType(StructField("a",
rowSchema.asInstanceOf[MapType]) :: Nil)
+ JacksonUtils.verifySchema(st)
TypeCheckResult.TypeCheckSuccess
} catch {
case e: UnsupportedOperationException =>
TypeCheckResult.TypeCheckFailure(e.getMessage)
}
case _ => TypeCheckResult.TypeCheckFailure(
- s"Input type ${child.dataType.simpleString} must be a struct or
array of structs.")
+ s"Input type ${child.dataType.simpleString} must be a struct, array
of structs or " +
+ s"an arbitrary map.")
--- End diff --
`an arbitrary map` -> `a map or array of map.`
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]