You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "nastra (via GitHub)" <gi...@apache.org> on 2026/02/19 11:27:49 UTC

[PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

nastra opened a new pull request, #15368:
URL: https://github.com/apache/iceberg/pull/15368

   (no comment)


-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#issuecomment-3949727693

   @singhpk234 @amogh-jahagirdar @danielcweeks can you guys please take another look? I took a slightly different approach here where we're passing the `FileIO` from the actual `Scan` on Spark's read path. This avoids the multi-threaded issue that @singhpk234 mentioned


-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#issuecomment-3928944981

   I pro-actively added this to 1.11 milestone, i feel its something we require for sure, please feel free to remove if you think otherwise 


-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2849006378


##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/TableWithIO.java:
##########
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.spark.source;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Supplier;
+import org.apache.iceberg.AppendFiles;
+import org.apache.iceberg.DeleteFiles;
+import org.apache.iceberg.ExpireSnapshots;
+import org.apache.iceberg.HasTableOperations;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.IncrementalAppendScan;
+import org.apache.iceberg.IncrementalChangelogScan;
+import org.apache.iceberg.ManageSnapshots;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.PartitionStatisticsFile;
+import org.apache.iceberg.PartitionStatisticsScan;
+import org.apache.iceberg.ReplacePartitions;
+import org.apache.iceberg.ReplaceSortOrder;
+import org.apache.iceberg.RewriteFiles;
+import org.apache.iceberg.RewriteManifests;
+import org.apache.iceberg.RowDelta;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.SnapshotRef;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.StatisticsFile;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.TableScan;
+import org.apache.iceberg.Transaction;
+import org.apache.iceberg.UpdateLocation;
+import org.apache.iceberg.UpdatePartitionSpec;
+import org.apache.iceberg.UpdatePartitionStatistics;
+import org.apache.iceberg.UpdateProperties;
+import org.apache.iceberg.UpdateSchema;
+import org.apache.iceberg.UpdateStatistics;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.LocationProvider;
+
+/**
+ * This is a wrapper around {@link Table} and {@link FileIO} where the {@link FileIO} instance might
+ * have more specific storage credentials and should be used for a table scan
+ *
+ * @param table The table instance
+ * @param fileIOForScan The {@link FileIO} instance that might have more specific storage
+ *     credentials for a table scan
+ */
+public record TableWithIO(Table table, Supplier<FileIO> fileIOForScan)

Review Comment:
   I'm a little hesitant to start using `record` as I don't think there's any other usage of it in the baseline.  Feels like we might be adding complexity for those who want to backport without a whole lot of value.



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2844992026


##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SparkPartitioningAwareScan.java:
##########
@@ -79,7 +80,13 @@ abstract class SparkPartitioningAwareScan<T extends PartitionScanTask> extends S
       Schema projection,
       List<Expression> filters,
       Supplier<ScanReport> scanReportSupplier) {
-    super(spark, table, readConf, projection, filters, scanReportSupplier);
+    super(
+        spark,
+        table instanceof BaseTable && null != scan ? new TableWithIO(table, scan::io) : table,

Review Comment:
   both `SparkBatchQueryScan` and `SparkCopyOnWriteScan` extend this class, so whenever a table's `FileIO` is being called, we'll be delegating to the actual `FileIO` of the `Scan`. The super class of `SparkPartitionAwareScan` is `SparkScan`, where `toBatch()` or `toMicroBatchStream()` exist, which would also get the correct `FileIO` instance



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2867656783


##########
open-api/src/testFixtures/java/org/apache/iceberg/rest/RESTServerCatalogAdapter.java:
##########
@@ -46,11 +53,30 @@ public <T extends RESTResponse> T handleRequest(
       Consumer<Map<String, String>> responseHeaders) {
     T restResponse = super.handleRequest(route, vars, httpRequest, responseType, responseHeaders);
 
-    if (restResponse instanceof LoadTableResponse) {
-      if (PropertyUtil.propertyAsBoolean(
-          catalogContext.configuration(), INCLUDE_CREDENTIALS, false)) {
-        applyCredentials(
-            catalogContext.configuration(), ((LoadTableResponse) restResponse).config());
+    if (PropertyUtil.propertyAsBoolean(
+        catalogContext.configuration(), INCLUDE_CREDENTIALS, false)) {
+      if (restResponse instanceof LoadTableResponse response) {
+        applyCredentials(catalogContext.configuration(), response.config());
+      } else if (restResponse instanceof PlanTableScanResponse response
+          && PlanStatus.COMPLETED == response.planStatus()) {
+        return (T)
+            PlanTableScanResponse.builder()
+                .withPlanStatus(response.planStatus())
+                .withPlanId(response.planId())
+                .withFileScanTasks(response.fileScanTasks())
+                .withSpecsById(response.specsById())
+                .withCredentials(createStorageCredentials(catalogContext.configuration()))
+                .build();

Review Comment:
   When rebuilding a completed PlanTableScanResponse to attach credentials, the code drops fields from the original response (e.g., planTasks and deleteFiles). That changes the semantics of the response and can break clients expecting those tasks/files. Preserve all fields from the original response when creating the new response (planTasks, fileScanTasks, deleteFiles, specsById, etc.) and only add/override the credentials.



##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/TableWithIO.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.spark.source;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Supplier;
+import org.apache.iceberg.AppendFiles;
+import org.apache.iceberg.DeleteFiles;
+import org.apache.iceberg.ExpireSnapshots;
+import org.apache.iceberg.HasTableOperations;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.IncrementalAppendScan;
+import org.apache.iceberg.IncrementalChangelogScan;
+import org.apache.iceberg.ManageSnapshots;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.PartitionStatisticsFile;
+import org.apache.iceberg.PartitionStatisticsScan;
+import org.apache.iceberg.ReplacePartitions;
+import org.apache.iceberg.ReplaceSortOrder;
+import org.apache.iceberg.RewriteFiles;
+import org.apache.iceberg.RewriteManifests;
+import org.apache.iceberg.RowDelta;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.SnapshotRef;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.StatisticsFile;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.TableScan;
+import org.apache.iceberg.Transaction;
+import org.apache.iceberg.UpdateLocation;
+import org.apache.iceberg.UpdatePartitionSpec;
+import org.apache.iceberg.UpdatePartitionStatistics;
+import org.apache.iceberg.UpdateProperties;
+import org.apache.iceberg.UpdateSchema;
+import org.apache.iceberg.UpdateStatistics;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.LocationProvider;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+/**
+ * This is a wrapper around {@link Table} and {@link FileIO} where the {@link FileIO} instance might
+ * have more specific storage credentials and should be used for a table scan
+ */
+public class TableWithIO implements Table, HasTableOperations {
+  private final Table table;
+  private final Supplier<FileIO> fileIOForScan;
+
+  public TableWithIO(Table table, Supplier<FileIO> fileIOForScan) {
+    Preconditions.checkArgument(null != table, "Invalid table: null");
+    Preconditions.checkArgument(null != fileIOForScan, "Invalid FileIO supplier: null");
+    this.table = table;
+    this.fileIOForScan = fileIOForScan;
+  }
+
+  @Override
+  public FileIO io() {
+    return fileIOForScan.get();
+  }
+
+  @Override
+  public void refresh() {
+    table.refresh();
+  }
+
+  @Override
+  public String name() {
+    return table.name();
+  }
+
+  @Override
+  public TableScan newScan() {
+    return table.newScan();

Review Comment:
   TableWithIO.newScan() delegates directly to the wrapped table, so scans created from TableWithIO will use the wrapped table's FileIO rather than the FileIO exposed by TableWithIO.io(). That makes the wrapper internally inconsistent and can reintroduce the original credential propagation problem if TableWithIO is used outside the current Spark path. Consider overriding newScan/newBatchScan to ensure the resulting scan uses the intended FileIO, or explicitly document/guard against using this wrapper to create new scans.
   ```suggestion
       throw new UnsupportedOperationException(
           "TableWithIO must not be used to create new scans directly because it would use the "
               + "underlying table's FileIO instead of the FileIO supplied via TableWithIO.io().");
   ```



##########
open-api/src/testFixtures/java/org/apache/iceberg/rest/RESTServerCatalogAdapter.java:
##########
@@ -46,11 +53,30 @@ public <T extends RESTResponse> T handleRequest(
       Consumer<Map<String, String>> responseHeaders) {
     T restResponse = super.handleRequest(route, vars, httpRequest, responseType, responseHeaders);
 
-    if (restResponse instanceof LoadTableResponse) {
-      if (PropertyUtil.propertyAsBoolean(
-          catalogContext.configuration(), INCLUDE_CREDENTIALS, false)) {
-        applyCredentials(
-            catalogContext.configuration(), ((LoadTableResponse) restResponse).config());
+    if (PropertyUtil.propertyAsBoolean(
+        catalogContext.configuration(), INCLUDE_CREDENTIALS, false)) {
+      if (restResponse instanceof LoadTableResponse response) {
+        applyCredentials(catalogContext.configuration(), response.config());
+      } else if (restResponse instanceof PlanTableScanResponse response
+          && PlanStatus.COMPLETED == response.planStatus()) {
+        return (T)
+            PlanTableScanResponse.builder()
+                .withPlanStatus(response.planStatus())
+                .withPlanId(response.planId())
+                .withFileScanTasks(response.fileScanTasks())
+                .withSpecsById(response.specsById())
+                .withCredentials(createStorageCredentials(catalogContext.configuration()))
+                .build();
+      } else if (restResponse instanceof FetchPlanningResultResponse response
+          && PlanStatus.COMPLETED == response.planStatus()) {
+        return (T)
+            FetchPlanningResultResponse.builder()
+                .withPlanStatus(response.planStatus())
+                .withFileScanTasks(response.fileScanTasks())
+                .withPlanTasks(response.planTasks())
+                .withSpecsById(response.specsById())

Review Comment:
   When rebuilding a completed FetchPlanningResultResponse to attach credentials, the code currently does not carry over deleteFiles from the original response. If delete files are present, clients will silently lose required information. Preserve deleteFiles (and any other fields) from the original response when constructing the new response, and only add/override the credentials.
   ```suggestion
                   .withSpecsById(response.specsById())
                   .withDeleteFiles(response.deleteFiles())
   ```



##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/TableWithIO.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.spark.source;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Supplier;
+import org.apache.iceberg.AppendFiles;
+import org.apache.iceberg.DeleteFiles;
+import org.apache.iceberg.ExpireSnapshots;
+import org.apache.iceberg.HasTableOperations;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.IncrementalAppendScan;
+import org.apache.iceberg.IncrementalChangelogScan;
+import org.apache.iceberg.ManageSnapshots;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.PartitionStatisticsFile;
+import org.apache.iceberg.PartitionStatisticsScan;
+import org.apache.iceberg.ReplacePartitions;
+import org.apache.iceberg.ReplaceSortOrder;
+import org.apache.iceberg.RewriteFiles;
+import org.apache.iceberg.RewriteManifests;
+import org.apache.iceberg.RowDelta;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.SnapshotRef;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.StatisticsFile;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.TableScan;
+import org.apache.iceberg.Transaction;
+import org.apache.iceberg.UpdateLocation;
+import org.apache.iceberg.UpdatePartitionSpec;
+import org.apache.iceberg.UpdatePartitionStatistics;
+import org.apache.iceberg.UpdateProperties;
+import org.apache.iceberg.UpdateSchema;
+import org.apache.iceberg.UpdateStatistics;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.LocationProvider;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+/**
+ * This is a wrapper around {@link Table} and {@link FileIO} where the {@link FileIO} instance might
+ * have more specific storage credentials and should be used for a table scan
+ */
+public class TableWithIO implements Table, HasTableOperations {
+  private final Table table;
+  private final Supplier<FileIO> fileIOForScan;
+
+  public TableWithIO(Table table, Supplier<FileIO> fileIOForScan) {
+    Preconditions.checkArgument(null != table, "Invalid table: null");
+    Preconditions.checkArgument(null != fileIOForScan, "Invalid FileIO supplier: null");
+    this.table = table;
+    this.fileIOForScan = fileIOForScan;
+  }
+
+  @Override
+  public FileIO io() {
+    return fileIOForScan.get();
+  }
+
+  @Override
+  public void refresh() {
+    table.refresh();
+  }
+
+  @Override
+  public String name() {
+    return table.name();
+  }
+
+  @Override
+  public TableScan newScan() {
+    return table.newScan();
+  }
+
+  @Override
+  public Schema schema() {
+    return table.schema();
+  }
+
+  @Override
+  public Map<Integer, Schema> schemas() {
+    return table.schemas();
+  }
+
+  @Override
+  public PartitionSpec spec() {
+    return table.spec();
+  }
+
+  @Override
+  public Map<Integer, PartitionSpec> specs() {
+    return table.specs();
+  }
+
+  @Override
+  public SortOrder sortOrder() {
+    return table.sortOrder();
+  }
+
+  @Override
+  public Map<Integer, SortOrder> sortOrders() {
+    return table.sortOrders();
+  }
+
+  @Override
+  public Map<String, String> properties() {
+    return table.properties();
+  }
+
+  @Override
+  public String location() {
+    return table.location();
+  }
+
+  @Override
+  public Snapshot currentSnapshot() {
+    return table.currentSnapshot();
+  }
+
+  @Override
+  public Snapshot snapshot(long snapshotId) {
+    return table.snapshot(snapshotId);
+  }
+
+  @Override
+  public Iterable<Snapshot> snapshots() {
+    return table.snapshots();
+  }
+
+  @Override
+  public List<HistoryEntry> history() {
+    return table.history();
+  }
+
+  @Override
+  public UpdateSchema updateSchema() {
+    return table.updateSchema();
+  }
+
+  @Override
+  public UpdatePartitionSpec updateSpec() {
+    return table.updateSpec();
+  }
+
+  @Override
+  public UpdateProperties updateProperties() {
+    return table.updateProperties();
+  }
+
+  @Override
+  public ReplaceSortOrder replaceSortOrder() {
+    return table.replaceSortOrder();
+  }
+
+  @Override
+  public UpdateLocation updateLocation() {
+    return table.updateLocation();
+  }
+
+  @Override
+  public AppendFiles newAppend() {
+    return table.newAppend();
+  }
+
+  @Override
+  public RewriteFiles newRewrite() {
+    return table.newRewrite();
+  }
+
+  @Override
+  public RewriteManifests rewriteManifests() {
+    return table.rewriteManifests();
+  }
+
+  @Override
+  public OverwriteFiles newOverwrite() {
+    return table.newOverwrite();
+  }
+
+  @Override
+  public RowDelta newRowDelta() {
+    return table.newRowDelta();
+  }
+
+  @Override
+  public ReplacePartitions newReplacePartitions() {
+    return table.newReplacePartitions();
+  }
+
+  @Override
+  public DeleteFiles newDelete() {
+    return table.newDelete();
+  }
+
+  @Override
+  public ExpireSnapshots expireSnapshots() {
+    return table.expireSnapshots();
+  }
+
+  @Override
+  public ManageSnapshots manageSnapshots() {
+    return table.manageSnapshots();
+  }
+
+  @Override
+  public Transaction newTransaction() {
+    return table.newTransaction();
+  }
+
+  @Override
+  public EncryptionManager encryption() {
+    return table.encryption();
+  }
+
+  @Override
+  public LocationProvider locationProvider() {
+    return table.locationProvider();
+  }
+
+  @Override
+  public List<StatisticsFile> statisticsFiles() {
+    return table.statisticsFiles();
+  }
+
+  @Override
+  public Map<String, SnapshotRef> refs() {
+    return table.refs();
+  }
+
+  @Override
+  public IncrementalAppendScan newIncrementalAppendScan() {
+    return table.newIncrementalAppendScan();
+  }
+
+  @Override
+  public IncrementalChangelogScan newIncrementalChangelogScan() {
+    return table.newIncrementalChangelogScan();
+  }
+
+  @Override
+  public PartitionStatisticsScan newPartitionStatisticsScan() {
+    return table.newPartitionStatisticsScan();
+  }
+
+  @Override
+  public AppendFiles newFastAppend() {
+    return table.newFastAppend();
+  }
+
+  @Override
+  public UpdateStatistics updateStatistics() {
+    return table.updateStatistics();
+  }
+
+  @Override
+  public UpdatePartitionStatistics updatePartitionStatistics() {
+    return table.updatePartitionStatistics();
+  }
+
+  @Override
+  public List<PartitionStatisticsFile> partitionStatisticsFiles() {
+    return table.partitionStatisticsFiles();
+  }
+
+  @Override
+  public UUID uuid() {
+    return table.uuid();
+  }
+
+  @Override
+  public TableOperations operations() {
+    return table instanceof HasTableOperations ? ((HasTableOperations) table).operations() : null;
+  }

Review Comment:
   TableWithIO declares it implements HasTableOperations but operations() may return null when the wrapped table is not a HasTableOperations. This violates the HasTableOperations contract and can cause NPEs in callers that rely on it (e.g., SerializableTable metadataFileLocation() calls operations().current()). Either require the wrapped table to implement HasTableOperations (and fail fast in the constructor) or drop HasTableOperations from this wrapper and avoid exposing operations() at all.



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2828743894


##########
core/src/main/java/org/apache/iceberg/rest/RESTTable.java:
##########
@@ -75,11 +79,20 @@ public TableScan newScan() {
         tableIdentifier,
         resourcePaths,
         supportedEndpoints,
-        io(),
+        ioReference,

Review Comment:
   we actually want to change this here because we're passing the `AtomicReference` here, which would later be updated by the `RESTTableScan` with a different storage credential



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2851317854


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTScanPlanning.java:
##########
@@ -953,4 +957,95 @@ public void serverSupportsPlanningButNotCancellation() throws IOException {
     // Verify no exception was thrown - cancelPlan returns false when endpoint not supported
     assertThat(cancelled).isFalse();
   }
+
+  @ParameterizedTest
+  @EnumSource(PlanningMode.class)
+  void fileIOForRemotePlanningIsPropagated(
+      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);
+                return maybeAddStorageCredential(response);
+              }
+            });
+
+    adapter.setPlanningBehavior(planMode.apply(TestPlanningBehavior.builder()).build());
+
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize(
+        "test",
+        ImmutableMap.of(
+            CatalogProperties.FILE_IO_IMPL,
+            "org.apache.iceberg.inmemory.InMemoryFileIO",
+            RESTCatalogProperties.REST_SCAN_PLANNING_ENABLED,
+            "true"));
+
+    Table table = restTableFor(catalog, "file_io_propagation");
+    setParserContext(table);
+
+    assertThat(table.io().properties()).doesNotContainKey(RESTCatalogProperties.REST_SCAN_PLAN_ID);
+    // make sure remote scan planning is called and FileIO gets the planId
+    TableScan tableScan = table.newScan();

Review Comment:
   done



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2832660010


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -116,6 +119,9 @@ public class CatalogHandlers {
   private static final InMemoryPlanningState IN_MEMORY_PLANNING_STATE =
       InMemoryPlanningState.getInstance();
   private static final ExecutorService ASYNC_PLANNING_POOL = Executors.newSingleThreadExecutor();
+  private static final List<Credential> DUMMY_STORAGE_CREDENTIALS =
+      ImmutableList.of(
+          ImmutableCredential.builder().prefix("dummy").putConfig("dummyKey", "dummyVal").build());

Review Comment:
   yeah this was a quick way of verifying the behavior but I agree that we most likely don't want to add dummy credentials in the reference implementation. I've moved this away from here and added a specific adapter that returns some dummy credentials for this single test only



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2827420080


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTScanPlanning.java:
##########
@@ -953,4 +953,18 @@ public void serverSupportsPlanningButNotCancellation() throws IOException {
     // Verify no exception was thrown - cancelPlan returns false when endpoint not supported
     assertThat(cancelled).isFalse();
   }
+
+  @ParameterizedTest
+  @EnumSource(PlanningMode.class)
+  void fileIOForRemotePlanningIsPropagated(

Review Comment:
   this reproduces the issue and fails without the fix



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2851334814


##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/TableWithIO.java:
##########
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.spark.source;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Supplier;
+import org.apache.iceberg.AppendFiles;
+import org.apache.iceberg.DeleteFiles;
+import org.apache.iceberg.ExpireSnapshots;
+import org.apache.iceberg.HasTableOperations;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.IncrementalAppendScan;
+import org.apache.iceberg.IncrementalChangelogScan;
+import org.apache.iceberg.ManageSnapshots;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.PartitionStatisticsFile;
+import org.apache.iceberg.PartitionStatisticsScan;
+import org.apache.iceberg.ReplacePartitions;
+import org.apache.iceberg.ReplaceSortOrder;
+import org.apache.iceberg.RewriteFiles;
+import org.apache.iceberg.RewriteManifests;
+import org.apache.iceberg.RowDelta;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.SnapshotRef;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.StatisticsFile;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.TableScan;
+import org.apache.iceberg.Transaction;
+import org.apache.iceberg.UpdateLocation;
+import org.apache.iceberg.UpdatePartitionSpec;
+import org.apache.iceberg.UpdatePartitionStatistics;
+import org.apache.iceberg.UpdateProperties;
+import org.apache.iceberg.UpdateSchema;
+import org.apache.iceberg.UpdateStatistics;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.LocationProvider;
+
+/**
+ * This is a wrapper around {@link Table} and {@link FileIO} where the {@link FileIO} instance might
+ * have more specific storage credentials and should be used for a table scan
+ *
+ * @param table The table instance
+ * @param fileIOForScan The {@link FileIO} instance that might have more specific storage
+ *     credentials for a table scan
+ */
+public record TableWithIO(Table table, Supplier<FileIO> fileIOForScan)

Review Comment:
   hm I thought we were already using records in some places but I checked again and you're right. I've switched this to a normal class as we don't gain a lot from using a record here



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra closed pull request #15368: API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path
URL: https://github.com/apache/iceberg/pull/15368


-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2828710662


##########
core/src/main/java/org/apache/iceberg/rest/RESTTable.java:
##########
@@ -75,11 +79,20 @@ public TableScan newScan() {
         tableIdentifier,
         resourcePaths,
         supportedEndpoints,
-        io(),
+        ioReference,

Review Comment:
   I don't think you need to change this since you updated the `io()`.  Typically better to use the getter.



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2844992026


##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SparkPartitioningAwareScan.java:
##########
@@ -79,7 +80,13 @@ abstract class SparkPartitioningAwareScan<T extends PartitionScanTask> extends S
       Schema projection,
       List<Expression> filters,
       Supplier<ScanReport> scanReportSupplier) {
-    super(spark, table, readConf, projection, filters, scanReportSupplier);
+    super(
+        spark,
+        table instanceof BaseTable && null != scan ? new TableWithIO(table, scan::io) : table,

Review Comment:
   both `SparkBatchQueryScan` and `SparkCopyOnWriteScan` extend this class, so whenever a table's `FileIO` is being called, we'll be delegating to the actual `FileIO` of the `Scan`



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#issuecomment-4044466709

   closing this one in favor of https://github.com/apache/iceberg/pull/15448


-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2827372575


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -867,7 +873,8 @@ public static PlanTableScanResponse planTableScan(
             .withPlanStatus(PlanStatus.COMPLETED)
             .withPlanId(planId)
             .withFileScanTasks(initial.first())
-            .withSpecsById(table.specs());
+            .withSpecsById(table.specs())
+            .withCredentials(DUMMY_STORAGE_CREDENTIALS);

Review Comment:
   we're returning a dummy storage credential so that the Plan ID gets added to the FileIO instance. If people feel too  strongly about adding dummy credentials here, I think it should also be possible to try and add them in `TestRESTScanPlanning`



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2829248949


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -116,6 +119,9 @@ public class CatalogHandlers {
   private static final InMemoryPlanningState IN_MEMORY_PLANNING_STATE =
       InMemoryPlanningState.getInstance();
   private static final ExecutorService ASYNC_PLANNING_POOL = Executors.newSingleThreadExecutor();
+  private static final List<Credential> DUMMY_STORAGE_CREDENTIALS =
+      ImmutableList.of(
+          ImmutableCredential.builder().prefix("dummy").putConfig("dummyKey", "dummyVal").build());

Review Comment:
   This is not a test class, is it a good idea to inject dummy key values ? 
   I don;t have a cleaner E2E setup scenario in my mind though 



##########
core/src/main/java/org/apache/iceberg/rest/RESTTable.java:
##########
@@ -75,11 +79,20 @@ public TableScan newScan() {
         tableIdentifier,
         resourcePaths,
         supportedEndpoints,
-        io(),
+        ioReference,
         catalogProperties,
         hadoopConf);
   }
 
+  @Override
+  public FileIO io() {

Review Comment:
   I am little bit nervous on multi-threaded scenarios, i understand there are places where we directly refer the `table.io()` (spark executors that i can think of), I wonder if we should fail for now saying illegal state 
   to avoid these scenario : 
   
   Thread 1 : 
   table.newScan()......planFIles()
   table.io().readFile()
   
   Thread2: 
   table.newScan().....planFiles()
   table.io().readFile()
   
   One of the thread might eventually fail, but how about when we do the newScan()...planFiles() and we trying setting the counter then we say hey its not null and not table.io() table level Fileio fail ? 



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#issuecomment-3957506997

   The alternative to using `TableWithIO` is to pass `FileIO` explicitly next to `Table` everywhere, but the diff turns out quite large, because all scan related classes and subclasses of `BaseReader` need to be adjusted. The other downside is that `FileIO` would need to be broadcasted separately (next to `Table`) in `SparkInputPartition` / `SparkBatch`, so I think having `TableWithIO` makes sense and causes less changes across the codebase but is a bit less explicit about the fact that a different `FileIO` instance is used


-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2827361548


##########
core/src/main/java/org/apache/iceberg/inmemory/InMemoryFileIO.java:
##########
@@ -24,12 +24,25 @@
 import org.apache.iceberg.io.InputFile;
 import org.apache.iceberg.io.OutputFile;
 import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
 import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.util.SerializableMap;
 
 public class InMemoryFileIO implements FileIO {
 
   private static final Map<String, byte[]> IN_MEMORY_FILES = Maps.newConcurrentMap();
   private boolean closed = false;
+  private SerializableMap<String, String> properties = SerializableMap.copyOf(ImmutableMap.of());

Review Comment:
   Technically the `InMemoryFileIO` doesn't have properties, so this is mainly being added to make testing FileIO properties easier/possible



##########
core/src/main/java/org/apache/iceberg/inmemory/InMemoryFileIO.java:
##########
@@ -24,12 +24,25 @@
 import org.apache.iceberg.io.InputFile;
 import org.apache.iceberg.io.OutputFile;
 import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
 import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.util.SerializableMap;
 
 public class InMemoryFileIO implements FileIO {
 
   private static final Map<String, byte[]> IN_MEMORY_FILES = Maps.newConcurrentMap();
   private boolean closed = false;
+  private SerializableMap<String, String> properties = SerializableMap.copyOf(ImmutableMap.of());

Review Comment:
   Technically `InMemoryFileIO` doesn't have properties, so this is mainly being added to make testing FileIO properties easier/possible



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2827381528


##########
core/src/main/java/org/apache/iceberg/rest/RESTTable.java:
##########
@@ -75,11 +79,20 @@ public TableScan newScan() {
         tableIdentifier,
         resourcePaths,
         supportedEndpoints,
-        io(),
+        ioReference,
         catalogProperties,
         hadoopConf);
   }
 
+  @Override
+  public FileIO io() {

Review Comment:
   the main issue was where the FileIO in `RESTTableScan` would get storage credentials from the server, but the FileIO instance here would still have the table's IO without any storage credentials, which then causes permission failures in real scenarios



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2829347351


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -116,6 +119,9 @@ public class CatalogHandlers {
   private static final InMemoryPlanningState IN_MEMORY_PLANNING_STATE =
       InMemoryPlanningState.getInstance();
   private static final ExecutorService ASYNC_PLANNING_POOL = Executors.newSingleThreadExecutor();
+  private static final List<Credential> DUMMY_STORAGE_CREDENTIALS =
+      ImmutableList.of(
+          ImmutableCredential.builder().prefix("dummy").putConfig("dummyKey", "dummyVal").build());

Review Comment:
   may be we can hijack the test adatper, so that we intercept these calls and inject this dummy cred in the tests, wdyt ? 



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2829329439


##########
core/src/main/java/org/apache/iceberg/rest/RESTTable.java:
##########
@@ -75,11 +79,20 @@ public TableScan newScan() {
         tableIdentifier,
         resourcePaths,
         supportedEndpoints,
-        io(),
+        ioReference,
         catalogProperties,
         hadoopConf);
   }
 
+  @Override
+  public FileIO io() {

Review Comment:
   I am little bit nervous on multi-threaded scenarios, i understand there are places where we directly refer the `table.io()` (spark executors that i can think of), I wonder if we should fail for now saying illegal state 
   to avoid these scenario : 
   
   Thread 1 : 
   table.newScan()......planFIles()
   table.io().readFile()
   
   Thread2: 
   table.newScan().....planFiles()
   table.io().readFile()
   
   One of the thread might eventually fail, but how about when we do the newScan()...planFiles() and we trying setting the reference then we say hey its not null and not table.io() table level Fileio fail ? 



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2832733013


##########
core/src/main/java/org/apache/iceberg/rest/RESTTable.java:
##########
@@ -75,11 +79,20 @@ public TableScan newScan() {
         tableIdentifier,
         resourcePaths,
         supportedEndpoints,
-        io(),
+        ioReference,
         catalogProperties,
         hadoopConf);
   }
 
+  @Override
+  public FileIO io() {

Review Comment:
   yes I agree and I had the same concern when I added his. I still wanted to put this out for now, since it fixes an obvious problem but doesn't work in a multi-threaded environment. I currently don't have a solution, so let me think a bit more about this



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2832665816


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -867,7 +873,8 @@ public static PlanTableScanResponse planTableScan(
             .withPlanStatus(PlanStatus.COMPLETED)
             .withPlanId(planId)
             .withFileScanTasks(initial.first())
-            .withSpecsById(table.specs());
+            .withSpecsById(table.specs())
+            .withCredentials(DUMMY_STORAGE_CREDENTIALS);

Review Comment:
   I've moved the dummy credentials out of the reference impl into the single test by having a custom adapter, so this shouldn't be a concern anymore



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Properly propagate FileIO for remote scan planning [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2828705355


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -867,7 +873,8 @@ public static PlanTableScanResponse planTableScan(
             .withPlanStatus(PlanStatus.COMPLETED)
             .withPlanId(planId)
             .withFileScanTasks(initial.first())
-            .withSpecsById(table.specs());
+            .withSpecsById(table.specs())
+            .withCredentials(DUMMY_STORAGE_CREDENTIALS);

Review Comment:
   I don't think using dummy credentials is the right way to go.  For testing the load table credentials, I believe we had a way to set them in the environment, which allowed for either not using credentials (insecure environments) or providing a single set of credentials that could be used for all requests.  That should be good enough for the test harness.



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2851793147


##########
core/src/main/java/org/apache/iceberg/BaseScan.java:
##########
@@ -102,7 +102,8 @@ public Table table() {
     return table;
   }
 
-  protected FileIO io() {
+  @Override
+  public FileIO io() {
     return table.io();
   }

Review Comment:
   actually that's a good point. I don't think we're closing the FileIO instance that we're creating inside `RESTTableScan`. I'll open a separate PR to address that



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2852119344


##########
core/src/main/java/org/apache/iceberg/BaseScan.java:
##########
@@ -102,7 +102,8 @@ public Table table() {
     return table;
   }
 
-  protected FileIO io() {
+  @Override
+  public FileIO io() {
     return table.io();
   }

Review Comment:
   opened https://github.com/apache/iceberg/pull/15439



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2854523797


##########
core/src/main/java/org/apache/iceberg/BaseScan.java:
##########
@@ -102,7 +102,8 @@ public Table table() {
     return table;
   }
 
-  protected FileIO io() {
+  @Override
+  public FileIO io() {

Review Comment:
   I'd like to explore the path of using `io` from the scan vs the table because we've now shifted to a point where all IO may not happen from the context of the table, but rather the scan which could have different permissions and possibly even different sources.



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API, Core, Spark: Pass Table with FileIO from Scan on Spark's read path [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #15368:
URL: https://github.com/apache/iceberg/pull/15368#discussion_r2850791296


##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/TableWithIO.java:
##########
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.spark.source;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Supplier;
+import org.apache.iceberg.AppendFiles;
+import org.apache.iceberg.DeleteFiles;
+import org.apache.iceberg.ExpireSnapshots;
+import org.apache.iceberg.HasTableOperations;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.IncrementalAppendScan;
+import org.apache.iceberg.IncrementalChangelogScan;
+import org.apache.iceberg.ManageSnapshots;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.PartitionStatisticsFile;
+import org.apache.iceberg.PartitionStatisticsScan;
+import org.apache.iceberg.ReplacePartitions;
+import org.apache.iceberg.ReplaceSortOrder;
+import org.apache.iceberg.RewriteFiles;
+import org.apache.iceberg.RewriteManifests;
+import org.apache.iceberg.RowDelta;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.SnapshotRef;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.StatisticsFile;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.TableScan;
+import org.apache.iceberg.Transaction;
+import org.apache.iceberg.UpdateLocation;
+import org.apache.iceberg.UpdatePartitionSpec;
+import org.apache.iceberg.UpdatePartitionStatistics;
+import org.apache.iceberg.UpdateProperties;
+import org.apache.iceberg.UpdateSchema;
+import org.apache.iceberg.UpdateStatistics;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.LocationProvider;
+
+/**
+ * This is a wrapper around {@link Table} and {@link FileIO} where the {@link FileIO} instance might
+ * have more specific storage credentials and should be used for a table scan
+ *
+ * @param table The table instance
+ * @param fileIOForScan The {@link FileIO} instance that might have more specific storage
+ *     credentials for a table scan
+ */
+public record TableWithIO(Table table, Supplier<FileIO> fileIOForScan)

Review Comment:
   should we override the name() too, i think default it goes to `toString` but i think having consistent semantics of table.name() would be nice 



##########
core/src/main/java/org/apache/iceberg/BaseScan.java:
##########
@@ -102,7 +102,8 @@ public Table table() {
     return table;
   }
 
-  protected FileIO io() {
+  @Override
+  public FileIO io() {
     return table.io();
   }

Review Comment:
   are we checking these io are correctly closed ?



##########
core/src/test/java/org/apache/iceberg/rest/TestRESTScanPlanning.java:
##########
@@ -953,4 +957,95 @@ public void serverSupportsPlanningButNotCancellation() throws IOException {
     // Verify no exception was thrown - cancelPlan returns false when endpoint not supported
     assertThat(cancelled).isFalse();
   }
+
+  @ParameterizedTest
+  @EnumSource(PlanningMode.class)
+  void fileIOForRemotePlanningIsPropagated(
+      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);
+                return maybeAddStorageCredential(response);
+              }
+            });
+
+    adapter.setPlanningBehavior(planMode.apply(TestPlanningBehavior.builder()).build());
+
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize(
+        "test",
+        ImmutableMap.of(
+            CatalogProperties.FILE_IO_IMPL,
+            "org.apache.iceberg.inmemory.InMemoryFileIO",
+            RESTCatalogProperties.REST_SCAN_PLANNING_ENABLED,
+            "true"));
+
+    Table table = restTableFor(catalog, "file_io_propagation");
+    setParserContext(table);
+
+    assertThat(table.io().properties()).doesNotContainKey(RESTCatalogProperties.REST_SCAN_PLAN_ID);
+    // make sure remote scan planning is called and FileIO gets the planId
+    TableScan tableScan = table.newScan();

Review Comment:
   should we add another call for it and may be inspect the plan-id values are different ?



-- 
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@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org