Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/18875#discussion_r137282534
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/json/JacksonGenerator.scala
---
@@ -193,14 +218,34 @@ private[sql] class JacksonGenerator(
*
* @param row The row to convert
*/
- def write(row: InternalRow): Unit = writeObject(writeFields(row, schema,
rootFieldWriters))
+ def write(row: InternalRow): Unit = dataType match {
+ case st: StructType =>
+ writeObject(writeFields(row, st, rootFieldWriters))
+ case _ => throw new UnsupportedOperationException(
+ s"this api is only used when `JacksonGenerator` is initialized with
`StructType`")
+ }
/**
* Transforms multiple `InternalRow`s to JSON array using Jackson
*
* @param array The array of rows to convert
*/
- def write(array: ArrayData): Unit = writeArray(writeArrayData(array,
arrElementWriter))
+ def write(array: ArrayData): Unit = dataType match {
+ case _: StructType => writeArray(writeArrayData(array,
arrElementWriter))
+ case _ => throw new UnsupportedOperationException(
+ s"this api is only used when `JacksonGenerator` is initialized with
`StructType`")
--- End diff --
`JacksonGenerator` can only be used to write out an array when initialized
with `StructType`.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]