[HUDI-2642] Add support ignoring case in update sql operation (#3882)
This commit is contained in:
@@ -51,7 +51,10 @@ case class UpdateHoodieTableCommand(updateTable: UpdateTable) extends RunnableCo
|
|||||||
}.toMap
|
}.toMap
|
||||||
|
|
||||||
val updateExpressions = table.output
|
val updateExpressions = table.output
|
||||||
.map(attr => name2UpdateValue.getOrElse(attr.name, attr))
|
.map(attr => {
|
||||||
|
val UpdateValueOption = name2UpdateValue.find(f => sparkSession.sessionState.conf.resolver(f._1, attr.name))
|
||||||
|
if(UpdateValueOption.isEmpty) attr else UpdateValueOption.get._2
|
||||||
|
})
|
||||||
.filter { // filter the meta columns
|
.filter { // filter the meta columns
|
||||||
case attr: AttributeReference =>
|
case attr: AttributeReference =>
|
||||||
!HoodieRecord.HOODIE_META_COLUMNS.asScala.toSet.contains(attr.name)
|
!HoodieRecord.HOODIE_META_COLUMNS.asScala.toSet.contains(attr.name)
|
||||||
|
|||||||
@@ -27,16 +27,16 @@ class TestUpdateTable extends TestHoodieSqlBase {
|
|||||||
spark.sql(
|
spark.sql(
|
||||||
s"""
|
s"""
|
||||||
|create table $tableName (
|
|create table $tableName (
|
||||||
| id int,
|
| ID int,
|
||||||
| name string,
|
| NAME string,
|
||||||
| price double,
|
| PRICE double,
|
||||||
| ts long
|
| TS long
|
||||||
|) using hudi
|
|) using hudi
|
||||||
| location '${tmp.getCanonicalPath}/$tableName'
|
| location '${tmp.getCanonicalPath}/$tableName'
|
||||||
| tblproperties (
|
| options (
|
||||||
| type = '$tableType',
|
| type = '$tableType',
|
||||||
| primaryKey = 'id',
|
| primaryKey = 'ID',
|
||||||
| preCombineField = 'ts'
|
| preCombineField = 'TS'
|
||||||
| )
|
| )
|
||||||
""".stripMargin)
|
""".stripMargin)
|
||||||
// insert data to table
|
// insert data to table
|
||||||
@@ -59,4 +59,45 @@ class TestUpdateTable extends TestHoodieSqlBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("Test ignoring case for Update Table") {
|
||||||
|
withTempDir { tmp =>
|
||||||
|
Seq("cow", "mor").foreach {tableType =>
|
||||||
|
val tableName = generateTableName
|
||||||
|
// create table
|
||||||
|
spark.sql(
|
||||||
|
s"""
|
||||||
|
|create table $tableName (
|
||||||
|
| id int,
|
||||||
|
| name string,
|
||||||
|
| price double,
|
||||||
|
| ts long
|
||||||
|
|) using hudi
|
||||||
|
| location '${tmp.getCanonicalPath}/$tableName'
|
||||||
|
| tblproperties (
|
||||||
|
| type = '$tableType',
|
||||||
|
| primaryKey = 'id',
|
||||||
|
| preCombineField = 'ts'
|
||||||
|
| )
|
||||||
|
""".stripMargin)
|
||||||
|
// insert data to table
|
||||||
|
spark.sql(s"insert into $tableName select 1, 'a1', 10, 1000")
|
||||||
|
checkAnswer(s"select id, name, price, ts from $tableName")(
|
||||||
|
Seq(1, "a1", 10.0, 1000)
|
||||||
|
)
|
||||||
|
|
||||||
|
// update data
|
||||||
|
spark.sql(s"update $tableName set PRICE = 20 where ID = 1")
|
||||||
|
checkAnswer(s"select id, name, price, ts from $tableName")(
|
||||||
|
Seq(1, "a1", 20.0, 1000)
|
||||||
|
)
|
||||||
|
|
||||||
|
// update data
|
||||||
|
spark.sql(s"update $tableName set PRICE = PRICE * 2 where ID = 1")
|
||||||
|
checkAnswer(s"select id, name, price, ts from $tableName")(
|
||||||
|
Seq(1, "a1", 40.0, 1000)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user