in linkis-commons/linkis-storage/src/main/scala/org/apache/linkis/storage/domain/DataType.scala [73:102]
def toValue(dataType: DataType, value: String): Any = {
var newValue: String = value
if (isLinkisNull(value)) {
if (!LinkisStorageConf.LINKIS_RESULT_ENABLE_NULL) {
return null
} else {
newValue = Dolphin.NULL
}
}
Utils.tryCatch(dataType match {
case NullType => null
case StringType | CharType | VarcharType | StructType | ListType | ArrayType | MapType =>
newValue
case BooleanType => if (isNumberNull(newValue)) null else newValue.toBoolean
case ShortIntType => if (isNumberNull(newValue)) null else newValue.toShort
case IntType => if (isNumberNull(newValue)) null else newValue.toInt
case LongType | BigIntType => if (isNumberNull(newValue)) null else newValue.toLong
case FloatType => if (isNumberNull(newValue)) null else newValue.toFloat
case DoubleType => if (isNumberNull(newValue)) null else newValue.toDouble
case DecimalType => if (isNumberNull(newValue)) null else new JavaBigDecimal(newValue)
case DateType => if (isNumberNull(newValue)) null else Date.valueOf(newValue)
case TimestampType =>
if (isNumberNull(newValue)) null else Timestamp.valueOf(newValue).toString.stripSuffix(".0")
case BinaryType => if (isNull(newValue)) null else newValue.getBytes()
case _ => newValue
}) { t =>
logger.debug(s"Failed to $newValue switch to dataType:", t)
newValue
}
}