Skip to content

Add interval mul/div support for Float64#10409

Open
peterxcli wants to merge 1 commit into
apache:mainfrom
peterxcli:feat/interval-mul-div-with-f64
Open

Add interval mul/div support for Float64#10409
peterxcli wants to merge 1 commit into
apache:mainfrom
peterxcli:feat/interval-mul-div-with-f64

Conversation

@peterxcli

@peterxcli peterxcli commented Jul 22, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

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:

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

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.

@peterxcli

peterxcli commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

cc @milevin @alamb @tustvold @felipecrv @bkietz @findepi @Jefffrey would appreciate a look whenever you have time, thanks! Tagging you since you reviewed #6906 and have context here. Sorry for the ping!

@alamb

alamb commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Thanks - I'll try and find time for this but I need to focus on performance and bugfixes first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support interval mul / div double arithmetic Support multiple and divide on intervals

2 participants