Skip to content

Commit

Permalink
[improve](load) opt rowColumnValue consider array is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kanedai committed Oct 18, 2023
1 parent 7595de1 commit be2df59
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import org.slf4j.LoggerFactory
import java.sql.Timestamp
import java.time.{LocalDateTime, ZoneOffset}
import scala.collection.JavaConversions._
import scala.collection.mutable

private[spark] object SchemaUtils {
private val logger = LoggerFactory.getLogger(SchemaUtils.getClass.getSimpleName.stripSuffix("$"))
Expand Down Expand Up @@ -166,16 +165,14 @@ private[spark] object SchemaUtils {
case dt: DecimalType => row.getDecimal(ordinal, dt.precision, dt.scale)
case at: ArrayType =>
val arrayData = row.getArray(ordinal)
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
if (arrayData == null) DataUtil.NULL_VALUE
else if(arrayData.numElements() == 0) "[]"
else {
(0 until arrayData.numElements()).map(i => {
if (arrayData.isNullAt(i)) null else rowColumnValue(arrayData, i, at.elementType)
}).mkString("[", ",", "]")
}

case mt: MapType =>
val mapData = row.getMap(ordinal)
val keys = mapData.keyArray()
Expand Down

0 comments on commit be2df59

Please sign in to comment.