This is an automated email from the ASF dual-hosted git repository. yuzhaojing pushed a commit to branch release-0.12.1-rc1 in repository https://gitbox.apache.org/repos/asf/hudi.git
commit f2360894b5a48725957fb97972c5e9812d73c56b Author: KnightChess <[email protected]> AuthorDate: Mon Sep 26 22:03:40 2022 +0800 [HUDI-4910] Fix unknown variable or type "Cast" (#6778) --- .../hudi/command/payload/ExpressionCodeGen.scala | 5 +-- .../spark/sql/hudi/TestMergeIntoTable2.scala | 40 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/payload/ExpressionCodeGen.scala b/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/payload/ExpressionCodeGen.scala index 947291d103..cd5b201f91 100644 --- a/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/payload/ExpressionCodeGen.scala +++ b/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/payload/ExpressionCodeGen.scala @@ -25,7 +25,7 @@ import org.apache.spark.sql.avro.AvroSerializer import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.expressions.codegen.Block.BlockHelper import org.apache.spark.sql.catalyst.expressions.codegen._ -import org.apache.spark.sql.catalyst.expressions.{BoundReference, Expression, GenericInternalRow, LeafExpression, UnsafeArrayData, UnsafeMapData, UnsafeRow} +import org.apache.spark.sql.catalyst.expressions.{BoundReference, Cast, Expression, GenericInternalRow, LeafExpression, UnsafeArrayData, UnsafeMapData, UnsafeRow} import org.apache.spark.sql.catalyst.util.{ArrayData, MapData} import org.apache.spark.sql.hudi.command.payload.ExpressionCodeGen.RECORD_NAME import org.apache.spark.sql.types.{DataType, Decimal} @@ -122,7 +122,8 @@ object ExpressionCodeGen extends Logging { classOf[IndexedRecord].getName, classOf[AvroSerializer].getName, classOf[GenericRecord].getName, - classOf[GenericInternalRow].getName + classOf[GenericInternalRow].getName, + classOf[Cast].getName ) evaluator.setImplementedInterfaces(Array(classOf[IExpressionEvaluator])) try { diff --git a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestMergeIntoTable2.scala b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestMergeIntoTable2.scala index b77b5c3dbd..8e6acd1be5 100644 --- a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestMergeIntoTable2.scala +++ b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestMergeIntoTable2.scala @@ -673,4 +673,44 @@ class TestMergeIntoTable2 extends HoodieSparkSqlTestBase { ) } } + + test ("Test Merge into with String cast to Double") { + withTempDir { tmp => + val tableName = generateTableName + // Create a cow partitioned table. + spark.sql( + s""" + | create table $tableName ( + | id int, + | name string, + | price double, + | ts long, + | dt string + | ) using hudi + | tblproperties ( + | type = 'cow', + | primaryKey = 'id', + | preCombineField = 'ts' + | ) + | partitioned by(dt) + | location '${tmp.getCanonicalPath}' + """.stripMargin) + // Insert data + spark.sql(s"insert into $tableName select 1, 'a1', cast(10.0 as double), 999, '2021-03-21'") + spark.sql( + s""" + | merge into $tableName as t0 + | using ( + | select 'a1' as name, 1 as id, '10.1' as price, 1000 as ts, '2021-03-21' as dt + | ) as s0 + | on t0.id = s0.id + | when matched then update set t0.price = s0.price, t0.ts = s0.ts + | when not matched then insert * + """.stripMargin + ) + checkAnswer(s"select id,name,price,dt from $tableName")( + Seq(1, "a1", 10.1, "2021-03-21") + ) + } + } }
