You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "eric-maynard (via GitHub)" <gi...@apache.org> on 2025/04/18 20:32:06 UTC
[PR] Support snapshots=refs [polaris]
eric-maynard opened a new pull request, #1405:
URL: https://github.com/apache/polaris/pull/1405
The IRC (and Polaris) spec states that a client can request a subset of snapshots when loading a table:
> The snapshots to return in the body of the metadata. Setting the value to `all` would return the full set of snapshots currently valid for the table. Setting the value to `refs` would load all snapshots referenced by branches or tags.
This PR adds support for the above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support snapshots=refs [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #1405:
URL: https://github.com/apache/polaris/pull/1405#discussion_r2052324206
##########
service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java:
##########
@@ -580,7 +586,18 @@ public Optional<LoadTableResponse> loadTableIfStale(
}
}
- return Optional.of(CatalogHandlers.loadTable(baseCatalog, tableIdentifier));
+ Table table = baseCatalog.loadTable(tableIdentifier);
+ if (table instanceof BaseMetadataTable) {
+ throw new NoSuchTableException("Table does not exist: %s", tableIdentifier.toString());
+ } else if (!(table instanceof BaseTable)) {
+ throw new IllegalStateException("Cannot wrap catalog that does not produce BaseTable");
+ } else {
+ LoadTableResponse rawResponse =
+ LoadTableResponse.builder()
+ .withTableMetadata(((BaseTable) table).operations().current())
+ .build();
+ return Optional.of(filterResponseToSnapshots(rawResponse, snapshots));
+ }
Review Comment:
Couldn't you keep the call to `CatalogHandlers.loadTable`?
```suggestion
LoadTableResponse rawResponse = CatalogHandlers.loadTable(baseCatalog, tableIdentifier);
return Optional.of(filterResponseToSnapshots(rawResponse, snapshots));
```
##########
integration-tests/src/main/java/org/apache/polaris/service/it/env/CatalogApi.java:
##########
@@ -149,6 +149,18 @@ public void dropTable(String catalog, TableIdentifier id) {
}
}
+ public int loadTable(String catalog, TableIdentifier id, String snapshots) {
+ String ns = RESTUtil.encodeNamespace(id.namespace());
+ try (Response res =
+ request(
+ "v1/{cat}/namespaces/" + ns + "/tables/{table}",
+ Map.of("cat", catalog, "table", id.name()),
+ Map.of("snapshots", snapshots))
+ .get()) {
+ return res.getStatus();
+ }
+ }
+
Review Comment:
Wouldn't it be nicer if this method actually returned the `LoadTableResponse` object? This way your test could inspect the returned snapshots.
```suggestion
public LoadTableResponse loadTable(String catalog, TableIdentifier id, String snapshots) {
String ns = RESTUtil.encodeNamespace(id.namespace());
try (Response res =
request(
"v1/{cat}/namespaces/" + ns + "/tables/{table}",
Map.of("cat", catalog, "table", id.name()),
snapshots == null ? Map.of() : Map.of("snapshots", snapshots))
.get()) {
if (res.getStatus() == Response.Status.OK.getStatusCode()) {
return res.readEntity(LoadTableResponse.class);
}
throw new RESTException(
"Unhandled error: %s",
((ErrorHandler) ErrorHandlers.defaultErrorHandler())
.parseResponse(res.getStatus(), res.readEntity(String.class)));
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support snapshots=refs [polaris]
Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard merged PR #1405:
URL: https://github.com/apache/polaris/pull/1405
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support snapshots=refs [polaris]
Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #1405:
URL: https://github.com/apache/polaris/pull/1405#discussion_r2051400734
##########
service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java:
##########
@@ -1010,6 +1028,31 @@ public void renameView(RenameTableRequest request) {
CatalogHandlers.renameView(viewCatalog, request);
}
+ private @Nonnull LoadTableResponse filterResponseToSnapshots(
+ LoadTableResponse loadTableResponse, String snapshots) {
+ if (snapshots == null || snapshots.equalsIgnoreCase(SNAPSHOTS_ALL)) {
+ return loadTableResponse;
+ } else if (snapshots.equalsIgnoreCase(SNAPSHOTS_REFS)) {
+ TableMetadata metadata = loadTableResponse.tableMetadata();
+
+ Set<Long> referencedSnapshotIds =
+ metadata.refs().values().stream()
+ .map(SnapshotRef::snapshotId)
+ .collect(Collectors.toSet());
+
+ TableMetadata filteredMetadata =
+ metadata.removeSnapshotsIf(s -> referencedSnapshotIds.contains(s.snapshotId()));
Review Comment:
The method is a bit confusing! This reads as `remove snapshots if a snapshot's ID is not in referencedSnapshotIds`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support snapshots=refs [polaris]
Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #1405:
URL: https://github.com/apache/polaris/pull/1405#discussion_r2051400734
##########
service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java:
##########
@@ -1010,6 +1028,31 @@ public void renameView(RenameTableRequest request) {
CatalogHandlers.renameView(viewCatalog, request);
}
+ private @Nonnull LoadTableResponse filterResponseToSnapshots(
+ LoadTableResponse loadTableResponse, String snapshots) {
+ if (snapshots == null || snapshots.equalsIgnoreCase(SNAPSHOTS_ALL)) {
+ return loadTableResponse;
+ } else if (snapshots.equalsIgnoreCase(SNAPSHOTS_REFS)) {
+ TableMetadata metadata = loadTableResponse.tableMetadata();
+
+ Set<Long> referencedSnapshotIds =
+ metadata.refs().values().stream()
+ .map(SnapshotRef::snapshotId)
+ .collect(Collectors.toSet());
+
+ TableMetadata filteredMetadata =
+ metadata.removeSnapshotsIf(s -> referencedSnapshotIds.contains(s.snapshotId()));
Review Comment:
The method is a bit confusing! This reads as `remove snapshots if a snapshot's ID is not in referencedSnapshotIds`, you're right
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support snapshots=refs [polaris]
Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #1405:
URL: https://github.com/apache/polaris/pull/1405#discussion_r2051279792
##########
service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java:
##########
@@ -1010,6 +1028,31 @@ public void renameView(RenameTableRequest request) {
CatalogHandlers.renameView(viewCatalog, request);
}
+ private @Nonnull LoadTableResponse filterResponseToSnapshots(
+ LoadTableResponse loadTableResponse, String snapshots) {
+ if (snapshots == null || snapshots.equalsIgnoreCase(SNAPSHOTS_ALL)) {
+ return loadTableResponse;
+ } else if (snapshots.equalsIgnoreCase(SNAPSHOTS_REFS)) {
+ TableMetadata metadata = loadTableResponse.tableMetadata();
+
+ Set<Long> referencedSnapshotIds =
+ metadata.refs().values().stream()
+ .map(SnapshotRef::snapshotId)
+ .collect(Collectors.toSet());
+
+ TableMetadata filteredMetadata =
+ metadata.removeSnapshotsIf(s -> referencedSnapshotIds.contains(s.snapshotId()));
Review Comment:
[doubt] I thought we want to return the snapshots that are being referenced ? should this be a
```suggestion
TableMetadata filteredMetadata =
metadata.removeSnapshotsIf(s -> ! referencedSnapshotIds.contains(s.snapshotId()));
```
##########
integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisRestCatalogIntegrationTest.java:
##########
@@ -1343,4 +1346,67 @@ public void testDropNonExistingGenericTable() {
genericTableApi.purge(currentCatalogName, namespace);
}
+
+ @Test
+ public void testLoadTableWithSnapshots() {
+ Namespace namespace = Namespace.of("ns1");
+ restCatalog.createNamespace(namespace);
+ TableIdentifier tableIdentifier = TableIdentifier.of(namespace, "tbl1");
+ restCatalog.createTable(tableIdentifier, SCHEMA);
+
+ assertThat(catalogApi.loadTable(currentCatalogName, tableIdentifier, "ALL"))
+ .isEqualTo(OK.getStatusCode());
+ assertThat(catalogApi.loadTable(currentCatalogName, tableIdentifier, "all"))
+ .isEqualTo(OK.getStatusCode());
+ assertThat(catalogApi.loadTable(currentCatalogName, tableIdentifier, "refs"))
+ .isEqualTo(OK.getStatusCode());
+ assertThat(catalogApi.loadTable(currentCatalogName, tableIdentifier, "REFS"))
+ .isEqualTo(OK.getStatusCode());
+ assertThat(catalogApi.loadTable(currentCatalogName, tableIdentifier, "not-real"))
+ .isEqualTo(BAD_REQUEST.getStatusCode());
+
+ catalogApi.purge(currentCatalogName, namespace);
+ }
+
+ @Test
+ public void testLoadTableWithRefFiltering() {
+ Namespace namespace = Namespace.of("ns1");
+ restCatalog.createNamespace(namespace);
+ TableIdentifier tableIdentifier = TableIdentifier.of(namespace, "tbl1");
+
+ restCatalog.createTable(tableIdentifier, SCHEMA);
+
+ Table table = restCatalog.loadTable(tableIdentifier);
+
+ // Create an orphaned snapshot:
+ table.newAppend().appendFile(FILE_A).commit();
+ long snapshotIdA = table.currentSnapshot().snapshotId();
+ table.newAppend().appendFile(FILE_B).commit();
+ table.manageSnapshots().setCurrentSnapshot(snapshotIdA).commit();
+
+ String ns = RESTUtil.encodeNamespace(tableIdentifier.namespace());
+ try (Response res =
+ catalogApi
+ .request(
+ "v1/{cat}/namespaces/" + ns + "/tables/{table}",
+ Map.of("cat", currentCatalogName, "table", tableIdentifier.name()),
+ Map.of("snapshots", "all"))
+ .get()) {
+ LoadTableResponse responseContent = res.readEntity(LoadTableResponse.class);
+ assertThat(responseContent.tableMetadata().snapshots().size()).isEqualTo(2);
+ }
+
+ try (Response res =
+ catalogApi
+ .request(
+ "v1/{cat}/namespaces/" + ns + "/tables/{table}",
+ Map.of("cat", currentCatalogName, "table", tableIdentifier.name()),
+ Map.of("snapshots", "refs"))
+ .get()) {
+ LoadTableResponse responseContent = res.readEntity(LoadTableResponse.class);
+ assertThat(responseContent.tableMetadata().snapshots().size()).isEqualTo(1);
Review Comment:
can we also assert the intended snapshot id ? as if we got back the snapshot-id we wanted ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org