Commit 0cc376a
authored
[GLUTEN-11917][VL] Respect allowPrecisionLoss from expression context in Spark 4.1 (#12110)
* [GLUTEN-11917][VL] Respect allowPrecisionLoss from expression context in Spark 4.1
In Spark 4.1, SPARK-53968 introduced NumericEvalContext which captures
allowPrecisionLoss at analysis time and embeds it in arithmetic expressions
(Add, Subtract, Multiply, Divide) via an evalContext field. Previously,
Gluten read SQLConf.get.decimalOperationsAllowPrecisionLoss at plan-conversion
time, which can diverge from the expression's captured value — for example,
when querying a persistent view whose expression was analyzed under a different
session config.
This commit adds a shim method decimalAllowPrecisionLoss(expr: BinaryArithmetic)
to SparkShims. The Spark41Shims override reads evalContext.allowDecimalPrecisionLoss
directly from the expression. All other Spark versions fall back to SQLConf.get,
preserving existing behavior. DecimalArithmeticUtil.getResultType and
VeloxSparkPlanExecApi.getDecimalArithmeticExprName are updated to use the shim,
ensuring the correct result type and Velox function name are selected.
Fixes: #11917
* [GLUTEN-11917][VL] Add test and clarifying comments for allowPrecisionLoss shim
- Add regression test covering the view-analyzed-under-different-session-config
scenario that motivated the fix: arithmetic is analyzed with allowPrecisionLoss=false,
cached in a temp view, then queried with allowPrecisionLoss=true. Gluten must read
the captured evalContext, not SQLConf.get.
- Add comment on SparkShims default explaining why SQLConf.get is correct for
pre-4.1 Spark versions (no evalContext field exists before SPARK-53968).
- Add comment on Spark41Shims wildcard arm explaining that Remainder/Pmod lack
evalContext and are gated out of Velox execution by GlutenNotSupportException
in DecimalArithmeticUtil.getResultType, making the SQLConf fallback safe.
- Add comment on SparkPlanExecApi default explaining why non-Velox backends
(e.g. ClickHouse) correctly ignore allowPrecisionLoss — they do not use the
_deny_precision_loss naming convention.
* [GLUTEN-11917][VL] Update GlutenSimpleSQLViewSuite comment for Spark 4.1
The original comment noted 2 failures. One was the allowPrecisionLoss
evalContext issue fixed in this PR (GLUTEN-11917). The suite still has
1 remaining failure unrelated to GLUTEN-11917, so it stays disabled.1 parent 55eb0d3 commit 0cc376a
8 files changed
Lines changed: 56 additions & 9 deletions
File tree
- backends-velox/src
- main/scala/org/apache/gluten/backendsapi/velox
- test/scala/org/apache/gluten/functions
- gluten-substrait/src/main/scala/org/apache/gluten
- backendsapi
- expression
- utils
- gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox
- shims
- common/src/main/scala/org/apache/gluten/sql/shims
- spark41/src/main/scala/org/apache/gluten/sql/shims/spark41
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
| 165 | + | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
416 | 442 | | |
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
268 | 271 | | |
269 | 272 | | |
270 | 273 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
647 | 647 | | |
648 | 648 | | |
649 | 649 | | |
650 | | - | |
| 650 | + | |
| 651 | + | |
651 | 652 | | |
652 | 653 | | |
653 | 654 | | |
| |||
664 | 665 | | |
665 | 666 | | |
666 | 667 | | |
667 | | - | |
| 668 | + | |
| 669 | + | |
668 | 670 | | |
669 | 671 | | |
670 | 672 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
36 | | - | |
| 35 | + | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
702 | 702 | | |
703 | 703 | | |
704 | 704 | | |
705 | | - | |
| 705 | + | |
706 | 706 | | |
707 | 707 | | |
708 | 708 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
253 | 259 | | |
254 | 260 | | |
255 | 261 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
610 | 610 | | |
611 | 611 | | |
612 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
613 | 624 | | |
614 | 625 | | |
615 | 626 | | |
| |||
0 commit comments