Skip to content

Commit

Permalink
fix!: Update Iceberg snapshots table to use Instant timestamps. (#5865
Browse files Browse the repository at this point in the history
  • Loading branch information
lbooker42 authored Aug 1, 2024
1 parent 911cf75 commit f2b70b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void testListSnapshots() {
Table table = adapter.listSnapshotsAsTable(tableIdentifier);
Assert.eq(table.size(), "table.size()", 4, "4 snapshots for sales/sales_multi");
Assert.eqTrue(table.getColumnSource("Id").getType().equals(long.class), "id column type");
Assert.eqTrue(table.getColumnSource("TimestampMs").getType().equals(long.class), "timestamp_ms column type");
Assert.eqTrue(table.getColumnSource("Timestamp").getType().equals(Instant.class), "timestamp column type");
Assert.eqTrue(table.getColumnSource("Operation").getType().equals(String.class), "operation column type");
Assert.eqTrue(table.getColumnSource("Summary").getType().equals(Map.class), "summary column type");
Assert.eqTrue(table.getColumnSource("SnapshotObject").getType().equals(Snapshot.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.deephaven.iceberg.layout.IcebergKeyValuePartitionedLayout;
import io.deephaven.iceberg.location.IcebergTableLocationFactory;
import io.deephaven.iceberg.location.IcebergTableLocationKey;
import io.deephaven.time.DateTimeUtils;
import org.apache.iceberg.PartitionField;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Schema;
Expand Down Expand Up @@ -310,8 +311,8 @@ public Table listSnapshotsAsTable(@NotNull final TableIdentifier tableIdentifier
columnSourceMap.put("Id", InMemoryColumnSource.getImmutableMemoryColumnSource(idArr, long.class, null));

final long[] timestampArr = new long[(int) size];
columnSourceMap.put("TimestampMs",
InMemoryColumnSource.getImmutableMemoryColumnSource(timestampArr, long.class, null));
columnSourceMap.put("Timestamp",
InMemoryColumnSource.getImmutableMemoryColumnSource(timestampArr, Instant.class, null));

final String[] operatorArr = new String[(int) size];
columnSourceMap.put("Operation",
Expand All @@ -329,7 +330,8 @@ public Table listSnapshotsAsTable(@NotNull final TableIdentifier tableIdentifier
for (int i = 0; i < size; i++) {
final Snapshot snapshot = snapshots.get(i);
idArr[i] = snapshot.snapshotId();
timestampArr[i] = snapshot.timestampMillis();
// Provided as millis from epoch, convert to nanos
timestampArr[i] = DateTimeUtils.millisToNanos(snapshot.timestampMillis());
operatorArr[i] = snapshot.operation();
summaryArr[i] = snapshot.summary();
snapshotArr[i] = snapshot;
Expand Down

0 comments on commit f2b70b8

Please sign in to comment.