peterxcli opened a new pull request, #10409:
URL: https://github.com/apache/arrow-rs/pull/10409

   # Which issue does this PR close?
   
   - Closes https://github.com/apache/arrow-rs/issues/6335.
   - Closes https://github.com/apache/arrow-rs/issues/9030.
   
   # Rationale for this change
   
   #10336 added interval multiplication by `Int64`. Floating-point 
multiplication and division require preserving calendar components rather than 
flattening the entire interval into a duration.
   
   This PR adapts DuckDB's `INTERVAL * DOUBLE` behavior. Whole months and days 
remain calendar components, while fractional months cascade to days using 30 
days per month and fractional days cascade to nanoseconds using 24 hours per 
day.
   
   DuckDB explicitly attributes its implementation to PostgreSQL's 
`interval_mul`:
   
   - [DuckDB 
implementation](https://github.com/duckdb/duckdb/blob/21aca0424f1faf78b593b1e6fbfdd4846624c987/src/function/scalar/operator/multiply.cpp#L48-L123)
   - [PostgreSQL 
implementation](https://github.com/postgres/postgres/blob/78758d37306cd89ab060f00cb06f249018d5b8da/src/backend/utils/adt/timestamp.c#L3627-L3744)
   
   
   # What changes are included in this PR?
   
   Add checked arithmetic for:
   
   - `Interval(YearMonth | DayTime | MonthDayNano) * Float64`
   - `Float64 * Interval(YearMonth | DayTime | MonthDayNano)`
   - `Interval(YearMonth | DayTime | MonthDayNano) / Float64`
   
   All results use `Interval(MonthDayNano)`. `YearMonth` and `DayTime` inputs 
are widened first so fractional months and sub-millisecond results are not 
truncated.
   
   
   # Are these changes tested?
   
   - reuses the checked integer path for integral `Float64` factors, preserving 
exact nanoseconds
   - implements division by multiplying by the reciprocal, following 
[DuckDB](https://github.com/duckdb/duckdb/blob/21aca0424f1faf78b593b1e6fbfdd4846624c987/src/function/scalar/operator/arithmetic.cpp#L1102-L1110)
   - uses ties-to-even rounding at nanosecond precision
   - checks division by zero and component overflow
   - preserves array, scalar, and null behavior
   
   `Interval / Int64`, `Float64 / Interval`, wrapping multiplication, and 
additional numeric factor types are not added.
   
   # Are these changes tested?
   
   Yes. Tests cover all three interval units, both multiplication operand 
orders, division, array and scalar operands, null propagation, component 
cascading, integral-factor precision, negative values, ties-to-even rounding, 
non-finite values, division by zero, and overflow.
   
   ```shell
   cargo fmt --all -- --check
   cargo test -p arrow-arith
   cargo clippy -p arrow-arith --all-targets --all-features -- -D warnings
   
   # Are there any user-facing changes?
   
   Yes. The checked `mul` and `div` kernels now accept the combinations listed 
above. Floating-point interval arithmetic always returns 
`Interval(MonthDayNano)`.
   There are no public API signature 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]

Reply via email to