timothyw553 commented on code in PR #19144:
URL: https://github.com/apache/iceberg/pull/19144#discussion_r4704355142
##########
core/src/test/java/org/apache/iceberg/rest/TestRESTScanPlanning.java:
##########
@@ -1569,6 +1571,79 @@ public <T extends RESTResponse> T execute(
.isNotEqualTo(planId);
}
+ @ParameterizedTest
+ @EnumSource(PlanningMode.class)
+ void ioBuilderBuildsFileIOForRemotePlanning(
+ Function<TestPlanningBehavior.Builder, TestPlanningBehavior.Builder>
planMode) {
+ RESTCatalogAdapter adapter =
+ Mockito.spy(
+ new RESTCatalogAdapter(backendCatalog) {
+ @Override
+ public <T extends RESTResponse> T execute(
+ HTTPRequest request,
+ Class<T> responseType,
+ Consumer<ErrorResponse> errorHandler,
+ Consumer<Map<String, String>> responseHeaders,
+ ParserContext parserContext) {
+ T response =
+ super.execute(
+ request, responseType, errorHandler, responseHeaders,
parserContext);
+ if (response instanceof LoadTableResponse loadTableResponse) {
+ return castResponse(
+ responseType,
+ LoadTableResponse.builder()
+ .withTableMetadata(loadTableResponse.tableMetadata())
+ .addAllConfig(loadTableResponse.config())
+ .addConfig("table-config-key", "table-config-value")
+ .build());
+ }
+
+ return maybeAddStorageCredential(response);
+ }
+ });
+
+
adapter.setPlanningBehavior(planMode.apply(TestPlanningBehavior.builder()).build());
+
+ SessionCatalog.SessionContext userContext =
+ new SessionCatalog.SessionContext("scan-session", "scan-user",
Map.of(), Map.of());
+ List<SessionCatalog.SessionContext> ioBuilderContexts =
Lists.newCopyOnWriteArrayList();
+ List<Map<String, String>> ioBuilderProperties =
Lists.newCopyOnWriteArrayList();
+ RESTCatalog catalog =
+ new RESTCatalog(userContext, (config) -> adapter) {
+ @Override
+ protected RESTSessionCatalog newSessionCatalog(
+ Function<Map<String, String>, RESTClient> clientBuilder) {
+ return new RESTSessionCatalog(
+ clientBuilder,
+ (context, properties) -> {
+ ioBuilderContexts.add(context);
+ ioBuilderProperties.add(properties);
+ return
CatalogUtil.loadFileIO(InMemoryFileIO.class.getName(), properties, null);
Review Comment:
`InMemoryFileIO` doesn't implement `SupportsStorageCredentials`, so this
test doesn't prove that scan credentials actually reach the returned `FileIO`
(it would pass even if credential forwarding were dropped). could we return a
`FileIO` that implements `SupportsStorageCredentials` and assert the expected
prefix and config for both sync and async planning? also probably want to
preserve `loadTableResponse.credentials()` when rebuilding `LoadTableResponse`
above:
```diff
LoadTableResponse.builder()
.withTableMetadata(loadTableResponse.tableMetadata())
.addAllConfig(loadTableResponse.config())
+ .addAllCredentials(loadTableResponse.credentials())
.addConfig("table-config-key", "table-config-value")
.build()
```
##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -704,7 +718,9 @@ private RESTTable restTableForScanPlanning(
paths,
endpoints,
properties(),
- conf,
+ (storageCredentials, planId) ->
Review Comment:
to my understanding, when no `ioBuilder` is configured, scans previously
used catalog properties only, and now they get merged catalog and table
properties (including table `io-impl` overrides and remote signing config). is
that intended? if so, the existing test without `ioBuilder` only checks the
plan id -- could we extend it to verify table property precedence, `io-impl`
override, and remote signing config?
##########
core/src/main/java/org/apache/iceberg/rest/RESTTableScan.java:
##########
@@ -226,21 +222,7 @@ private CloseableIterable<FileScanTask>
planTableScan(PlanTableScanRequest planT
}
private FileIO scanFileIO(List<Credential> storageCredentials) {
- ImmutableMap.Builder<String, String> builder =
- ImmutableMap.<String, String>builder().putAll(catalogProperties);
- if (null != planId) {
- builder.put(RESTCatalogProperties.REST_SCAN_PLAN_ID, planId);
- }
-
- Map<String, String> properties = builder.buildKeepingLast();
- FileIO ioForScan =
- CatalogUtil.loadFileIO(
- catalogProperties.getOrDefault(CatalogProperties.FILE_IO_IMPL,
DEFAULT_FILE_IO_IMPL),
- properties,
- hadoopConf,
- storageCredentials.stream()
- .map(c -> StorageCredential.create(c.prefix(), c.config()))
- .collect(Collectors.toList()));
+ FileIO ioForScan = scanFileIOBuilder.apply(storageCredentials, planId);
FILEIO_TRACKER.put(this, ioForScan);
Review Comment:
if a custom `ioBuilder` returns a shared `FileIO` (like `table().io()`),
could `FILEIO_TRACKER` end up closing it when this scan is GC'd? if `ioBuilder`
isn't guaranteed to return a fresh instance, maybe we should guard against
tracking `table().io()`:
```diff
FileIO ioForScan = scanFileIOBuilder.apply(storageCredentials, planId);
-FILEIO_TRACKER.put(this, ioForScan);
+if (ioForScan != table().io()) {
+ FILEIO_TRACKER.put(this, ioForScan);
+}
return ioForScan;
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]