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] add Delta logging to UniForm conversion mismatch #3327

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all 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 @@ -367,6 +367,7 @@ class IcebergConverter(spark: SparkSession)
}

icebergTxn.commit()
validateIcebergCommit(snapshotToConvert, catalogTable)
Some(snapshotToConvert.version, snapshotToConvert.timestamp)
}

Expand Down Expand Up @@ -482,4 +483,36 @@ class IcebergConverter(spark: SparkSession)
}
}

/**
* Validate the Iceberg conversion by comparing the number of files and size in bytes
* between the converted Iceberg table and the Delta table.
* TODO: throw exception and proactively abort conversion transaction
*/
private def validateIcebergCommit(snapshotToConvert: Snapshot, catalogTable: CatalogTable) = {
val table = loadIcebergTable(snapshotToConvert, catalogTable)
val lastConvertedDeltaVersion = IcebergConverter.getLastConvertedDeltaVersion(table)
table.map {t =>
if (lastConvertedDeltaVersion.contains(snapshotToConvert.version) &&
t.currentSnapshot() != null) {
val icebergNumOfFiles = t.currentSnapshot().summary().asScala
.getOrElse("total-data-files", "-1").toLong
val icebergTotalBytes = t.currentSnapshot().summary().asScala
.getOrElse("total-files-size", "-1").toLong

if (icebergNumOfFiles != snapshotToConvert.numOfFiles ||
icebergTotalBytes != snapshotToConvert.sizeInBytes) {
recordDeltaEvent(
snapshotToConvert.deltaLog, "delta.iceberg.conversion.mismatch",
data = Map(
"lastConvertedDeltaVersion" -> snapshotToConvert.version,
"numOfFiles" -> snapshotToConvert.numOfFiles,
"icebergNumOfFiles" -> icebergNumOfFiles,
"sizeInBytes" -> snapshotToConvert.sizeInBytes,
"icebergTotalBytes" -> icebergTotalBytes
)
)
}
}
}
}
}
Loading