Skip to content

Commit

Permalink
Dev 1.10.0 bug fix (#705)
Browse files Browse the repository at this point in the history
* Code Optimization

* Code Optimization

* Code Optimization

* Code Optimization

* fix miss code

* New interface: Retrieve data source list based on type name

* New interface: Retrieve data source list based on type name

* bug   fix

* bug   fix

* code  review fix

* code  review fix

* code  review fix

* code  review fix

* Security work order repair

* revent decimal fix

---------

Co-authored-by: “v_kkhuang” <“[email protected]”>
  • Loading branch information
v-kkhuang and “v_kkhuang” authored Jan 8, 2025
1 parent 0f28786 commit 5d7500e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object DataType extends Logging {
case "date" => DateType
case "timestamp" => TimestampType
case "binary" => BinaryType
case "decimal" | DECIMAL_REGEX() => DecimalType(dataType, 3)
case "decimal" | DECIMAL_REGEX() => DecimalType
case ARRAY_REGEX() => ArrayType
case MAP_REGEX() => MapType
case LIST_REGEX() => ListType
Expand All @@ -89,8 +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(_, _) =>
if (isNumberNull(newValue)) null else new JavaBigDecimal(newValue)
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")
Expand Down Expand Up @@ -146,16 +145,12 @@ case object VarcharType extends DataType("varchar", 12)
case object DateType extends DataType("date", 91)
case object TimestampType extends DataType("timestamp", 93)
case object BinaryType extends DataType("binary", -2)
case object DecimalType extends DataType("decimal", 3)
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 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 object BigDecimalType extends DataType("bigdecimal", 3)

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

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(_, _) => 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(_, _) =>
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,7 +21,6 @@ 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 @@ -30,7 +29,6 @@ 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 @@ -77,7 +75,7 @@ object UJESClientUtils {
case "boolean" => value.toBoolean
case "byte" => value.toByte
case "bigint" => value.toLong
case "decimal" | DECIMAL_REGEX() => new JavaBigDecimal(value)
case "decimal" => value.toDouble
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 = new DecimalType("decimal", 3).typeName();
retVal = DecimalType.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(_, _) => DecimalType(bigDecimalPrecision, bigDecimalScale)
case wds.DecimalType => DecimalType(bigDecimalPrecision, bigDecimalScale)
case wds.DateType => DateType
// case wds.TimestampType => TimestampType
case wds.BinaryType => BinaryType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ public Message queryFailedTaskDiagnosis(
if (StringUtils.isBlank(taskID)) {
return Message.error("Invalid jobId cannot be empty");
}
if (!QueryUtils.checkNumberValid(taskID)) {
throw new LinkisCommonErrorException(21304, "Invalid taskID : " + taskID);
}
JobHistory jobHistory = null;
boolean isAdmin = Configuration.isJobHistoryAdmin(username) || Configuration.isAdmin(username);
boolean isDepartmentAdmin = Configuration.isDepartmentAdmin(username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ object QueryUtils extends Logging {
private val LENGTH_SPLIT = "#"
private val NAME_REGEX = "^[a-zA-Z\\-\\d_\\.]+$"
private val INSTANCE_NAME_REGEX = "^[a-zA-Z\\-\\d_\\.:]+$"
private val NUMBER_REGEX = "^[0-9]+$"
private val nameRegexPattern = Pattern.compile(NAME_REGEX)
private val instanceNameRegexPattern = Pattern.compile(INSTANCE_NAME_REGEX)
private val numberRegexPattern = Pattern.compile(NUMBER_REGEX)

private val dateFormatLocal = new ThreadLocal[SimpleDateFormat]() {
override protected def initialValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
Expand Down Expand Up @@ -173,4 +175,8 @@ object QueryUtils extends Logging {
instanceNameRegexPattern.matcher(param).find()
}

def checkNumberValid(param: String): Boolean = {
numberRegexPattern.matcher(param).find()
}

}

0 comments on commit 5d7500e

Please sign in to comment.