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 5327f57c fix(arrow/scalar): use duration type for units (#1041)
5327f57c is described below
commit 5327f57c92ce2130509133f06e77c668ca576ae1
Author: Minh Vu <[email protected]>
AuthorDate: Tue Jul 28 17:08:11 2026 +0200
fix(arrow/scalar): use duration type for units (#1041)
## What changed
Read a duration scalar's unit from `arrow.DurationType` instead of
asserting it is a timestamp type.
## Why
Valid duration scalars carry `*arrow.DurationType`. The previous
assertion to `*arrow.TimestampType` panicked whenever `Unit` was called,
including through string formatting and duration unit conversion.
The regression test covers direct unit access, string formatting, and
seconds-to-milliseconds conversion.
## Validation
`go test ./arrow/scalar`
---
arrow/scalar/scalar_test.go | 10 ++++++++++
arrow/scalar/temporal.go | 2 +-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/arrow/scalar/scalar_test.go b/arrow/scalar/scalar_test.go
index 8aa7aebe..056da477 100644
--- a/arrow/scalar/scalar_test.go
+++ b/arrow/scalar/scalar_test.go
@@ -524,6 +524,16 @@ func TestDurationScalarBasics(t *testing.T) {
assert.False(t, scalar.Equals(tsNull, tsVal2))
}
+func TestDurationScalarUnitConversions(t *testing.T) {
+ s := scalar.NewDurationScalar(1, arrow.FixedWidthTypes.Duration_s)
+ assert.Equal(t, arrow.Second, s.Unit())
+ assert.Equal(t, "1s", s.String())
+
+ converted, err := s.CastTo(arrow.FixedWidthTypes.Duration_ms)
+ require.NoError(t, err)
+ assert.Equal(t, arrow.Duration(1000),
converted.(*scalar.Duration).Value)
+}
+
func TestMonthIntervalScalarBasics(t *testing.T) {
typ1 := arrow.FixedWidthTypes.MonthInterval
typ2 := arrow.FixedWidthTypes.MonthInterval
diff --git a/arrow/scalar/temporal.go b/arrow/scalar/temporal.go
index 26a6aeae..4f06106e 100644
--- a/arrow/scalar/temporal.go
+++ b/arrow/scalar/temporal.go
@@ -73,7 +73,7 @@ func (s *Duration) equals(rhs Scalar) bool {
}
func (s *Duration) Unit() arrow.TimeUnit {
- return s.DataType().(*arrow.TimestampType).Unit
+ return s.DataType().(*arrow.DurationType).Unit
}
func (s *Duration) Data() []byte {
return (*[arrow.DurationSizeBytes]byte)(unsafe.Pointer(&s.Value))[:]