wolfboys commented on code in PR #147: URL: https://github.com/apache/doris-spark-connector/pull/147#discussion_r1363166877
########## spark-doris-connector/src/main/scala/org/apache/doris/spark/sql/SchemaUtils.scala: ########## @@ -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) Review Comment: ๐Thank you for your contribution! ๐ It is necessary to consider the case where the array is empty (size = 0). The code can be further improved! ``` 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(data, i, at.elementType) }).mkString("[", ",", "]") } } ``` ########## spark-doris-connector/src/main/scala/org/apache/doris/spark/sql/SchemaUtils.scala: ########## @@ -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) Review Comment: ๐Thank you for your contribution! ๐ It is necessary to consider the case where the array is empty (size = 0). The code can be further improved! ``` 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(data, i, at.elementType) }).mkString("[", ",", "]") } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org