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 4b3c870c fix(arrow/compute): honor the input offset in is_not_null
(#1456)
4b3c870c is described below
commit 4b3c870ca902c64f7be899e668997d81f08d98e9
Author: Harrison Crosse <[email protected]>
AuthorDate: Wed Nov 4 11:41:09 2026 -0500
fix(arrow/compute): honor the input offset in is_not_null (#1456)
### Rationale for this change
`is_not_null` ignores a sliced array's offset, so its mask comes from
the start of the parent array. For example, `is_not_null` on `[null, 1,
null, 2]` sliced from offset 1 returns `[false, true, false]` instead of
`[true, false, true]`. A filter using that mask can select null rows and
drop non-null rows without an error.
### What changes are included in this PR?
The output always starts at offset 0, so sharing the input validity
buffer is correct only when the input offset is also 0. `isNotNullExec`
still shares it in that case. Otherwise, it copies the bits from the
input offset into a new bitmap. Inputs without a validity buffer still
produce all true.
### Are these changes tested?
I added `TestSlicedInput`, which checks `is_null` and `is_not_null` at
offsets 0, 1, 8 and 9, with and without a validity buffer. On main,
`is_not_null` fails at offsets 1, 8 and 9 with a validity buffer, and
the other cases pass.
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.
### Are there any user-facing changes?
Yes. `is_not_null` returns the correct mask on sliced arrays and slices
of record batches, so filters select the right rows. There is no API
change.
Closes https://github.com/apache/arrow-go/issues/1453.
---
.../compute/internal/kernels/scalar_comparisons.go | 9 +++-
arrow/compute/scalar_compare_test.go | 48 ++++++++++++++++++++++
2 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/arrow/compute/internal/kernels/scalar_comparisons.go
b/arrow/compute/internal/kernels/scalar_comparisons.go
index 4dfe00cc..4c2b4c9f 100644
--- a/arrow/compute/internal/kernels/scalar_comparisons.go
+++ b/arrow/compute/internal/kernels/scalar_comparisons.go
@@ -734,11 +734,16 @@ func isNotNullExec(ctx *exec.KernelCtx, batch
*exec.ExecSpan, out *exec.ExecResu
input := batch.Values[0].Array
validityBuf := input.GetBuffer(0)
- if validityBuf == nil {
+ switch {
+ case validityBuf == nil:
out.Buffers[1].WrapBuffer(ctx.AllocateBitmap(input.Len))
memory.Set(out.Buffers[1].Buf, 0xFF)
- } else {
+ case input.Offset == 0:
out.Buffers[1].SetBuffer(validityBuf)
+ default:
+ out.Buffers[1].WrapBuffer(ctx.AllocateBitmap(input.Len))
+ bitutil.CopyBitmap(validityBuf.Bytes(), int(input.Offset),
int(input.Len),
+ out.Buffers[1].Buf, 0)
}
return nil
diff --git a/arrow/compute/scalar_compare_test.go
b/arrow/compute/scalar_compare_test.go
index 13127805..edb49d0b 100644
--- a/arrow/compute/scalar_compare_test.go
+++ b/arrow/compute/scalar_compare_test.go
@@ -1575,6 +1575,54 @@ func (sv *ScalarValiditySuite) TestNotNull() {
}
}
+func (sv *ScalarValiditySuite) checkValiditySliced(input arrow.Array, isNull,
isNotNull string) {
+ for _, tt := range []struct{ fn, expected string }{
+ {"is_null", isNull}, {"is_not_null", isNotNull},
+ } {
+ exp := sv.getArr(arrow.FixedWidthTypes.Boolean, tt.expected)
+ res, err := compute.CallFunction(sv.ctx, tt.fn, nil,
compute.NewDatumWithoutOwning(input))
+ sv.Require().NoError(err)
+ result := res.(*compute.ArrayDatum).MakeArray()
+ res.Release()
+ sv.Truef(array.Equal(exp, result), "%s(%s): expected %s, got
%s", tt.fn, input, exp, result)
+ exp.Release()
+ result.Release()
+ }
+}
+
+func (sv *ScalarValiditySuite) TestSlicedInput() {
+ withNulls := sv.getArr(arrow.PrimitiveTypes.Int32, `[null, 1, null, 2,
3, 4, null, 5, 6, 7, null, null, 8]`)
+ defer withNulls.Release()
+ data := array.NewData(arrow.PrimitiveTypes.Int32, withNulls.Len(),
+ []*memory.Buffer{nil, withNulls.Data().Buffers()[1]}, nil, 0, 0)
+ noValidity := array.MakeFromData(data)
+ data.Release()
+ defer noValidity.Release()
+
+ tests := []struct {
+ offset int64
+ isNull string
+ isNotNull string
+ }{
+ {0, `[true, false, true, false]`, `[false, true, false, true]`},
+ {1, `[false, true, false, false]`, `[true, false, true, true]`},
+ {8, `[false, false, true, true]`, `[true, true, false, false]`},
+ {9, `[false, true, true, false]`, `[true, false, false, true]`},
+ }
+ for _, tt := range tests {
+ sv.Run(fmt.Sprintf("validity/offset=%d", tt.offset), func() {
+ sliced := array.NewSlice(withNulls, tt.offset,
tt.offset+4)
+ defer sliced.Release()
+ sv.checkValiditySliced(sliced, tt.isNull, tt.isNotNull)
+ })
+ sv.Run(fmt.Sprintf("no validity/offset=%d", tt.offset), func() {
+ sliced := array.NewSlice(noValidity, tt.offset,
tt.offset+4)
+ defer sliced.Release()
+ sv.checkValiditySliced(sliced, `[false, false, false,
false]`, `[true, true, true, true]`)
+ })
+ }
+}
+
func (sv *ScalarValiditySuite) TestIsNaN() {
tests := []struct {
in string