Skip to content

Commit

Permalink
Moved TableIdentifierComparator next to location key
Browse files Browse the repository at this point in the history
  • Loading branch information
malhotrashivam committed Nov 19, 2024
1 parent 22aee1d commit c440d6c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import io.deephaven.base.verify.Require;
import io.deephaven.engine.table.impl.locations.TableLocationKey;
import io.deephaven.iceberg.util.IcebergUtils;
import io.deephaven.parquet.table.ParquetInstructions;
import io.deephaven.parquet.table.location.ParquetTableLocationKey;
import org.apache.iceberg.DataFile;
Expand All @@ -30,8 +29,8 @@ public class IcebergTableParquetLocationKey extends ParquetTableLocationKey impl

private static final Comparator<String> CATALONG_NAME_COMPARATOR = Comparator.nullsFirst(Comparator.naturalOrder());
private static final Comparator<UUID> UUID_COMPARATOR = Comparator.nullsFirst(Comparator.naturalOrder());
private static final Comparator<TableIdentifier> TABLE_ID_COMPARATOR =
Comparator.nullsFirst(IcebergUtils.TABLE_IDENTIFIER_COMPARATOR);
private static final Comparator<TableIdentifier> TABLE_IDENTIFIER_COMPARATOR =
Comparator.nullsFirst(TableIdentifierComparator.INSTANCE);

@Nullable
private final String catalogName;
Expand Down Expand Up @@ -157,7 +156,8 @@ public int compareTo(@NotNull final TableLocationKey other) {
if ((comparisonResult = UUID_COMPARATOR.compare(tableUuid, otherTyped.tableUuid)) != 0) {
return comparisonResult;
}
if ((comparisonResult = TABLE_ID_COMPARATOR.compare(tableIdentifier, otherTyped.tableIdentifier)) != 0) {
if ((comparisonResult =
TABLE_IDENTIFIER_COMPARATOR.compare(tableIdentifier, otherTyped.tableIdentifier)) != 0) {
return comparisonResult;
}
if ((comparisonResult = Long.compare(dataSequenceNumber, otherTyped.dataSequenceNumber)) != 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.iceberg.location;

import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Comparator;

enum TableIdentifierComparator implements Comparator<TableIdentifier> {
INSTANCE;

/**
* Compare two {@link TableIdentifier} instances.
* <p>
* Note that this method assumes:
* <ul>
* <li>There are just two fields {@link TableIdentifier#namespace()} and {@link TableIdentifier#name()} in
* {@link TableIdentifier} class, and both are not null for the objects being compared.</li>
* <li>There is just a single field {@link Namespace#levels()} in the {@link Namespace} class.</li>
* </ul>
* <p>
* {@inheritDoc}
*
* @param ti1 the first object to be compared.
* @param ti2 the second object to be compared.
* @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater
* than the second, respectively.
*/
@Override
public int compare(@NotNull final TableIdentifier ti1, @NotNull final TableIdentifier ti2) {
if (ti1 == ti2) {
return 0;
}
final int comparisonResult;
if ((comparisonResult = Arrays.compare(ti1.namespace().levels(), ti2.namespace().levels())) != 0) {
return comparisonResult;
}
return ti1.name().compareTo(ti2.name());
}
}

This file was deleted.

0 comments on commit c440d6c

Please sign in to comment.