jayzhan211 opened a new pull request, #26774:
URL: https://github.com/apache/datafusion/pull/26774

   ## Which issue does this PR close?
   
   - Unblocks #26211, whose merge-queue run failed in 
`fuzz_cases::aggregate_fuzz::test_sum`.
   
   ## Rationale for this change
   
   The aggregate fuzz tests build decimal columns with a random precision, but 
fill them with random values from the whole `i32`/`i64`/`i128`/`i256` range. 
Most values do not fit the column's precision, so the data is not valid Arrow. 
For example, a `Decimal32(1, 0)` column can hold `693850995`.
   
   `sum` never checks precision (it adds with wrapping), so this went unnoticed 
on `main`. #26211 adds a decimal `CAST`, and the cast does check. With this 
data, the baseline query fails before any comparison is made:
   
   | query (PR #26211, `decimal128` is `Decimal128(20, 3)`) | actual | expected 
|
   | --- | --- | --- |
   | `SELECT u8_low, utf8_low, sum(i64), sum(decimal128), sum(DISTINCT u64), 
sum(u8), sum(i16) FROM fuzz_table GROUP BY u8_low, utf8_low` | `Failed to cast 
field 'sum(alias3)' from Decimal128(38, 3) to Decimal128(30, 3)`: 
`113138524487158375289685055217956519.303 is too large to store in a Decimal128 
of precision 30` | the query runs and the fuzzer compares its results |
   
   With valid `Decimal128(20, 3)` input, a sum would need more than 10^10 rows 
to exceed precision 30. Here it overflows because the generated values are 
already close to 10^38.
   
   ## What changes are included in this PR?
   
   `DecimalArrayGenerator` reduces each random value modulo `10^precision`, so 
every value fits the declared precision. Values still cover the full digit 
range of the column.
   
   ## What is the testing strategy for this PR?
   
   With #26211 applied, `test_sum` failed in 4 of 10 local runs without this 
change (on `Decimal64`, `Decimal128` and `Decimal256` columns) and passed 20 of 
20 runs with it. A local check, not included in this PR, generated arrays for 
every decimal type and precision with 20 seeds each. Every array passed 
`validate_decimal_precision`. Without this change, the same check fails on the 
first array.
   
   ## Are there any user-facing changes?
   
   No. Only test data generation changes.
   


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