1
0

[HUDI-3781] fix spark delete sql can not delete record (#5215)

This commit is contained in:
KnightChess
2022-04-08 14:26:40 +08:00
committed by GitHub
parent df87095ef0
commit 7a6272fba1
2 changed files with 51 additions and 1 deletions

View File

@@ -255,7 +255,10 @@ trait ProvidesHoodieConfig extends Logging {
val hoodieProps = getHoodieProps(catalogProperties, tableConfig, sparkSession.sqlContext.conf)
val hiveSyncConfig = buildHiveSyncConfig(hoodieProps, hoodieCatalogTable)
withSparkConf(sparkSession, hoodieCatalogTable.catalogProperties) {
// operation can not be overwrite
val options = hoodieCatalogTable.catalogProperties.-(OPERATION.key())
withSparkConf(sparkSession, options) {
Map(
"path" -> path,
RECORDKEY_FIELD.key -> hoodieCatalogTable.primaryKeys.mkString(","),

View File

@@ -151,4 +151,51 @@ class TestDeleteTable extends TestHoodieSqlBase {
}
}
}
test("Test Delete Table with op upsert") {
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',
| hoodie.datasource.write.operation = 'upsert'
| )
""".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)
)
// delete data from table
spark.sql(s"delete from $tableName where id = 1")
checkAnswer(s"select count(1) from $tableName") (
Seq(0)
)
spark.sql(s"insert into $tableName select 2, 'a2', 10, 1000")
spark.sql(s"delete from $tableName where id = 1")
checkAnswer(s"select id, name, price, ts from $tableName")(
Seq(2, "a2", 10.0, 1000)
)
spark.sql(s"delete from $tableName")
checkAnswer(s"select count(1) from $tableName")(
Seq(0)
)
}
}
}
}