mattfaltyn commented on code in PR #1558:
URL: https://github.com/apache/iceberg-go/pull/1558#discussion_r3664192171
##########
visitors_test.go:
##########
@@ -233,6 +233,119 @@ func TestAlwaysExprBinding(t *testing.T) {
}
}
+func TestTranslateColumnNamesMissingFieldInitialDefault(t *testing.T) {
Review Comment:
Agreed. I added date cases for a numeric Iceberg Go default and an ISO
metadata value. Both verify that the missing-column filter folds correctly.
##########
table/scanner_internal_test.go:
##########
@@ -969,3 +969,72 @@ func TestProjectionV3SchemaAlreadyHasRowID(t *testing.T) {
}
})
}
+
Review Comment:
Good point. I added a decimal default to the end-to-end scan so filtering
and materialization run together. Binary stays in focused translation coverage
because the projection decoder has a separate bug.
##########
visitors.go:
##########
@@ -496,27 +504,92 @@ func (columnNameTranslator) VisitUnbound(pred
UnboundPredicate) BooleanExpressio
panic(fmt.Errorf("%w: expected bound predicate, got: %s",
ErrInvalidArgument, pred.Term()))
}
+func unbindPredicate(pred BoundPredicate, ref Reference) UnboundPredicate {
+ switch p := pred.(type) {
+ case BoundUnaryPredicate:
+ return p.AsUnbound(ref)
+ case BoundLiteralPredicate:
+ return p.AsUnbound(ref, p.Literal())
+ case BoundSetPredicate:
+ return p.AsUnbound(ref, p.Literals().Members())
+ default:
+ panic(fmt.Errorf("%w: unsupported predicate: %s",
ErrNotImplemented, pred))
+ }
+}
+
+func initialDefaultLiteral(field NestedField) (Literal, error) {
+ switch field.Type.(type) {
+ case BinaryType, FixedType, GeographyType, GeometryType:
+ var data []byte
+ switch val := field.InitialDefault.(type) {
+ case []byte:
+ data = val
+ case string:
+ var err error
+ data, err = base64.StdEncoding.DecodeString(val)
+ if err != nil {
+ return nil, err
+ }
+ default:
+ return nil, fmt.Errorf("%w: invalid %s initial default
%v",
+ ErrInvalidSchema, field.Type,
field.InitialDefault)
+ }
+
+ switch field.Type.(type) {
+ case GeographyType, GeometryType:
+ return LiteralFromBytes(field.Type, data)
+ default:
+ return BinaryLiteral(data).To(field.Type)
+ }
+ case DecimalType:
+ if val, ok := field.InitialDefault.(Decimal); ok {
+ return DecimalLiteral(val).To(field.Type)
+ }
+ }
+
+ data, err := json.Marshal(field.InitialDefault)
+ if err != nil {
+ return nil, err
+ }
+
+ return decodeValue(data, field.Type)
+}
+
func (c columnNameTranslator) VisitBound(pred BoundPredicate)
BooleanExpression {
fileColName, found :=
c.fileSchema.FindColumnName(pred.Term().Ref().Field().ID)
if !found {
// in the case of schema evolution, the column might not be
present
// in the file schema when reading older data
- if pred.Op() == OpIsNull {
+ field := pred.Ref().Field()
+ if field.InitialDefault == nil {
+ if pred.Op() == OpIsNull {
+ return AlwaysTrue{}
+ }
+
+ return AlwaysFalse{}
+ }
+
+ eval, err := ExpressionEvaluator(NewSchema(0, field),
+ unbindPredicate(pred, Reference(field.Name)), true)
+ if err != nil {
+ panic(err)
+ }
+
+ lit, err := initialDefaultLiteral(field)
Review Comment:
Thank you. Errors from evaluator construction, default decoding and
evaluation now include the column name and field ID. An invalid hex test
verifies that context.
--
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]