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 6ef0335b fix(arrow/compute): register is_null, is_not_null and is_nan
as unary functions (#1457)
6ef0335b is described below
commit 6ef0335bf0ea56395965db89b7e59ef56b4f6b59
Author: Harrison Crosse <[email protected]>
AuthorDate: Wed Nov 4 13:56:16 2026 -0500
fix(arrow/compute): register is_null, is_not_null and is_nan as unary
functions (#1457)
### Rationale for this change
`is_null`, `is_not_null` and `is_nan` can panic because their dispatch
assumes two arguments. For example, `is_null` on any decimal array
panics. In iceberg-go, a decimal `IsNull`, `NotNull` or `IN` filter
crashes the process.
### What changes are included in this PR?
The three functions are now plain scalar functions with exact dispatch,
as in Arrow C++. They were registered as `compareFunction`, whose
`DispatchBest` uses helpers that read a second argument. A short comment
on `compareFunction` records that assumption.
`is_not_null` already returns wrong results on sliced input, for example
on sliced int32 arrays (https://github.com/apache/arrow-go/issues/1453).
Decimals panicked before reaching that bug. With this change alone,
`is_not_null` on a sliced decimal array returns a wrong result instead
of panicking. https://github.com/apache/arrow-go/pull/1456 fixes the
offset bug and should land before or with this PR.
### Are these changes tested?
I added `TestDecimal` for `is_null`, `is_not_null` and `is_nan` on
`decimal128` and `decimal256`, and `TestIsNaNDictionaryNotImplemented`
for a float dictionary returning `arrow.ErrNotImplemented`. All seven
subtests panic on main and pass with this change.
I also compared main with this change on 171 cases, covering 57 input
types for each of the three functions, on macOS. Calls that previously
panicked now return results or errors. Two timestamp null checks also
return results instead of rejecting a time zone that cannot be loaded.
Every case that returned a result before returns the same result now.
With iceberg-go main `8ef0a092`, decimal `IsNull`, `NotNull`, `IN` and
`NOT IN` scan filters return the expected rows where they crashed
before.
On Linux amd64, `go test -count=1 ./arrow/compute/...`, `go vet`,
`gofmt` and `golangci-lint` passed, along with the `prek` hooks on the
changed files, including the Release Audit Tool. I did not test arm64.
### Are there any user-facing changes?
Yes. `is_null` and `is_not_null` return results on decimal input.
`is_nan` on decimal input returns all false through its existing kernel.
As before, `is_nan` returns false for null inputs, where Arrow C++
returns null. Inputs without an `is_nan` kernel, including dictionaries,
strings and unsupported temporal types, return `arrow.ErrNotImplemented`
instead of panicking. I checked the dictionary, string and timestamp
cases against Arrow C++.
`is_null` and `is_not_null` no longer reject a timestamp whose time zone
cannot be loaded, because neither function uses the zone. This also
matches Arrow C++. There is no API change.
Closes https://github.com/apache/arrow-go/issues/1454.
---
arrow/compute/scalar_compare.go | 8 +++++---
arrow/compute/scalar_compare_test.go | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/arrow/compute/scalar_compare.go b/arrow/compute/scalar_compare.go
index a118a87f..2636868f 100644
--- a/arrow/compute/scalar_compare.go
+++ b/arrow/compute/scalar_compare.go
@@ -27,6 +27,8 @@ import (
"github.com/apache/arrow-go/v18/arrow/compute/internal/kernels"
)
+// compareFunction dispatches binary comparisons. Its DispatchBest assumes
+// exactly two arguments, so unary functions must not use it.
type compareFunction struct {
ScalarFunction
}
@@ -163,12 +165,12 @@ func RegisterScalarComparisons(reg FunctionRegistry) {
reg.AddFunction(lteFn, false)
isOrNotNullKns := kernels.IsNullNotNullKernels()
- isNullFn := &compareFunction{*NewScalarFunction("is_null", Unary(),
EmptyFuncDoc)}
+ isNullFn := NewScalarFunction("is_null", Unary(), EmptyFuncDoc)
if err := isNullFn.AddKernel(isOrNotNullKns[0]); err != nil {
panic(err)
}
- isNotNullFn := &compareFunction{*NewScalarFunction("is_not_null",
Unary(), EmptyFuncDoc)}
+ isNotNullFn := NewScalarFunction("is_not_null", Unary(), EmptyFuncDoc)
if err := isNotNullFn.AddKernel(isOrNotNullKns[1]); err != nil {
panic(err)
}
@@ -176,7 +178,7 @@ func RegisterScalarComparisons(reg FunctionRegistry) {
reg.AddFunction(isNullFn, false)
reg.AddFunction(isNotNullFn, false)
- isNaNFn := &compareFunction{*NewScalarFunction("is_nan", Unary(),
EmptyFuncDoc)}
+ isNaNFn := NewScalarFunction("is_nan", Unary(), EmptyFuncDoc)
for _, k := range kernels.IsNaNKernels() {
if err := isNaNFn.AddKernel(k); err != nil {
panic(err)
diff --git a/arrow/compute/scalar_compare_test.go
b/arrow/compute/scalar_compare_test.go
index edb49d0b..0e30192f 100644
--- a/arrow/compute/scalar_compare_test.go
+++ b/arrow/compute/scalar_compare_test.go
@@ -1642,6 +1642,40 @@ func (sv *ScalarValiditySuite) TestIsNaN() {
}
}
+func (sv *ScalarValiditySuite) TestDecimal() {
+ tests := []struct {
+ funcName string
+ typ arrow.DataType
+ expected string
+ }{
+ {"is_null", &arrow.Decimal128Type{Precision: 10, Scale: 2},
`[false, true, false]`},
+ {"is_null", &arrow.Decimal256Type{Precision: 40, Scale: 2},
`[false, true, false]`},
+ {"is_not_null", &arrow.Decimal128Type{Precision: 10, Scale: 2},
`[true, false, true]`},
+ {"is_not_null", &arrow.Decimal256Type{Precision: 40, Scale: 2},
`[true, false, true]`},
+ {"is_nan", &arrow.Decimal128Type{Precision: 10, Scale: 2},
`[false, false, false]`},
+ {"is_nan", &arrow.Decimal256Type{Precision: 40, Scale: 2},
`[false, false, false]`},
+ }
+
+ for _, tt := range tests {
+ sv.Run(tt.funcName+"/"+tt.typ.String(), func() {
+ sv.checkScalarUnary(tt.funcName, sv.getArr(tt.typ,
`["1.50", null, "2.25"]`),
+ sv.getArr(arrow.FixedWidthTypes.Boolean,
tt.expected))
+ })
+ }
+}
+
+func (sv *ScalarValiditySuite) TestIsNaNDictionaryNotImplemented() {
+ dict := sv.getArr(&arrow.DictionaryType{IndexType:
arrow.PrimitiveTypes.Int8, ValueType: arrow.PrimitiveTypes.Float64},
+ `[1.5, "NaN", null]`)
+ defer dict.Release()
+
+ res, err := compute.CallFunction(sv.ctx, "is_nan", nil,
compute.NewDatumWithoutOwning(dict))
+ if res != nil {
+ res.Release()
+ }
+ sv.ErrorIs(err, arrow.ErrNotImplemented)
+}
+
func TestScalarValidity(t *testing.T) {
suite.Run(t, &ScalarValiditySuite{})
}