in polaris-synchronizer/api/src/main/java/org/apache/polaris/tools/sync/polaris/catalog/PolarisCatalog.java [107:160]
public Table loadTable(TableIdentifier ident, String etag) {
String catalogName = this.properties.get("warehouse");
String tablePath =
String.format("%s/%s", this.properties.get("uri"), resourcePaths.table(ident));
HttpRequest.Builder requestBuilder =
HttpRequest.newBuilder()
.uri(URI.create(tablePath))
.GET();
this.authenticationSession.getSessionHeaders().forEach(requestBuilder::header);
// specify last known etag in if-none-match header
if (etag != null) {
requestBuilder.header(HttpHeaders.IF_NONE_MATCH, etag);
}
HttpRequest request = requestBuilder.build();
HttpResponse<String> response;
try {
response = this.httpClient.send(request, HttpResponse.BodyHandlers.ofString());
} catch (Exception e) {
throw new RuntimeException(e);
}
// api responded with 304 not modified, throw from here to signal
if (response.statusCode() == HttpStatus.SC_NOT_MODIFIED) {
throw new MetadataNotModifiedException(ident);
}
String body = response.body();
String newETag = null;
// if etag header is present in response, store new provided etag
if (response.headers().firstValue(HttpHeaders.ETAG).isPresent()) {
newETag = response.headers().firstValue(HttpHeaders.ETAG).get();
}
// build custom base table with metadata so that tool can retrieve the
// location and register it on the target side
LoadTableResponse loadTableResponse = LoadTableResponseParser.fromJson(body);
MetadataWrapperTableOperations ops =
new MetadataWrapperTableOperations(loadTableResponse.tableMetadata());
if (newETag != null) {
return new BaseTableWithETag(ops, CatalogUtil.fullTableName(catalogName, ident), newETag);
}
return new BaseTable(ops, CatalogUtil.fullTableName(catalogName, ident));
}