brijrajk opened a new pull request, #12332:
URL: https://github.com/apache/gluten/pull/12332

   ## What changes are proposed in this pull request?
   
   Fixes #12260
   
   **Root cause**
   
   `CheckOverflowTransformer` was passing `original.child.dataType` — Spark's 
declared type on the raw `BinaryArithmetic` — to `createCheckOverflowExprNode` 
as the `childResultType` argument.
   
   `DecimalArithmeticExpressionTransformer` overrides `dataType` to return 
`resultType`, the type computed by `DecimalArithmeticUtil.getResultType()` 
after `rescaleLiteral` adjusts the operands. When the literal is integer-valued 
(e.g. `5.0`, `BigDecimal.isValidLong == true`), `rescaleLiteral` rescales it, 
changing the result type. The transformer's actual output type therefore 
differs from Spark's declared type on the original expression.
   
   `VeloxTransformerApi.createCheckOverflowExprNode` compares `childResultType` 
with the target `DecimalType` to decide whether to insert a cast:
   
   ```scala
   if (childResultType.equals(dataType)) {
     childNode          // no cast needed
   } else {
     ExpressionBuilder.makeCast(typeNode, childNode, nullOnOverflow)  // insert 
cast
   }
   ```
   
   With the wrong `childResultType`, the cast is generated with the wrong 
source type, making the Substrait plan invalid. Velox's SimpleFunction type 
validation rejects it, and `ColumnarPartialProjectRule` falls back the entire 
`Project` to JVM.
   
   **Fix**
   
   Pass `child.dataType` (the transformer's actual output type) instead of 
`original.child.dataType`. For transformers that do not override `dataType` 
(returning `original.dataType` by default) the behaviour is unchanged.
   
   **Files changed**
   
   - `UnaryExpressionTransformer.scala` — `original.child.dataType` → 
`child.dataType` in `CheckOverflowTransformer.doTransform`
   - `DecimalArithmeticValidateSuite.scala` (new) — regression test that 
reproduces the exact trigger conditions from the issue report and asserts 
`ProjectExecTransformer` is used
   
   ---
   
   ## How was this patch tested?
   
   New regression test `DecimalArithmeticValidateSuite` in `backends-velox`:
   
   - Creates two BIGINT temp views
   - Runs `SELECT a.val, (a.val - COALESCE(SUM(b.val), 0) / 5.0) / 
(COALESCE(SUM(b.val), 0) / 5.0) AS growth_rate FROM t1 CROSS JOIN t2 GROUP BY 
a.val` (the exact reproducer from #12260)
   - Asserts `ProjectExecTransformer` is present in the executed plan (would 
fail before this fix)
   
   Verified locally: 1/1 test passes.
   
   ---
   
   ## Was this patch authored or co-authored using generative AI tooling?
   
   `Generated-by: Claude Code (claude-sonnet-4-6)`


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to