hcrosse opened a new pull request, #1467:
URL: https://github.com/apache/arrow-go/pull/1467

   ### Rationale for this change
   
   `starts_with` rejects `string_view` and `binary_view`, so callers have to 
cast them first. This change accepts view inputs directly. Arrow C++ also lacks 
support for these inputs (https://github.com/apache/arrow/issues/50478).
   
   ### What changes are included in this PR?
   
   The kernel checks the length in the 16-byte view header first. Inline values 
compare inside the header. For out-of-line values, it checks the 4-byte prefix 
before reading the data buffer, and reads only the pattern bytes past that 
prefix.
   
   `ArraySpan` has three buffer slots, so inputs with more than one data buffer 
are coalesced before execution with the existing helper that `cast` uses. They 
share its `math.MaxInt32` limit on out-of-line bytes. Dictionaries of views use 
the existing dictionary decoding, including coalescing multi-buffer dictionary 
values. The `scalar` package has no view scalars, so scalar inputs are 
unchanged.
   
   ### Are these changes tested?
   
   Yes. I extended `TestStartsWith` to run the shared cases on both view types. 
New rows check inline and out-of-line matches, prefix mismatches, mismatches 
past the prefix and patterns longer than the value. A sliced `string_view` 
checks offsets. The sliced multi-buffer `binary_view` case reads past the 
prefix in a later buffer, checking both a match and a mismatch. A dictionary of 
`string_view` checks decoding, null indices and null dictionary values.
   
   I also ran an uncommitted differential test over 20,000 generated cases, 
comparing the view result with cast-then-existing-kernel and `bytes.HasPrefix`. 
It found no differences across multi-buffer, sliced, dictionary and chunked 
inputs.
   
   On macOS arm64 with Go `1.27.3`, `go test ./arrow/compute/...` passed with 
and without `-tags assert,test`, along with `-race` on `arrow/compute`, 
`arrow/compute/internal/kernels` and `arrow/compute/exprs`. `gofmt`, `go vet` 
on compute and kernels, and the Release Audit Tool passed. `golangci-lint` 
`2.13.2`, run with Go `1.26.10`, reported no issues in `arrow`, `parquet` and 
`internal`.
   
   I benchmarked 65,536 synthetic `string_view` values against casting to 
`string` before calling `starts_with`. These results are from a Linux amd64 VM 
with 8 AMD EPYC vCPUs, with 12 runs per case:
   
   | Input | Cast then string | View kernel | Less time |
   | --- | ---: | ---: | ---: |
   | Inline values, 1 to 12 bytes | 3.197 ms | 0.590 ms | 81.6% |
   | 64-byte values, 128 data buffers | 8.214 ms | 5.412 ms | 34.1% |
   | Same 64-byte values, one data buffer | 3.143 ms | 0.895 ms | 71.5% |
   
   The multi-buffer gain is smaller because both paths first copy the 
out-of-line data into one buffer.
   
   ### Are there any user-facing changes?
   
   Yes. `starts_with` accepts `string_view` and `binary_view` inputs, including 
dictionaries of views. There is no API change.
   
   Closes https://github.com/apache/arrow-go/issues/1459.
   


-- 
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