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


##########
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:
   Done. I dropped the logical-name fallback entirely. The synthetic column now 
carries the translated physical field path (SourcePath, derived from 
fileSchema.FindColumnName in extractRef), and buildExtractColumn resolves the 
source by field id (descending nested structs) with the physical path as the 
id-less fallback. Rename and struct-nested cases both resolve now; an    
unresolved source still errors cleanly instead of null-filling. Covered by 
TestBuildExtractColumnRenamedSource and TestBuildExtractColumnNested.           
                                 
   
   re the "nested containers" - I checked whether an extract can even bind to a 
variant nested in a list/map: Reference.Bind rejects it with "invalid schema" 
(same as any  list/map-element ref, so it's the existing binding behavior, not 
extract-specific), which means those never reach materialization. So struct 
descent covers everything that can actually bind. Left it struct-only for that 
reason - happy to extend the descent to list/map if you'd rather have it 
explicit.      



##########
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:
   Good catch - gave it the same polarity protection as stripExtractPredicates. 
sanitizeVisitor now returns a sanitizedResult carrying a hasUnserializable flag 
(set for extract and bbox), OR-propagated through And/Or, and VisitNot 
collapses a subtree containing one to AlwaysTrue instead of NewNot(AlwaysTrue) 
= AlwaysFalse. So the ScanReport no longer misstates the filter. 
TestSanitizeExpressionExtractCollapses now asserts the NOT(extract) case 
(unbound + bound) resolves to AlwaysTrue and still marshals.
   



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