Skip to content

Commit 66c5ecc

Browse files
Merge branch 'main' into 184-query-the-iceberg-table-through-all-delta-tablev1-apis
2 parents c97f219 + 8da4c5b commit 66c5ecc

File tree

41 files changed

+318
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+318
-8
lines changed

server/app/src/test/java/io/whitefox/api/deltasharing/SampleTables.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public static InternalTable s3IcebergTable1(
4141
public static final InternalTable icebergtable1 =
4242
icebergTableWithHadoopCatalog("test_db", "icebergtable1");
4343

44+
public static final InternalTable icebergtable2 =
45+
icebergTableWithHadoopCatalog("test_db", "icebergtable2");
46+
4447
public static final String deltaTable1Path = deltaTableUri("delta-table");
4548

4649
public static final String deltaTableWithHistory1Path = deltaTableUri("delta-table-with-history");
@@ -59,7 +62,8 @@ public static StorageManager createStorageManager() {
5962
new SharedTable("table1", "default", "name", deltaTable1),
6063
new SharedTable(
6164
"table-with-history", "default", "name", deltaTableWithHistory1),
62-
new SharedTable("icebergtable1", "default", "name", icebergtable1)),
65+
new SharedTable("icebergtable1", "default", "name", icebergtable1),
66+
new SharedTable("icebergtable2", "default", "name", icebergtable2)),
6367
"name")),
6468
testPrincipal,
6569
0L)));

server/app/src/test/java/io/whitefox/api/deltasharing/server/DeltaSharesApiImplAwsTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ public void updateStorageManagerWithS3Tables() {
8888
0L));
8989
}
9090

91+
@Test
92+
@DisabledOnOs(OS.WINDOWS)
93+
public void icebergTableVersion() {
94+
given()
95+
.when()
96+
.filter(deltaFilter)
97+
.get(
98+
"delta-api/v1/shares/{share}/schemas/{schema}/tables/{table}/version",
99+
"s3share",
100+
"s3schema",
101+
"s3IcebergTable1")
102+
.then()
103+
.statusCode(200)
104+
.header("Delta-Table-Version", "1");
105+
}
106+
91107
@Test
92108
@DisabledOnOs(OS.WINDOWS)
93109
public void icebergTableMetadata() throws IOException {

server/app/src/test/java/io/whitefox/api/deltasharing/server/DeltaSharesApiImplTest.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,13 @@ public void listTables() {
149149
.get("delta-api/v1/shares/{share}/schemas/{schema}/tables", "name", "default")
150150
.then()
151151
.statusCode(200)
152-
.body("items", hasSize(3))
152+
.body("items", hasSize(4))
153153
.body(
154154
"items[0].name",
155-
either(is("table1")).or(is("table-with-history")).or(is("icebergtable1")))
155+
either(is("table1"))
156+
.or(is("table-with-history"))
157+
.or(is("icebergtable1"))
158+
.or(is("icebergtable2")))
156159
.body("items[0].schema", is("default"))
157160
.body("items[0].share", is("name"))
158161
.body("nextPageToken", is(nullValue()));
@@ -206,6 +209,22 @@ public void deltaTableMetadata() throws IOException {
206209
objectMapper.reader().readValue(responseBodyLines[1], MetadataObject.class));
207210
}
208211

212+
@Test
213+
@DisabledOnOs(OS.WINDOWS)
214+
public void icebergTableVersion() {
215+
given()
216+
.when()
217+
.filter(deltaFilter)
218+
.get(
219+
"delta-api/v1/shares/{share}/schemas/{schema}/tables/{table}/version",
220+
"name",
221+
"default",
222+
"icebergtable1")
223+
.then()
224+
.statusCode(200)
225+
.header("Delta-Table-Version", "1");
226+
}
227+
209228
@Test
210229
@DisabledOnOs(OS.WINDOWS)
211230
public void icebergTableMetadata() throws IOException {
@@ -248,10 +267,13 @@ public void listAllTables() {
248267
.get("delta-api/v1/shares/{share}/all-tables", "name")
249268
.then()
250269
.statusCode(200)
251-
.body("items", hasSize(3))
270+
.body("items", hasSize(4))
252271
.body(
253272
"items[0].name",
254-
either(is("table1")).or(is("table-with-history")).or(is("icebergtable1")))
273+
either(is("table1"))
274+
.or(is("table-with-history"))
275+
.or(is("icebergtable1"))
276+
.or(is("icebergtable2")))
255277
.body("items[0].schema", is("default"))
256278
.body("items[0].share", is("name"))
257279
.body("nextPageToken", is(nullValue()));

server/core/src/main/java/io/whitefox/core/services/IcebergSharedTable.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.iceberg.PartitionField;
1414
import org.apache.iceberg.Snapshot;
1515
import org.apache.iceberg.Table;
16+
import org.apache.iceberg.util.SnapshotUtil;
1617

1718
public class IcebergSharedTable implements InternalSharedTable {
1819

@@ -59,8 +60,17 @@ private Optional<Snapshot> getSnapshot(Optional<String> startingTimestamp) {
5960
return startingTimestamp
6061
.map(this::getTimestamp)
6162
.map(Timestamp::getTime)
62-
.map(icebergTable::snapshot)
63-
.or(() -> Optional.of(icebergTable.currentSnapshot()));
63+
.map(this::getSnapshotForTimestampAsOf)
64+
.orElseGet(() -> Optional.ofNullable(icebergTable.currentSnapshot()));
65+
}
66+
67+
private Optional<Snapshot> getSnapshotForTimestampAsOf(long l) {
68+
try {
69+
return Optional.of(SnapshotUtil.snapshotIdAsOfTime(icebergTable, l))
70+
.map(icebergTable::snapshot);
71+
} catch (IllegalArgumentException iea) {
72+
return Optional.empty();
73+
}
6474
}
6575

6676
private Timestamp getTimestamp(String timestamp) {
@@ -71,7 +81,7 @@ private Timestamp getTimestamp(String timestamp) {
7181

7282
@Override
7383
public Optional<Long> getTableVersion(Optional<String> startingTimestamp) {
74-
return Optional.of(0L);
84+
return getSnapshot(startingTimestamp).map(Snapshot::sequenceNumber);
7585
}
7686

7787
@Override

server/core/src/test/java/io/whitefox/core/services/IcebergSharedTableTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,61 @@ void getTableMetadata() {
3030
assertEquals("3369848726892806393", metadata.get().id());
3131
}
3232

33+
@Test
34+
void getTableMetadataWithTimestamp() {
35+
var PTable = new SharedTable(
36+
"icebergtable2",
37+
"default",
38+
"share1",
39+
icebergTableWithHadoopCatalog("test_db", "icebergtable2"));
40+
var DTable = icebergTableLoader.loadTable(PTable);
41+
var metadata = DTable.getMetadata(Optional.of("2024-01-25T01:32:15+01:00"));
42+
assertTrue(metadata.isPresent());
43+
assertEquals("2174306913745765008", metadata.get().id());
44+
}
45+
3346
@Test
3447
void getUnknownTableMetadata() {
3548
var unknownPTable = new SharedTable(
3649
"notFound", "default", "share1", icebergTableWithHadoopCatalog("test_db", "not-found"));
3750
assertThrows(IllegalArgumentException.class, () -> DeltaSharedTable.of(unknownPTable));
3851
}
52+
53+
@Test
54+
void getTableVersion() {
55+
var PTable = new SharedTable(
56+
"icebergtable1",
57+
"default",
58+
"share1",
59+
icebergTableWithHadoopCatalog("test_db", "icebergtable1"));
60+
var DTable = icebergTableLoader.loadTable(PTable);
61+
var version = DTable.getTableVersion(Optional.empty());
62+
assertTrue(version.isPresent());
63+
assertEquals(1, version.get());
64+
}
65+
66+
@Test
67+
void getTableVersionWithTimestamp() {
68+
var PTable = new SharedTable(
69+
"icebergtable2",
70+
"default",
71+
"share1",
72+
icebergTableWithHadoopCatalog("test_db", "icebergtable2"));
73+
var DTable = icebergTableLoader.loadTable(PTable);
74+
var version = DTable.getTableVersion(Optional.of("2024-01-25T01:32:15+01:00"));
75+
assertTrue(version.isPresent());
76+
assertEquals(1, version.get());
77+
}
78+
79+
@Test
80+
void getTableVersionWithTooOldTimestamp() {
81+
var PTable = new SharedTable(
82+
"icebergtable2",
83+
"default",
84+
"share1",
85+
icebergTableWithHadoopCatalog("test_db", "icebergtable2"));
86+
var DTable = icebergTableLoader.loadTable(PTable);
87+
var version = DTable.getTableVersion(Optional.of("2024-01-24T01:32:15+01:00"));
88+
assertTrue(version.isEmpty());
89+
}
3990
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"format-version" : 2,
3+
"table-uuid" : "77734b3f-6c0a-4151-83b9-9be5cf0197d9",
4+
"location" : "/Users/aleksandarmilosevic/Desktop/lake-sharing/server/core/src/testFixtures/resources/iceberg/samples/test_db/icebergtable2",
5+
"last-sequence-number" : 0,
6+
"last-updated-ms" : 1706142410682,
7+
"last-column-id" : 1,
8+
"current-schema-id" : 0,
9+
"schemas" : [ {
10+
"type" : "struct",
11+
"schema-id" : 0,
12+
"fields" : [ {
13+
"id" : 1,
14+
"name" : "id",
15+
"required" : true,
16+
"type" : "long"
17+
} ]
18+
} ],
19+
"default-spec-id" : 0,
20+
"partition-specs" : [ {
21+
"spec-id" : 0,
22+
"fields" : [ ]
23+
} ],
24+
"last-partition-id" : 999,
25+
"default-sort-order-id" : 0,
26+
"sort-orders" : [ {
27+
"order-id" : 0,
28+
"fields" : [ ]
29+
} ],
30+
"properties" : {
31+
"write.parquet.compression-codec" : "zstd"
32+
},
33+
"current-snapshot-id" : -1,
34+
"refs" : { },
35+
"snapshots" : [ ],
36+
"statistics" : [ ],
37+
"snapshot-log" : [ ],
38+
"metadata-log" : [ ]
39+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"format-version" : 2,
3+
"table-uuid" : "77734b3f-6c0a-4151-83b9-9be5cf0197d9",
4+
"location" : "/Users/aleksandarmilosevic/Desktop/lake-sharing/server/core/src/testFixtures/resources/iceberg/samples/test_db/icebergtable2",
5+
"last-sequence-number" : 1,
6+
"last-updated-ms" : 1706142720036,
7+
"last-column-id" : 1,
8+
"current-schema-id" : 0,
9+
"schemas" : [ {
10+
"type" : "struct",
11+
"schema-id" : 0,
12+
"fields" : [ {
13+
"id" : 1,
14+
"name" : "id",
15+
"required" : true,
16+
"type" : "long"
17+
} ]
18+
} ],
19+
"default-spec-id" : 0,
20+
"partition-specs" : [ {
21+
"spec-id" : 0,
22+
"fields" : [ ]
23+
} ],
24+
"last-partition-id" : 999,
25+
"default-sort-order-id" : 0,
26+
"sort-orders" : [ {
27+
"order-id" : 0,
28+
"fields" : [ ]
29+
} ],
30+
"properties" : {
31+
"write.parquet.compression-codec" : "zstd"
32+
},
33+
"current-snapshot-id" : 2174306913745765008,
34+
"refs" : {
35+
"main" : {
36+
"snapshot-id" : 2174306913745765008,
37+
"type" : "branch"
38+
}
39+
},
40+
"snapshots" : [ {
41+
"sequence-number" : 1,
42+
"snapshot-id" : 2174306913745765008,
43+
"timestamp-ms" : 1706142720036,
44+
"summary" : {
45+
"operation" : "append",
46+
"spark.app.id" : "local-1706142687377",
47+
"added-data-files" : "5",
48+
"added-records" : "5",
49+
"added-files-size" : "2094",
50+
"changed-partition-count" : "1",
51+
"total-records" : "5",
52+
"total-files-size" : "2094",
53+
"total-data-files" : "5",
54+
"total-delete-files" : "0",
55+
"total-position-deletes" : "0",
56+
"total-equality-deletes" : "0"
57+
},
58+
"manifest-list" : "/Users/aleksandarmilosevic/Desktop/lake-sharing/server/core/src/testFixtures/resources/iceberg/samples/test_db/icebergtable2/metadata/snap-2174306913745765008-1-f034929c-0fad-4fed-9671-579ecceb195b.avro",
59+
"schema-id" : 0
60+
} ],
61+
"statistics" : [ ],
62+
"snapshot-log" : [ {
63+
"timestamp-ms" : 1706142720036,
64+
"snapshot-id" : 2174306913745765008
65+
} ],
66+
"metadata-log" : [ {
67+
"timestamp-ms" : 1706142410682,
68+
"metadata-file" : "/Users/aleksandarmilosevic/Desktop/lake-sharing/server/core/src/testFixtures/resources/iceberg/samples/test_db/icebergtable2/metadata/v1.metadata.json"
69+
} ]
70+
}

0 commit comments

Comments
 (0)