timothyw553 commented on code in PR #19149:
URL: https://github.com/apache/iceberg/pull/19149#discussion_r4728530324


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -883,7 +883,7 @@ public static PlanTableScanResponse planTableScan(
             ? Collections.emptyList()
             : IN_MEMORY_PLANNING_STATE.nextPlanTask(initial.second());
     PlanTableScanResponse.Builder builder =
-        PlanTableScanResponse.builder(table.specs())
+        PlanTableScanResponse.builder(RESTPartitionSpecUtil.specs(table, 
initial.first()))

Review Comment:
   here (and on lines 915 and 936) the server responds with task-bound specs, 
but `table.newScan()` still ignores `request.useSnapshotSchema()`. after 
FLOAT->DOUBLE promotion without a new append, a branch read gets `1.1` instead 
of `1.100000023841858` because the server serializes a float `1.1` and the 
client parses it as a double. could we pass `request.useSnapshotSchema()` into 
the scan options before `useSnapshot`, and add a fractional FLOAT->DOUBLE test 
across sync, async, and paginated planning?
   ```diff
   -TableScan tableScan = table.newScan();
   +TableScan tableScan =
   +    table.newScan().option(
   +        "use-snapshot-schema",
   +        Boolean.toString(request.useSnapshotSchema()));
   ```



##########
core/src/main/java/org/apache/iceberg/SnapshotScan.java:
##########
@@ -86,7 +86,7 @@ protected Map<Integer, PartitionSpec> specs() {
     if (!useSnapshotSchema()
         || snapshotId() == null
         || table().currentSnapshot() == null
-        || snapshotId().equals(table().currentSnapshot().snapshotId())) {
+        || tableSchema().schemaId() == table().schema().schemaId()) {

Review Comment:
   spark pins a snapshot via `useSnapshot` for ordinary reads too, so after a 
schema change without a new write this makes `specs()` fall back to the 
snapshot's older schema. in spark CI that already breaks filtering on a newly 
added nested column and drops runtime filters on renamed partition sources, and 
after INT->LONG promotion it returns an `Integer` constant instead of `Long`. 
could we separate snapshot selection from schema selection with an option in 
`DataScan` and `DataTableScan` that spark sets before `useSnapshot`?
   ```diff
    protected boolean useSnapshotSchema() {
   -  return true;
   +  return Boolean.parseBoolean(
   +      options().getOrDefault("use-snapshot-schema", "true"));
    }
   ```



##########
core/src/main/java/org/apache/iceberg/SnapshotScan.java:
##########
@@ -86,7 +86,7 @@ protected Map<Integer, PartitionSpec> specs() {
     if (!useSnapshotSchema()
         || snapshotId() == null
         || table().currentSnapshot() == null

Review Comment:
   what if only a branch has data and `main` has no snapshots yet? 
`table().currentSnapshot()` is `null` in that case, so tag reads skip rebinding 
and filtering on a dropped partition column still fails. should we drop this 
`null` check and add a branch-only tag test?
   ```diff
   -        || table().currentSnapshot() == null
   ```



##########
core/src/main/java/org/apache/iceberg/rest/RESTPartitionSpecUtil.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.rest;
+
+import java.util.Map;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+final class RESTPartitionSpecUtil {
+  private RESTPartitionSpecUtil() {}
+
+  static Map<Integer, PartitionSpec> specs(Table table, Schema schema) {
+    Map<Integer, PartitionSpec> specs = Maps.newHashMap(table.specs());
+    specs.replaceAll((id, spec) -> spec.toUnbound().bind(schema, true));

Review Comment:
   rebinding every spec with `bind(schema, true)` runs name-conflict checks 
against newer specs that the selected snapshot doesn't even use. if column `x` 
was dropped and a later partition field on `y` was named `x`, reading the older 
snapshot throws (same for `event_date` or bucket collisions). could we move 
this into one core helper using `PartitionSpec.Builder.checkConflicts(false)` 
(since `buildUnchecked()` still checks conflicts) and have `RESTTableScan` 
reuse `specs()` once scan state is set instead of rebinding eagerly on every 
refinement?



-- 
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]

Reply via email to