Repository navigation
feat: support interval * number, number * interval and interval / number - #26258
Open
RishavTiwari25 wants to merge 1 commit into
Open
RishavTiwari25 wants to merge 1 commit into
RishavTiwari25 wants to merge 1 commit into
Conversation
…/ number` Multiplying an interval by a number failed to plan or execute, and dividing by an integer failed, because `temporal_math_coercion` coerced the numeric operand to `Interval(MonthDayNano)`, which arrow rejects as `Interval * Interval`, and because result type probing and evaluation used `mul_wrapping`, which arrow's interval kernels do not implement. Add `interval_number_coercion`: the interval becomes `Interval(MonthDayNano)`, an integer factor becomes `Int64` (exact), and any other numeric or NULL factor or divisor becomes `Float64`. Probe and evaluate interval multiplication with the checked `mul` kernel. Remove the old `Interval * number => Interval` arms. Closes apache#13850 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Multiplying an interval by a number, which PostgreSQL and DuckDB both support, fails in DataFusion:
Dividing by an integer (
interval '1 day' / 2) fails the same way, whileinterval '1 hour' / 1.5already works.The arrow side of #13850 (apache/arrow-rs#6335) is available in the arrow 60 release DataFusion uses: the kernels support
Interval * Int64,Interval(MonthDayNano) * Float64andInterval(MonthDayNano) / Float64. Two things on the DataFusion side still got in the way:temporal_math_coercioncoerced the numeric operand toInterval(MonthDayNano), which arrow rejects asInterval * Interval.mul_wrapping, but arrow's interval kernels only implement the checkedmul.What changes are included in this PR?
interval_number_coercionhandlesinterval * number,number * intervalandinterval / number: the interval becomesInterval(MonthDayNano), an integer factor becomesInt64(exact multiplication), and any other numeric factor or divisor becomesFloat64. The oldInterval * number => Interval * Intervalarms are removed, sointerval + 2now fails with the generic "cannot coerce" error instead of a cast error.BinaryTypeCoercer::get_resultprobes multiplication withmul, andBinaryExprevaluatesinterval * numberwithmul, since the interval kernels do not implement the wrapping variant.What is the testing strategy for this PR?
datetime/arith_interval_double.slt: the cases that were documented as failing now have expected results.datetime/arith_interval_integer.sltcovers integer factors on both sides, division by an integer,NULLoperands, column inputs, and the result type.datafusion-expr-commonanddatafusion-physical-exprtests.Are there any user-facing changes?
interval * integer,integer * interval,interval * float,float * intervalandinterval / numberare now supported and returnInterval(MonthDayNano).I used an AI coding assistant while working on this change; I have read the diff and the tests and can walk through them.
🤖 Generated with Claude Code