From f2b70b8ae65bd48349ca6fe9bbdb22acdacf0ca3 Mon Sep 17 00:00:00 2001 From: Larry Booker Date: Wed, 31 Jul 2024 17:44:39 -0700 Subject: [PATCH] fix!: Update Iceberg snapshots table to use `Instant` timestamps. (#5865) New snapshot table view: image image --- .../java/io/deephaven/iceberg/util/IcebergToolsTest.java | 2 +- .../io/deephaven/iceberg/util/IcebergCatalogAdapter.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/extensions/iceberg/s3/src/test/java/io/deephaven/iceberg/util/IcebergToolsTest.java b/extensions/iceberg/s3/src/test/java/io/deephaven/iceberg/util/IcebergToolsTest.java index 5e1f9f98639..da373ef3a37 100644 --- a/extensions/iceberg/s3/src/test/java/io/deephaven/iceberg/util/IcebergToolsTest.java +++ b/extensions/iceberg/s3/src/test/java/io/deephaven/iceberg/util/IcebergToolsTest.java @@ -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), diff --git a/extensions/iceberg/src/main/java/io/deephaven/iceberg/util/IcebergCatalogAdapter.java b/extensions/iceberg/src/main/java/io/deephaven/iceberg/util/IcebergCatalogAdapter.java index 8513d0344fd..c3ad3cd4970 100644 --- a/extensions/iceberg/src/main/java/io/deephaven/iceberg/util/IcebergCatalogAdapter.java +++ b/extensions/iceberg/src/main/java/io/deephaven/iceberg/util/IcebergCatalogAdapter.java @@ -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; @@ -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", @@ -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;