laskoviymishka commented on code in PR #2793:
URL: https://github.com/apache/iceberg-go/pull/2793#discussion_r4771484785
##########
visitors_test.go:
##########
@@ -1345,6 +1345,72 @@ func TestSanitizeExpression(t *testing.T) {
}
}
+func TestSanitizeExpressionBoundNestedField(t *testing.T) {
Review Comment:
Could these five blocks be `t.Run` subtests, or a table like
`TestSanitizeExpression` above? `assert.JSONEq` already reports every mismatch,
so nothing gets hidden. Named subtests would just show which shape broke and
let us run one with `-run`.
##########
visitors_test.go:
##########
@@ -1345,6 +1345,72 @@ func TestSanitizeExpression(t *testing.T) {
}
}
+func TestSanitizeExpressionBoundNestedField(t *testing.T) {
+ schema := iceberg.NewSchema(0,
+ iceberg.NestedField{
+ ID: 1,
+ Name: "user",
+ Type: iceberg.NewStructType(
+ iceberg.NestedField{ID: 2, Name: "email", Type:
iceberg.PrimitiveTypes.String},
+ iceberg.NestedField{ID: 3, Name: "id", Type:
iceberg.PrimitiveTypes.Int64},
+ ),
+ },
+ )
Review Comment:
Should we add a top-level field here as a bound control case? Every input in
`TestSanitizeExpression` is unbound
([visitors_test.go#L1289-L1346](https://github.com/apache/iceberg-go/blob/cfb26753d220f4465e463c1beb87a26d9bea1262/visitors_test.go#L1289-L1346)),
so nothing checks that a bound non-nested predicate still sanitizes to its
plain name.
##########
visitors_test.go:
##########
@@ -1345,6 +1345,72 @@ func TestSanitizeExpression(t *testing.T) {
}
}
+func TestSanitizeExpressionBoundNestedField(t *testing.T) {
+ schema := iceberg.NewSchema(0,
+ iceberg.NestedField{
+ ID: 1,
+ Name: "user",
+ Type: iceberg.NewStructType(
+ iceberg.NestedField{ID: 2, Name: "email", Type:
iceberg.PrimitiveTypes.String},
+ iceberg.NestedField{ID: 3, Name: "id", Type:
iceberg.PrimitiveTypes.Int64},
+ ),
+ },
+ )
+
+ // Bound nested literal predicate preserves full dotted column path and
redacts literal.
+ boundEq, err := iceberg.BindExpr(schema,
iceberg.EqualTo(iceberg.Reference("user.email"), "[email protected]"), true)
+ require.NoError(t, err)
+ sanitized, err := iceberg.SanitizeExpression(boundEq)
+ require.NoError(t, err)
+
+ raw, err := json.Marshal(sanitized)
+ require.NoError(t, err)
+ assert.JSONEq(t,
`{"type":"eq","term":"user.email","value":"(redacted)"}`, string(raw))
+ assert.NotContains(t, string(raw), "[email protected]")
+
+ // Bound nested set predicate preserves full dotted column path and
arity.
+ boundIn, err := iceberg.BindExpr(schema,
iceberg.IsIn(iceberg.Reference("user.id"), int64(10), int64(20)), true)
+ require.NoError(t, err)
+ sanitized, err = iceberg.SanitizeExpression(boundIn)
+ require.NoError(t, err)
+
+ raw, err = json.Marshal(sanitized)
+ require.NoError(t, err)
+ assert.JSONEq(t,
`{"type":"in","term":"user.id","values":["(redacted)-1","(redacted)-2"]}`,
string(raw))
+
+ // Bound nested unary predicate preserves full dotted column path.
+ boundNull, err := iceberg.BindExpr(schema,
iceberg.IsNull(iceberg.Reference("user.email")), true)
+ require.NoError(t, err)
+ sanitized, err = iceberg.SanitizeExpression(boundNull)
+ require.NoError(t, err)
+
+ raw, err = json.Marshal(sanitized)
+ require.NoError(t, err)
+ assert.JSONEq(t, `{"type":"is-null","term":"user.email"}`, string(raw))
+
+ // Bound transform over nested field preserves full dotted column path.
+ boundTf, err := iceberg.BindExpr(schema,
+
iceberg.EqualTo(iceberg.NewUnboundTransform(iceberg.BucketTransform{NumBuckets:
16}, iceberg.Reference("user.id")), int32(5)),
+ true)
+ require.NoError(t, err)
+ sanitized, err = iceberg.SanitizeExpression(boundTf)
+ require.NoError(t, err)
+
+ raw, err = json.Marshal(sanitized)
+ require.NoError(t, err)
+ assert.JSONEq(t,
`{"type":"eq","term":{"type":"transform","transform":"bucket[16]","term":"user.id"},"value":"(redacted)"}`,
string(raw))
+
+ // Case-insensitive bound reference resolves to canonical nested column
path.
+ boundCI, err := iceberg.BindExpr(schema,
iceberg.EqualTo(iceberg.Reference("USER.EMAIL"), "[email protected]"), false)
Review Comment:
Do we want the canonical `user.email` here even though Java differs? Java's
`NamedReference.bind` keeps the caller's spelling
([NamedReference.java#L40-L48](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/api/src/main/java/org/apache/iceberg/expressions/NamedReference.java#L40-L48))
and `ExpressionUtil.sanitize` unbinds by that name
([ExpressionUtil.java#L234-L243](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/api/src/main/java/org/apache/iceberg/expressions/ExpressionUtil.java#L234-L243)),
so Java would log `USER.EMAIL`. Canonical seems better to me; it may still
deserve a line in the test 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: [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]