Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,14 @@ trait ProvidesHoodieConfig extends Logging {
// Only validate duplicate key for COW, for MOR it will do the merge with the DefaultHoodieRecordPayload
// on reading.
classOf[ValidateDuplicateKeyPayload].getCanonicalName
} else if (operation == INSERT_OPERATION_OPT_VAL &&
tableType == COW_TABLE_TYPE_OPT_VAL && hasPrecombineColumn == false && insertMode == InsertMode.STRICT){
Comment thread
kazdy marked this conversation as resolved.
Outdated
classOf[ValidateDuplicateKeyPayload].getCanonicalName
Comment thread
kazdy marked this conversation as resolved.
Outdated
} else {
classOf[OverwriteWithLatestAvroPayload].getCanonicalName
}


logInfo(s"Insert statement use write operation type: $operation, payloadClass: $payloadClassName")

withSparkConf(sparkSession, catalogProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class TestInsertTable extends HoodieSparkSqlTestBase {
throw root
}
}

// Create table with dropDup is true
val tableName2 = generateTableName
spark.sql("set hoodie.datasource.write.insert.drop.duplicates = true")
Expand Down Expand Up @@ -297,6 +298,52 @@ class TestInsertTable extends HoodieSparkSqlTestBase {
}
}

test("Test Insert Into None Partitioned Table strict mode with no preCombineField") {
withTempDir { tmp =>
val tableName = generateTableName
spark.sql(s"set hoodie.sql.insert.mode=strict")
// Create none partitioned cow table
spark.sql(
s"""
|create table $tableName (
| id int,
| name string,
| price double
|) using hudi
| location '${tmp.getCanonicalPath}/$tableName'
| tblproperties (
| type = 'cow',
| primaryKey = 'id'
| )
""".stripMargin)
spark.sql(s"insert into $tableName values(1, 'a1', 10)")
checkAnswer(s"select id, name, price from $tableName")(
Seq(1, "a1", 10.0)
)
spark.sql(s"insert into $tableName select 2, 'a2', 12")
checkAnswer(s"select id, name, price from $tableName")(
Seq(1, "a1", 10.0),
Seq(2, "a2", 12.0)
)

assertThrows[HoodieDuplicateKeyException] {
try {
spark.sql(s"insert into $tableName select 1, 'a1', 10")
} catch {
case e: Exception =>
var root: Throwable = e
while (root.getCause != null) {
root = root.getCause
}
throw root
}
}

// disable this config to avoid affect other test in this class.
spark.sql(s"set hoodie.sql.insert.mode=upsert")
}
}

test("Test Insert Overwrite") {
withTempDir { tmp =>
val tableName = generateTableName
Expand Down