zeroshade commented on code in PR #1607:
URL: https://github.com/apache/iceberg-go/pull/1607#discussion_r3909527617


##########
table/variant_residual.go:
##########
@@ -0,0 +1,252 @@
+// 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 table
+
+import (
+       "context"
+       "fmt"
+       "log/slog"
+       "strconv"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/array"
+       "github.com/apache/arrow-go/v18/arrow/compute"
+       "github.com/apache/arrow-go/v18/arrow/extensions"
+       "github.com/apache/arrow-go/v18/arrow/memory"
+       "github.com/apache/iceberg-go"
+       "github.com/google/uuid"
+)
+
+// augmentSchemaWithExtracts returns fileSchema plus one primitive column per 
variant extract term.
+func augmentSchemaWithExtracts(fileSchema *iceberg.Schema, cols 
[]iceberg.VariantExtractColumn) *iceberg.Schema {
+       fields := fileSchema.Fields()
+       for _, c := range cols {
+               fields = append(fields, iceberg.NestedField{
+                       ID:   c.FieldID,
+                       Name: c.Name,
+                       Type: c.Term.Type().(iceberg.PrimitiveType),
+               })
+       }
+
+       return iceberg.NewSchemaWithIdentifiers(fileSchema.ID, 
fileSchema.IdentifierFieldIDs, fields...)
+}
+
+// buildExtractColumn materializes one variant extract term into a typed Arrow 
array over rec.
+func buildExtractColumn(col iceberg.VariantExtractColumn, rec 
arrow.RecordBatch, mem memory.Allocator) (arrow.Array, arrow.Field, error) {
+       typ := col.Term.Type().(iceberg.PrimitiveType)
+       dt, err := TypeToArrowType(typ, false, false)
+       if err != nil {
+               return nil, arrow.Field{}, err
+       }
+
+       bldr := array.NewBuilder(mem, dt)
+       defer bldr.Release()
+
+       n := int(rec.NumRows())
+       varName := col.Term.Ref().Field().Name
+       varIdx := fieldIndexByID(rec.Schema(), col.Term.Ref().Field().ID)
+       if varIdx < 0 {
+               // Arrow field may lack PARQUET:field_id metadata on 
name-mapping reads; fall back to the column name.
+               if idxs := rec.Schema().FieldIndices(varName); len(idxs) == 1 {

Review Comment:
   This fallback does not work after a name-mapped column rename. For an 
ID-less file, the Arrow batch retains the legacy physical name (for example, 
`old_payload`), while `col.Term.Ref().Field().Name` is the current logical name 
(`payload`), so the scan aborts instead of evaluating the extract. This 
resolution is also top-level-only, so a Variant nested in a struct cannot be 
found/materialized. Please carry or derive the translated physical field path 
and descend through nested containers rather than falling back only to the 
current top-level name.



##########
visitors.go:
##########
@@ -822,6 +901,11 @@ func (sanitizeVisitor) VisitOr(left, right 
BooleanExpression) BooleanExpression
 }
 
 func (sanitizeVisitor) VisitUnbound(pred UnboundPredicate) BooleanExpression {
+       // An extract term has no REST expression-JSON form; keeping it would 
fail json.Marshal. Collapse it like bbox (mirrors VisitBound).
+       if _, ok := pred.Term().(*unboundExtract); ok {
+               return AlwaysTrue{}

Review Comment:
   The unsupported-term collapse needs the same polarity protection as 
`stripExtractPredicates`. Today `NOT(extract(...) = 1)` visits the extract as 
`AlwaysTrue` and then becomes `AlwaysFalse`, so the emitted `ScanReport` 
misstates the filter even though the scan returns rows. Please track whether 
the child contained an extract/bbox and make a `NOT` over such a subtree 
conservatively `AlwaysTrue` (or cause the report filter to be omitted).



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