You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@linkis.apache.org by GitBox <gi...@apache.org> on 2022/07/15 03:24:41 UTC

[GitHub] [incubator-linkis] casionone commented on a diff in pull request #2468: Fix multiple bugs in version 1.2.0

casionone commented on code in PR #2468:
URL: https://github.com/apache/incubator-linkis/pull/2468#discussion_r921779231


##########
linkis-commons/linkis-storage/src/main/scala/org/apache/linkis/storage/excel/StorageExcelWriter.scala:
##########
@@ -150,29 +150,29 @@ class StorageExcelWriter(val charset: String, val sheetName: String, val dateFor
 
   private def setCellTypeValue(dataType: DataType, elem: Any, cell: SXSSFCell): Unit = {
     if (null == elem) return
-    dataType match {
-      case StringType => cell.setCellValue(DataType.valueToString(elem))
-      case TinyIntType => cell.setCellValue(elem.toString.toInt)
-      case ShortIntType => cell.setCellValue(elem.toString.toInt)
-      case IntType => cell.setCellValue(elem.toString.toInt)
-      case LongType => cell.setCellValue(elem.toString.toLong)
-      case BigIntType => cell.setCellValue(elem.toString.toLong)
-      case FloatType => cell.setCellValue(elem.toString.toFloat)
-      case DoubleType => cell.setCellValue(elem.toString.toDouble)
-      case CharType => cell.setCellValue(DataType.valueToString(elem))
-      case VarcharType => cell.setCellValue(DataType.valueToString(elem))
-      case DateType => cell.setCellValue(getDate(elem))
-      case TimestampType => cell.setCellValue(getDate(elem))
-      case DecimalType => cell.setCellValue(DataType.valueToString(elem))
-      case BigDecimalType => cell.setCellValue(DataType.valueToString(elem))
-      case _ =>
-        val value = DataType.valueToString(elem)
-        cell.setCellValue(value)
-        if (null != dataType) {
-          logger.warn(s"Cannot find matched type for dataType : ${dataType.toString}, string value:${value}, value className : ${elem.getClass.getName}, will treat it as string.")
-        } else {
-          logger.warn(s"Invalid null dataType. Will treat value string : ${value}, value className : ${elem.getClass.getName} as string.")
-        }
+    Utils.tryCatch {
+      dataType match {
+        case StringType => cell.setCellValue(DataType.valueToString(elem))
+        case TinyIntType => cell.setCellValue(elem.toString.toInt)
+        case ShortIntType => cell.setCellValue(elem.toString.toInt)
+        case IntType => cell.setCellValue(elem.toString.toInt)
+        case LongType => cell.setCellValue(elem.toString.toLong)
+        case BigIntType => cell.setCellValue(elem.toString.toLong)
+        case FloatType => cell.setCellValue(elem.toString.toFloat)
+        case DoubleType => cell.setCellValue(elem.toString.toDouble)
+        case CharType => cell.setCellValue(DataType.valueToString(elem))
+        case VarcharType => cell.setCellValue(DataType.valueToString(elem))
+        case DateType => cell.setCellValue(getDate(elem))
+        case TimestampType => cell.setCellValue(getDate(elem))
+        case DecimalType => cell.setCellValue(DataType.valueToString(elem))
+        case BigDecimalType => cell.setCellValue(DataType.valueToString(elem))
+        case _ =>
+          val value = DataType.valueToString(elem)
+          cell.setCellValue(value)
+      }
+    } {
+      case e: Exception =>
+        cell.setCellValue(valueToString(elem))

Review Comment:
   keep the uniform style?
   `DataType.valueToString(elem)`



-- 
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: notifications-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org
For additional commands, e-mail: notifications-help@linkis.apache.org