You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "zeroshade (via GitHub)" <gi...@apache.org> on 2026/08/06 22:14:54 UTC
Re: [PR] fix(substrait): convert nanosecond timestamp literals [iceberg-go]
zeroshade commented on code in PR #1590:
URL: https://github.com/apache/iceberg-go/pull/1590#discussion_r3732157903
##########
table/substrait/substrait_test.go:
##########
@@ -137,6 +137,80 @@ func TestExprs(t *testing.T) {
}
}
+func TestNanosecondTimestampLiterals(t *testing.T) {
+ tests := []struct {
+ name string
+ fieldType iceberg.Type
+ predicate iceberg.BooleanExpression
+ wantExpr string
+ wantValues []string
+ wantType string
+ }{
+ {
+ name: "timestamp equality",
+ fieldType: iceberg.PrimitiveTypes.TimestampNs,
+ predicate: iceberg.EqualTo(iceberg.Reference("ts"), iceberg.TimestampNano(123456789)),
+ wantExpr: "equal(.field(0) => precision_timestamp?<9>, precision_timestamp<9>(1970-01-01 00:00:00.123456789)) => boolean?",
+ wantValues: []string{"1970-01-01 00:00:00.123456789"},
+ wantType: "precision_timestamp<9>",
+ },
+ {
+ name: "timestamp with timezone equality before epoch",
+ fieldType: iceberg.PrimitiveTypes.TimestampTzNs,
+ predicate: iceberg.EqualTo(iceberg.Reference("ts"), iceberg.TimestampNano(-123456789)),
+ wantExpr: "equal(.field(0) => precision_timestamp_tz?<9>, precision_timestamp_tz<9>(1969-12-31T23:59:59.876543211Z)) => boolean?",
+ wantValues: []string{"1969-12-31T23:59:59.876543211Z"},
+ wantType: "precision_timestamp_tz<9>",
+ },
+ {
+ name: "timestamp in",
+ fieldType: iceberg.PrimitiveTypes.TimestampNs,
+ predicate: iceberg.IsIn(iceberg.Reference("ts"), iceberg.TimestampNano(1), iceberg.TimestampNano(1001)),
+ wantValues: []string{"1970-01-01 00:00:00.000000001", "1970-01-01 00:00:00.000001001"},
+ wantType: "precision_timestamp<9>",
+ },
+ {
+ name: "timestamp with timezone not in",
+ fieldType: iceberg.PrimitiveTypes.TimestampTzNs,
+ predicate: iceberg.NotIn(iceberg.Reference("ts"), iceberg.TimestampNano(-1), iceberg.TimestampNano(1001)),
+ wantValues: []string{"1969-12-31T23:59:59.999999999Z", "1970-01-01T00:00:00.000001001Z"},
+ wantType: "precision_timestamp_tz<9>",
+ },
+ {
+ name: "timestamp greater than",
+ fieldType: iceberg.PrimitiveTypes.TimestampNs,
+ predicate: iceberg.GreaterThan(iceberg.Reference("ts"), iceberg.TimestampNano(42)),
+ wantExpr: "gt(.field(0) => precision_timestamp?<9>, precision_timestamp<9>(1970-01-01 00:00:00.000000042)) => boolean?",
+ },
+ {
+ name: "timestamp with timezone less than",
+ fieldType: iceberg.PrimitiveTypes.TimestampTzNs,
+ predicate: iceberg.LessThan(iceberg.Reference("ts"), iceberg.TimestampNano(-42)),
+ wantExpr: "lt(.field(0) => precision_timestamp_tz?<9>, precision_timestamp_tz<9>(1969-12-31T23:59:59.999999958Z)) => boolean?",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ sc := iceberg.NewSchema(1, iceberg.NestedField{ID: 1, Name: "ts", Type: tt.fieldType})
+ bound, err := iceberg.BindExpr(sc, tt.predicate, true)
+ require.NoError(t, err)
+
+ _, converted, err := substrait.ConvertExpr(sc, bound, true)
+ require.NoError(t, err)
+ if tt.wantExpr != "" {
+ assert.Equal(t, tt.wantExpr, converted.String())
+ }
+ for _, value := range tt.wantValues {
Review Comment:
Non-blocking: for the IN and NOT IN cases, `Contains` can pass when one literal is wrong and becomes vacuous if rendering changes. Consider giving those cases complete `wantExpr` values and asserting `Equal`, as the tests directly above do; these are the two cases that specifically exercise `toSubstraitLiteralSet`.
##########
table/substrait/substrait_test.go:
##########
@@ -137,6 +137,80 @@ func TestExprs(t *testing.T) {
}
}
+func TestNanosecondTimestampLiterals(t *testing.T) {
Review Comment:
Worth a follow-up: boundary cases for `MinInt64`/`MaxInt64`, a cross-precision `TimestampNsLiteral.To(...)` case that pins ns-to-us truncation direction, and one execution round-trip would complement the current rendered-string coverage.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org