Skip to content

Commit

Permalink
[fix](load) fix npe when array is null
Browse files Browse the repository at this point in the history
  • Loading branch information
kanedai committed Oct 18, 2023
1 parent 7a45abe commit 7595de1
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,16 @@ private[spark] object SchemaUtils {
case dt: DecimalType => row.getDecimal(ordinal, dt.precision, dt.scale)
case at: ArrayType =>
val arrayData = row.getArray(ordinal)
var i = 0
val buffer = mutable.Buffer[Any]()
while (i < arrayData.numElements()) {
if (arrayData.isNullAt(i)) buffer += null else buffer += rowColumnValue(arrayData, i, at.elementType)
i += 1
}
s"[${buffer.mkString(",")}]"
val result: String = Option(arrayData)
.filter(_.numElements() > 0)
.map { data =>
(0 until data.numElements()).map { i =>
if (data.isNullAt(i)) null else rowColumnValue(data, i, at.elementType)
}.mkString(",")
}
.map(str => s"[$str]")
.getOrElse(DataUtil.NULL_VALUE)
result
case mt: MapType =>
val mapData = row.getMap(ordinal)
val keys = mapData.keyArray()
Expand Down

0 comments on commit 7595de1

Please sign in to comment.