Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spark][TEST-ONLY] More tests updating Identity Column high water mark #3985

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Changes from 1 commit
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 @@ -577,6 +577,51 @@ trait IdentityColumnDMLSuiteBase
Row(2, 102, CDCReader.CDC_TYPE_UPDATE_POSTIMAGE)))
}
}

test("UPDATE cannot lead to bad high watermarks") {
val tblName = getRandomTableName
withTable(tblName) {
createTable(
tblName,
Seq(
IdentityColumnSpec(
GeneratedByDefault,
startsWith = Some(1),
incrementBy = Some(1)),
TestColumnSpec(colName = "value", dataType = IntegerType)
),
partitionedBy = Seq("value"),
tblProperties = Map(
DeltaConfigs.CHANGE_DATA_FEED.key -> "true",
DeltaConfigs.ENABLE_DELETION_VECTORS_CREATION.key -> "false"
)
)
val deltaLog = DeltaLog.forTable(spark, TableIdentifier(tblName))

sql(s"INSERT INTO $tblName(id, value) VALUES (-5, -5), (-3, -3), (-1, -1)")
val valuesStr = (-999 to -900).map(id => s"($id, -3)").mkString(", ")
sql(s"INSERT INTO $tblName(id, value) VALUES $valuesStr")
sql(s"INSERT INTO $tblName(id, value) VALUES (-1, -1)")
val expectedNumFiles = 5
assert(deltaLog.update().allFiles.count() === expectedNumFiles)
assert(getHighWaterMark(deltaLog.update(), colName = "id").isEmpty,
"High watermark should not be set for user inserted values")

Seq((-1000L, -3)).toDF("id", "value")
.write
.format("delta")
.mode("overwrite")
.option(DeltaOptions.REPLACE_WHERE_OPTION, "value = -3 and id <= -987")
.saveAsTable(tblName)

assert(getHighWaterMark(deltaLog.update(), colName = "id").isEmpty,
"High watermark should not be set for user inserted values")

sql(s"UPDATE $tblName SET value = -3 WHERE id = -1")
assert(getHighWaterMark(deltaLog.update(), colName = "id").isEmpty,
"Updates should not update high watermark")
}
}
}

class IdentityColumnDMLScalaSuite
Expand Down
Loading