hcrosse opened a new issue, #1455:
URL: https://github.com/apache/arrow-go/issues/1455

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   `not` on a sliced boolean array returns nulls on the wrong rows. It can turn 
a non-null input into null and a null input into a boolean value, without an 
error.
   
   I reproduced this on v18.8.0 and main at 
`22c9f26df0abbc2066f5d9ae45f31720d29a4300`, on Linux amd64. Slicing `[null, 
true, null, false]` from offset 1 gives `[true (null) false]`, but `not` 
returns `[(null) true (null)]` instead of `[false (null) true]`.
   
   **Reproduction**
   
   Save this as `main.go` in a module that requires 
`github.com/apache/arrow-go/v18 v18.8.0`, or in a new subdirectory of a 
checkout at `22c9f26d`, then run `go run .`:
   
   ```go
   package main
   
   import (
        "context"
        "fmt"
        "strings"
   
        "github.com/apache/arrow-go/v18/arrow"
        "github.com/apache/arrow-go/v18/arrow/array"
        "github.com/apache/arrow-go/v18/arrow/compute"
        "github.com/apache/arrow-go/v18/arrow/memory"
   )
   
   func main() {
        arr, _, _ := array.FromJSON(memory.DefaultAllocator, 
arrow.FixedWidthTypes.Boolean,
                strings.NewReader(`[null, true, null, false]`))
        sliced := array.NewSlice(arr, 1, 4)
   
        out, err := compute.CallFunction(context.Background(), "not", nil, 
compute.NewDatum(sliced))
        if err != nil {
                panic(err)
        }
        fmt.Println("input:   ", sliced)
        fmt.Println("not:     ", out.(*compute.ArrayDatum).MakeArray())
        fmt.Println("expected: [false (null) true]")
   }
   ```
   
   Output on both versions:
   
   ```text
   input:    [true (null) false]
   not:      [(null) true (null)]
   expected: [false (null) true]
   ```
   
   **Expected behavior**
   
   `not` should invert each non-null value and preserve the slice's null 
positions. The result here should be `[false (null) true]`.
   
   **Cause**
   
   `NotExecKernel` inverts the values at the input offset correctly. It then 
reuses the input validity buffer without carrying the input offset. The output 
starts at bit 0, so its validity comes from the start of the parent bitmap:
   
   
https://github.com/apache/arrow-go/blob/22c9f26df0abbc2066f5d9ae45f31720d29a4300/arrow/compute/internal/kernels/scalar_boolean.go#L336-L347
   
   The function is registered with `NullComputedNoPrealloc`, leaving validity 
handling to the kernel:
   
   
https://github.com/apache/arrow-go/blob/22c9f26df0abbc2066f5d9ae45f31720d29a4300/arrow/compute/scalar_bool.go#L138-L139
   
   `is_not_null` makes the same mistake with the validity buffer: 
https://github.com/apache/arrow-go/issues/1453.
   
   I have a patch with tests and can open a PR.
   
   ### Component(s)
   
   Other
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to