From d46d5dfd6a5673dd71e9615f3872e41a8e4229a8 Mon Sep 17 00:00:00 2001 From: Chuang Li <64473732+CodeCooker17@users.noreply.github.com> Date: Fri, 15 Sep 2023 17:58:50 +0800 Subject: [PATCH] [bug] NPE occurs for StringType when column value is null. (#141) --- .../src/main/scala/org/apache/doris/spark/sql/SchemaUtils.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spark-doris-connector/src/main/scala/org/apache/doris/spark/sql/SchemaUtils.scala b/spark-doris-connector/src/main/scala/org/apache/doris/spark/sql/SchemaUtils.scala index f5a6a159..86a403f5 100644 --- a/spark-doris-connector/src/main/scala/org/apache/doris/spark/sql/SchemaUtils.scala +++ b/spark-doris-connector/src/main/scala/org/apache/doris/spark/sql/SchemaUtils.scala @@ -156,7 +156,7 @@ private[spark] object SchemaUtils { case LongType => row.getLong(ordinal) case FloatType => row.getFloat(ordinal) case DoubleType => row.getDouble(ordinal) - case StringType => row.getUTF8String(ordinal).toString + case StringType => Option(row.getUTF8String(ordinal)).map(_.toString).getOrElse(DataUtil.NULL_VALUE) case TimestampType => LocalDateTime.ofEpochSecond(row.getLong(ordinal) / 100000, (row.getLong(ordinal) % 1000).toInt, ZoneOffset.UTC) new Timestamp(row.getLong(ordinal) / 1000).toString