feat: Add ANSI mode support for Spark arithmetic operations#16361
feat: Add ANSI mode support for Spark arithmetic operations#16361malinjawi wants to merge 7 commits intofacebookincubator:mainfrom
Conversation
Add ANSI mode support for arithmetic operations (add, subtract, multiply, divide, unary minus) and interval arithmetic in Spark dialect. In ANSI mode: - Overflow throws errors instead of wrapping around - Division by zero throws errors instead of returning NULL - MIN_VALUE / -1 overflow throws errors In non-ANSI mode (default): - Overflow wraps around (two's complement) - Division by zero returns NULL - MIN_VALUE / -1 returns MIN_VALUE Key changes: - Add IntegerDivideFunction with ANSI overflow and division-by-zero checks - Update DivideFunction to support both float and double - Add ANSI overflow checks to Add, Subtract, Multiply functions - Add ANSI support for interval arithmetic (IntervalDayTime, IntervalYearMonth) - Add comprehensive tests for all arithmetic operations - Update documentation with ANSI behavior examples Addresses: apache/incubator-gluten#10134
✅ Deploy Preview for meta-velox canceled.
|
|
Just a heads-up, ANSI-mode support for non-decimal integral arithmetic already exists via the This PR introduces a different approach by reading However, the I have a series of PRs extending the Happy to follow whatever direction the maintainers prefer. cc @rui-mo |
You're absolutely right, and thank you for catching this! I didn't realize that I reviewed your PRs (#16302, #16307, #16323) and see that you're extending this pattern to decimal arithmetic, which is the correct approach. I also see that @rui-mo is approving this direction. I'll refactor my PR to:
One question: I notice Thanks again for the feedback. cc @rui-mo |
Hi @n0r0shi Sorry, I just saw your message. Could you help me understand the motivation for making the functions config-agnostic, given that Spark already controls the behavior via configuration? I don’t think ANSI ON/OFF functions should co-exist, and using a configuration in Velox to control ANSI behavior shouldn’t confuse users, since it follows Spark and keeps the behavior consistent with Spark. How do you think? cc: @zhli1142015 @jinchengchenghh Please also note that the Please feel free to open a discussion in Gluten to gather more opinions from other maintainers as well. |
|
I would +1 moving forward with the approach proposed in this PR. |
7f44d6c to
78b111e
Compare
Thanks all for the context. I’ve updated the branch. Before I proceed further, I’d like to align on direction for ANSI arithmetic in Velox: config‑based behavior inside functions (as in this PR) vs. checked_* selection by caller. I’m happy to follow whichever approach maintainers prefer. For context, I also opened #16402 for checked interval arithmetic (checked_* pattern) in case that direction is preferred for intervals. Would it help to loop in anyone else from Gluten or Spark folks who’ve weighed in on ANSI behavior? I can tag them or start a short discussion thread if useful. cc: @n0r0shi @rui-mo @zhli1142015 @jinchengchenghh @PHILO-HE |
|
@rui-mo Thank you for the feedback and for sharing the context. When I started the work, what I observed was that So it was a natural extension to me to support the same pattern on the Velox side to make it work for
Can we keep This has minimal impact on the code already merged (for both Gluten and Velox), I can check other PRs of mine and change to config based for the ones who don't have |
|
@n0r0shi Yes, it makes sense to treat |
|
@rui-mo @malinjawi Thank you for the alignment. Based on the discussion, here's how I plan to proceed: I'll keep PRs for
I'll yield For |
|
I noticed the unaryminus ANSI support in this PR hasn't been updated since our discussion. I went ahead and submitted it as a separate config-based PR #16672 — hope that's okay. Happy to coordinate if you had plans for it. |
Add ANSI mode support for arithmetic operations (add, subtract, multiply, divide, unary minus) and interval arithmetic in Spark dialect.
In ANSI mode:
In non-ANSI mode (default):
Key changes:
Addresses: apache/incubator-gluten#10134