Skip to content

Commit

Permalink
[Kernel]Fix test failure by adding equals method to Format.java (#4229)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan233usc authored Mar 6, 2025
1 parent b24c5a6 commit 2ae0eae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,18 @@ public Row toRow() {
public String toString() {
return "Format{" + "provider='" + provider + '\'' + ", options=" + options + '}';
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
Format format = (Format) o;
return provider.equals(format.provider) && options.equals(format.options);
}

@Override
public int hashCode() {
return Objects.hash(provider, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import io.delta.kernel.defaults.utils.TestUtils
import io.delta.kernel.engine.Engine
import io.delta.kernel.internal.DeltaLogActionUtils.DeltaAction
import io.delta.kernel.internal.TableImpl
import io.delta.kernel.internal.actions.{AddFile, SingleAction}
import io.delta.kernel.internal.actions.{AddFile, Metadata, SingleAction}
import io.delta.kernel.internal.checksum.{ChecksumReader, CRCInfo}
import io.delta.kernel.internal.fs.Path
import io.delta.kernel.internal.util.FileNames
Expand Down Expand Up @@ -101,11 +101,26 @@ class ChecksumSimpleComparisonSuite extends DeltaTableWriteSuiteBase with TestUt
}
}

implicit class MetadataOpt(private val metadata: Metadata) {
def withDeterministicIdAndCreateTime: Metadata = {
new Metadata(
"id",
metadata.getName,
metadata.getDescription,
metadata.getFormat,
metadata.getSchemaString,
metadata.getSchema,
metadata.getPartitionColumns,
Optional.empty(),
metadata.getConfigurationMapValue)
}
}

implicit class CrcInfoOpt(private val crcInfo: CRCInfo) {
def copyWithoutTxnId(): CRCInfo = {
def withoutTransactionId: CRCInfo = {
new CRCInfo(
crcInfo.getVersion,
crcInfo.getMetadata,
crcInfo.getMetadata.withDeterministicIdAndCreateTime,
crcInfo.getProtocol,
crcInfo.getTableSizeBytes,
crcInfo.getNumFiles,
Expand All @@ -128,7 +143,7 @@ class ChecksumSimpleComparisonSuite extends DeltaTableWriteSuiteBase with TestUt
val sparkCrc = readCrcInfo(engine, sparkTablePath, version)
val kernelCrc = readCrcInfo(engine, kernelTablePath, version)
// Remove the randomly generated TxnId
assert(sparkCrc.copyWithoutTxnId() === kernelCrc.copyWithoutTxnId())
assert(sparkCrc.withoutTransactionId === kernelCrc.withoutTransactionId)
}

private def readCrcInfo(engine: Engine, path: String, version: Long): CRCInfo = {
Expand Down

0 comments on commit 2ae0eae

Please sign in to comment.