[HUDI-2131] Exception Throw Out When MergeInto With Decimal Type Field (#3224)
This commit is contained in:
@@ -86,4 +86,11 @@ class TestHoodieSqlBase extends FunSuite with BeforeAndAfterAll {
|
||||
assertResult(errorMsg)(e.getMessage)
|
||||
}
|
||||
}
|
||||
|
||||
protected def removeQuotes(value: Any): Any = {
|
||||
value match {
|
||||
case s: String => s.stripPrefix("'").stripSuffix("'")
|
||||
case _=> value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,11 +277,4 @@ class TestInsertTable extends TestHoodieSqlBase {
|
||||
" count: 3,columns: (1,a1,10)"
|
||||
)
|
||||
}
|
||||
|
||||
private def removeQuotes(value: Any): Any = {
|
||||
value match {
|
||||
case s: String => s.stripPrefix("'").stripSuffix("'")
|
||||
case _=> value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.apache.spark.sql.hudi
|
||||
import org.apache.hudi.{DataSourceReadOptions, HoodieDataSourceHelpers}
|
||||
import org.apache.hudi.common.fs.FSUtils
|
||||
|
||||
|
||||
class TestMergeIntoTable extends TestHoodieSqlBase {
|
||||
|
||||
test("Test MergeInto Basic") {
|
||||
@@ -687,4 +686,50 @@ class TestMergeIntoTable extends TestHoodieSqlBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test("Test MereInto With All Kinds Of DataType") {
|
||||
withTempDir { tmp =>
|
||||
val dataAndTypes = Seq(
|
||||
("string", "'a1'"),
|
||||
("int", "10"),
|
||||
("bigint", "10"),
|
||||
("double", "10.0"),
|
||||
("float", "10.0"),
|
||||
("decimal(5,2)", "10.11"),
|
||||
("decimal(5,0)", "10"),
|
||||
("timestamp", "'2021-05-20 00:00:00'"),
|
||||
("date", "'2021-05-20'")
|
||||
)
|
||||
dataAndTypes.foreach { case (dataType, dataValue) =>
|
||||
val tableName = generateTableName
|
||||
spark.sql(
|
||||
s"""
|
||||
|create table $tableName (
|
||||
| id int,
|
||||
| name string,
|
||||
| value $dataType,
|
||||
| ts long
|
||||
|) using hudi
|
||||
| location '${tmp.getCanonicalPath}/$tableName'
|
||||
| options (
|
||||
| primaryKey ='id',
|
||||
| preCombineField = 'ts'
|
||||
| )
|
||||
""".stripMargin)
|
||||
|
||||
spark.sql(
|
||||
s"""
|
||||
|merge into $tableName h0
|
||||
|using (
|
||||
| select 1 as id, 'a1' as name, cast($dataValue as $dataType) as value, 1000 as ts
|
||||
| ) s0
|
||||
| on h0.id = s0.id
|
||||
| when not matched then insert *
|
||||
|""".stripMargin)
|
||||
checkAnswer(s"select id, name, cast(value as string), ts from $tableName")(
|
||||
Seq(1, "a1", removeQuotes(dataValue), 1000)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user