Skip to content

Commit

Permalink
push decimal fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
“v_kkhuang” committed Dec 13, 2024
1 parent 398b171 commit c18b087
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object DataType extends Logging {
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(dataType, 3) =>
case DecimalType(_, _) =>
if (isNumberNull(newValue)) null else new JavaBigDecimal(newValue)
case DateType => if (isNumberNull(newValue)) null else Date.valueOf(newValue)
case TimestampType =>
Expand Down Expand Up @@ -150,11 +150,13 @@ case object ArrayType extends DataType("array", 2003)
case object MapType extends DataType("map", 2000)
case object ListType extends DataType("list", 2001)
case object StructType extends DataType("struct", 2002)
case object BigDecimalType extends DataType("bigdecimal", 3)

case class DecimalType(override val typeName: String, override val javaSQLType: Int)
extends DataType(typeName, javaSQLType)

case class BigDecimalType(override val typeName: String, override val javaSQLType: Int)
extends DataType(typeName, javaSQLType)

case class Column(columnName: String, dataType: DataType, comment: String) {

def toArray: Array[Any] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class StorageExcelWriter(
case VarcharType => style.setDataFormat(format.getFormat("@"))
case DateType => style.setDataFormat(format.getFormat("m/d/yy h:mm"))
case TimestampType => style.setDataFormat(format.getFormat("m/d/yy h:mm"))
case DecimalType(dataType, 3) => style.setDataFormat(format.getFormat("#.000000000"))
case BigDecimalType => style.setDataFormat(format.getFormat("#.000000000"))
case DecimalType(_, _) => style.setDataFormat(format.getFormat("#.000000000"))
case BigDecimalType(_, _) => style.setDataFormat(format.getFormat("#.000000000"))
case _ => style.setDataFormat(format.getFormat("@"))
}
}
Expand Down Expand Up @@ -171,10 +171,10 @@ class StorageExcelWriter(
case VarcharType => cell.setCellValue(DataType.valueToString(elem))
case DateType => cell.setCellValue(getDate(elem))
case TimestampType => cell.setCellValue(getDate(elem))
case DecimalType(dataType, 3) =>
case DecimalType(_, _) =>
doubleCheck(DataType.valueToString(elem))
cell.setCellValue(DataType.valueToString(elem).toDouble)
case BigDecimalType =>
case BigDecimalType(_, _) =>
doubleCheck(DataType.valueToString(elem))
cell.setCellValue(DataType.valueToString(elem).toDouble)
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.apache.linkis.ujes.client.exception.UJESClientBuilderException
import org.apache.linkis.ujes.client.request.JobExecuteAction.{EngineType, RunType}
import org.apache.linkis.ujes.client.response.ResultSetResult

import java.math.{BigDecimal => JavaBigDecimal}
import java.util
import java.util.Locale

Expand All @@ -29,6 +30,7 @@ import com.google.gson.{Gson, JsonObject}
object UJESClientUtils {

val gson: Gson = new Gson()
val DECIMAL_REGEX = "^decimal\\(\\s*\\d*\\s*,\\s*\\d*\\s*\\)".r.unanchored

def toEngineType(engineType: String): EngineType = engineType match {
case "spark" => EngineType.SPARK
Expand Down Expand Up @@ -75,7 +77,7 @@ object UJESClientUtils {
case "boolean" => value.toBoolean
case "byte" => value.toByte
case "bigint" => value.toLong
case "decimal" => value.toDouble
case "decimal" | DECIMAL_REGEX() => new JavaBigDecimal(value)
case "array" => gson.fromJson(value, classOf[util.ArrayList[Object]])
case "map" => gson.fromJson(value, classOf[util.HashMap[Object, Object]])
case "struct" => gson.fromJson(value, classOf[JsonObject])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static String getTypeStr(int type) {
retVal = BinaryType.typeName();
break;
case Types.DECIMAL:
retVal = DecimalType.toDataType(String.valueOf(type)).toString();
retVal = new DecimalType("decimal", 3).typeName();
break;
case Types.ARRAY:
retVal = ArrayType.typeName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object DolphinToSpark {
case wds.BigIntType => LongType
case wds.FloatType => FloatType
case wds.DoubleType => DoubleType
case wds.DecimalType(dataType, 3) => DecimalType(bigDecimalPrecision, bigDecimalScale)
case wds.DecimalType(_, _) => DecimalType(bigDecimalPrecision, bigDecimalScale)
case wds.DateType => DateType
// case wds.TimestampType => TimestampType
case wds.BinaryType => BinaryType
Expand Down

0 comments on commit c18b087

Please sign in to comment.