mrhhsg commented on code in PR #68488:
URL: https://github.com/apache/doris/pull/68488#discussion_r4096007110
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########
@@ -277,7 +277,7 @@ public static Expression divideDouble(DoubleLiteral first,
DoubleLiteral second)
*/
@ExecFunction(name = "divide")
public static Expression divideDecimal(DecimalLiteral first,
DecimalLiteral second) {
- if (first.getValue().compareTo(BigDecimal.ZERO) == 0) {
+ if (second.getValue().compareTo(BigDecimal.ZERO) == 0) {
Review Comment:
Fixed in 67b27f27d72. Both FE fold helpers now compute the quotient the way
BE does and return a literal of the type `Divide` analyzes:
- `divideDecimal` (DECIMALV2) mirrors `DecimalV2Value::operator/` /
`do_div`: it divides `|a| * 10^18` by `|b| * 10^9`, rounds up once the
remainder reaches `divisor >> 1`, reapplies the sign, and returns
`DECIMALV2(27, 9)` (`DecimalV2Type.SYSTEM_DEFAULT`, the type
`BinaryArithmetic.getDataTypeForDecimalV2` gives the expression). A zero
divisor returns `NULL` of that type.
- `divideDecimalV3` divides at the analyzed result scale `t1.scale -
t2.scale` with `RoundingMode.DOWN`, which matches the truncating native
division in `DivideDecimalImpl`.
`1 / 3` now folds to `0.333333333` and `1 / 1024` to `0.000976563`. For
DECIMALV3, `2.0 / 3` folds to `0.66666`. These are the values BE returns with
`debug_skip_fold_constant = true`, so these levels are accepted on the plain,
window, INSERT, state and combine paths. A quotient that overflows the type
still stays unfolded, the same as before, and BE decides it.
Coverage:
- `FoldConstantTest` checks value and type for both helpers:
- DECIMALV2: `1/3`, `1/1024`, `-2/3`, `1/0.000000003` (odd divisor, where
BE's `divisor >> 1` rule differs from HALF_UP), `1/0.000000001`, `0/2`, `1/0`.
- DECIMALV3: `2/3`, `-2/3`, `1/1024`, `1/0`.
- `PercentileReservoirParameterTest` accepts DECIMALV2 `1/3` and `1/1024`
and DECIMALV3 `2.0/3` and `1.0/1024` as levels. It rejects `4/3` with the
rounded value in the message.
- The regression suite adds `qt_decimal_quotient` and `qt_*_quotient_level`,
plus a `4.0 / 3` negative case. They run with and without
`debug_skip_fold_constant = true`, and both modes produce identical output.
`datatype_p0/decimalv2`, `fold_constant_numeric_arithmatic` and
`test_int128_unaligned_access` also pass locally.
--
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]