You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ze...@apache.org on 2025/07/24 14:42:24 UTC
(arrow-go) branch main updated: fix(arrow/compute/exprs): fix literalToDatum for precision types (#447)
This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git
The following commit(s) were added to refs/heads/main by this push:
new daaf932 fix(arrow/compute/exprs): fix literalToDatum for precision types (#447)
daaf932 is described below
commit daaf9323da0307325160eece2f6c41019c859495
Author: Matt Topol <zo...@gmail.com>
AuthorDate: Thu Jul 24 10:42:19 2025 -0400
fix(arrow/compute/exprs): fix literalToDatum for precision types (#447)
### Rationale for this change
While #404 fixed support for substrait precision types on inputs, it did
not address support for literals that use the Precision types.
Fixes #446
### What changes are included in this PR?
Fix `literalToDatum` so that it properly supports the precision types
for literals.
### Are these changes tested?
Yes, a unit test is added.
### Are there any user-facing changes?
Just the increased support
---
arrow/compute/exprs/exec.go | 30 ++++++++++++++++++++++++++++++
arrow/compute/exprs/exec_test.go | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+)
diff --git a/arrow/compute/exprs/exec.go b/arrow/compute/exprs/exec.go
index 57fb7c8..b58340c 100644
--- a/arrow/compute/exprs/exec.go
+++ b/arrow/compute/exprs/exec.go
@@ -379,6 +379,36 @@ func literalToDatum(mem memory.Allocator, lit expr.Literal, ext ExtensionIDSet)
case *types.VarCharType:
return compute.NewDatum(scalar.NewExtensionScalar(
scalar.NewStringScalar(v.Value.(string)), varChar(int32(t.Length)))), nil
+ case *types.PrecisionTimeType:
+ dt, _, err := FromSubstraitType(t, ext)
+ if err != nil {
+ return nil, err
+ }
+
+ switch dt.ID() {
+ case arrow.TIME32:
+ return &compute.ScalarDatum{Value: scalar.NewTime32Scalar(
+ arrow.Time32(v.Value.(int64)), dt)}, nil
+ case arrow.TIME64:
+ return &compute.ScalarDatum{Value: scalar.NewTime64Scalar(
+ arrow.Time64(v.Value.(int64)), dt)}, nil
+ }
+ case *types.PrecisionTimestampType:
+ dt, _, err := FromSubstraitType(t, ext)
+ if err != nil {
+ return nil, err
+ }
+
+ return &compute.ScalarDatum{Value: scalar.NewTimestampScalar(
+ arrow.Timestamp(v.Value.(int64)), dt)}, nil
+ case *types.PrecisionTimestampTzType:
+ dt, _, err := FromSubstraitType(t, ext)
+ if err != nil {
+ return nil, err
+ }
+
+ return &compute.ScalarDatum{Value: scalar.NewTimestampScalar(
+ arrow.Timestamp(v.Value.(int64)), dt)}, nil
}
}
diff --git a/arrow/compute/exprs/exec_test.go b/arrow/compute/exprs/exec_test.go
index 2d95810..b1cbec3 100644
--- a/arrow/compute/exprs/exec_test.go
+++ b/arrow/compute/exprs/exec_test.go
@@ -518,6 +518,43 @@ func Test_Types(t *testing.T) {
return expr.NewPrimitiveLiteral(types.Time(v), true)
},
},
+ {
+ name: "expect arrow.TIME64 (ns) ok",
+ schema: func() *arrow.Schema {
+ field := arrow.Field{
+ Name: "col",
+ Type: &arrow.Time64Type{Unit: arrow.Nanosecond},
+ Nullable: true,
+ }
+
+ return arrow.NewSchema([]arrow.Field{field}, nil)
+ },
+ record: func(rq *require.Assertions, schema *arrow.Schema) arrow.Record {
+ b := array.NewTime64Builder(memory.DefaultAllocator, &arrow.Time64Type{Unit: arrow.Nanosecond})
+ defer b.Release()
+
+ t1, err := arrow.Time64FromString("10:00:00.000000", arrow.Nanosecond)
+ rq.NoError(err, "Failed to create Time64 value")
+
+ b.AppendValues([]arrow.Time64{t1}, []bool{true})
+
+ return array.NewRecord(schema, []arrow.Array{b.NewArray()}, 1)
+ },
+ val: func(rq *require.Assertions) expr.Literal {
+ v, err := arrow.Time64FromString("11:00:00.000000", arrow.Nanosecond)
+ rq.NoError(err, "Failed to create Time64 value")
+
+ pt := &types.PrecisionTime{
+ Precision: int32(arrow.Nanosecond) * 3,
+ Value: int64(v),
+ }
+
+ lit, err := expr.NewLiteral(pt, true)
+ rq.NoError(err, "Failed to create literal")
+
+ return lit
+ },
+ },
{
name: "expect arrow.TIMESTAMP (ns) ok",
schema: func() *arrow.Schema {