dmitry-chirkov-dremio opened a new pull request, #49442:
URL: https://github.com/apache/arrow/pull/49442
### Rationale for this change
Add `rand_integer` function to Gandiva to generate random integers,
complementing the existing `rand`/`random` functions that generate random
doubles. This provides native integer random number generation and offers a
more efficient alternative to `CAST(rand() * range AS INT)`.
### What changes are included in this PR?
- Add `RandomIntegerGeneratorHolder` class following the existing
`RandomGeneratorHolder` pattern
- Implement three function signatures:
- `rand_integer()` → int32 in range [INT32_MIN, INT32_MAX]
- `rand_integer(int32 range)` → int32 in range [0, range-1]
- `rand_integer(int32 min, int32 max)` → int32 in range [min, max]
inclusive
- Add parameter validation (range > 0, min <= max) at expression compilation
time
- Add 8 unit tests covering all signatures and edge cases
- Use `std::uniform_int_distribution<int32_t>` with Mersenne Twister engine
### Are these changes tested?
Yes, added 8 unit tests in `random_generator_holder_test.cc`:
- `NoParams` - verifies full int32 range
- `WithRange` - verifies [0, range-1] bounds
- `WithMinMax` - verifies [min, max] inclusive bounds
- `WithNegativeMinMax` - verifies negative range handling
- `InvalidRangeZero` - verifies range=0 is rejected
- `InvalidRangeNegative` - verifies negative range is rejected
- `InvalidMinGreaterThanMax` - verifies min > max is rejected
- `NullRangeDefaultsToOne` - verifies null parameter handling
### Are there any user-facing changes?
Yes, this adds a new `rand_integer` function to Gandiva with three
signatures as described above.
--
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]