mansur-akhmadi opened a new pull request, #1713:
URL: https://github.com/apache/arrow-go/pull/1713

   ### Rationale for this change
   
   Fixes #1712. In a safe float-to-integer cast, `checkFloatTrunc` reads the 
validity bitmap from bit 0 instead of from the array offset. For a sliced array 
with nulls, it checks the wrong slots. A fractional value next to a null is 
truncated without an error (`[1.5, 2, null]` sliced from `[null, 1.5, 2, null]` 
→ int32 `[1, 2, null]`), and a value stored under a null can fail the cast.
   
   ### What changes are included in this PR?
   
   `offsetPos` starts at `in.Offset`, as in the integer bounds check in 
`helpers.go`. One line.
   
   ### Are these changes tested?
   
   Yes. `TestCasts/TestFloatingToIntSliced` checks two slices, once at offset 0 
and once after 64 padding values (a null, then 63 zeros) so the slice starts in 
a later bitmap word:
   - `[1.5, 2, null]` sliced from `[null, 1.5, 2, null]` must fail with 
`ErrInvalid`. On main it casts to `[1, 2, null]`.
   - `[2, null]` sliced from `[null, 2, null]`, with 9.5 stored under the last 
null, must cast to `[2, null]`. On main it fails on the 9.5.
   
   Both halves fail on main at both offsets and pass with the fix.
   
   - `go test -short -tags assert,test ./arrow/compute/... ./arrow/scalar/...` 
and the same with `assert,test,noasm`: ok
   - `golangci-lint run ./compute/...` from `arrow/`: 0 issues
   
   Not changed here, found while testing:
   - Sliced **bool** casts have the same kind of offset bug in a different 
place: `ScalarUnaryBoolArg` (`helpers.go`) and the bool → string kernel read 
bits from 0. `[true, false, false, true]` sliced `[1:3]` (`[false, false]`) 
casts to int32 `[1, 0]` and to utf8 `["true", "false"]`. I'll file that 
separately.
   - When execution is chunked, the span's null count is `UnknownNullCount` 
(-1), so the error-reporting loop's `in.Nulls > 0` takes the no-nulls branch. 
The cast still fails, but the message can name a value stored under a null. 
`intsCanFit` has the same condition.
   
   ### Are there any user-facing changes?
   
   Safe casts of sliced float arrays now catch truncation and ignore values 
under nulls, the same as unsliced arrays.
   


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