Skip to content

ARROW-10816: [Rust][DataFusion] Initial support for Interval expressions - #9373

Closed
ovr wants to merge 1 commit into
apache:masterfrom
ovr:issue-10816
Closed

ARROW-10816: [Rust][DataFusion] Initial support for Interval expressions#9373
ovr wants to merge 1 commit into
apache:masterfrom
ovr:issue-10816

Conversation

@ovr

@ovrovr commented Jan 30, 2021

Copy link
Copy Markdown
Contributor

Initial support for Interval expressions in Data Fusion. This PR allows creating interval from SQL, store intervals in ScalarValue(s) and displaying intervals in tests.

@github-actions

Copy link
Copy Markdown

@ovrovr changed the title ARROW-10816: [Rust][DataFushion] Initial support for Interval express… ARROW-10816: [Rust][DF] Initial support for Interval expressionsJan 30, 2021
@codecov-io

codecov-io commented Jan 30, 2021

Copy link
Copy Markdown

Codecov Report

Merging #9373 (3e10d6d) into master (3d4c2bb) will decrease coverage by 0.05%.
The diff coverage is 57.85%.

Impacted file tree graph

@@ Coverage Diff @@## master #9373 +/- ##
==========================================
- Coverage 82.10% 82.05% -0.06% 
==========================================
Files 230 230 Lines 54043 54164 +121 ==========================================
+ Hits 44374 44442 +68 - Misses 9669 9722 +53 
Impacted FilesCoverage Δ
rust/arrow/src/datatypes.rs78.33% <ø> (ø)
rust/datafusion/src/sql/planner.rs82.70% <51.11%> (-3.01%)⬇️
rust/datafusion/src/scalar.rs56.28% <63.15%> (+0.43%)⬆️
rust/arrow/src/util/display.rs77.14% <100.00%> (+1.38%)⬆️
rust/datafusion/tests/sql.rs99.85% <100.00%> (+<0.01%)⬆️
rust/arrow/src/array/equal/utils.rs75.49% <0.00%> (-0.99%)⬇️
rust/parquet/src/encodings/encoding.rs94.86% <0.00%> (-0.20%)⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d4c2bb...7e55dd4. Read the comment docs.

@ovr
ovr marked this pull request as ready for review January 31, 2021 20:12
@ovrovr changed the title ARROW-10816: [Rust][DF] Initial support for Interval expressionsARROW-10816: [Rust][DF] Initial support for Interval expressionsJan 31, 2021
@ovr

ovr commented Jan 31, 2021

Copy link
Copy Markdown
ContributorAuthor

@alamb@andygrove@Dandandan@jorgecarleitao It's initial support for intervals, I've got some questions:

EDITED

  • Is it correct how I store it? (I found in C++ source, starting to work on correct implementation)
  • What about rang overflows, should it be implemented?

P.S I next PR i will add binary operations for intervals and support for DateTime + Intervals.

Thanks

@ovr
ovrforce-pushed the issue-10816 branch 2 times, most recently from fc1b71b to 7cf5df7CompareJanuary 31, 2021 20:28
@ovr

ovr commented Jan 31, 2021

Copy link
Copy Markdown
ContributorAuthor

Wow, I found that it's possible to write

select INTERVAL '1 hour 1 second 1 month';
select INTERVAL '250 year 1 month 1 day 100 milliseconds';

Start to work on support for it.

And I found how It's implemented in C++

https://github.com/apache/arrow/blob/master/cpp/src/arrow/type.h#L1238

Started to rework this branch, marked as DRAFT.

@ovr
ovr marked this pull request as draft January 31, 2021 22:19
@ovr
ovrforce-pushed the issue-10816 branch 2 times, most recently from cc553e6 to f1d9d97CompareFebruary 1, 2021 17:36

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really nice @ovr -- let me know when you are ready for a full review.

Comment threadrust/arrow/src/util/display.rs Outdated
Comment threadrust/datafusion/src/sql/planner.rs Outdated
Comment threadrust/datafusion/tests/sql.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth testing with a fractional interval as well interval '2.3' years as I think your implementation parses the numbers as a f32

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added.

Comment threadrust/datafusion/src/sql/planner.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 is really nice

Comment threadrust/datafusion/src/sql/planner.rs Outdated
Comment threadrust/datafusion/src/sql/planner.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be i32 as well as the other types f32?

@ovrovrFeb 3, 2021

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using f32 for compability with PostgreSQL dialect:

SELECT INTERVAL '0.5 day';
0 years 0 mons 0 days 12 hours 0 mins 0.00 secs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize that was possible. What about rounding errors (and rounding in general)?

@ovrovrFeb 4, 2021

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont have any ideas, how it should be correct, but anyway using 0.5 DAY or 0.5 HOUR will be rly usefull and works as expected.

Can you point my attention how it should works?

Thanks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether rounding errors are going to be a problem, I could imagine some calculation might cause for example the number of milliseconds to be off for non-trivial fractions?
In that case we should use some decimal type instead of f32 in order to avoid those rounding errors.

@ovrovrFeb 4, 2021

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dandandan

for example the number of milliseconds to be off for non-trivial fractions?

It's better to use Decimal anyway.

👍 I can place a comment in this place with // @todo, when I will finish with #9232 I can reuse Decimal128 in this place. Is it ok? Thanks

@ovr
ovrforce-pushed the issue-10816 branch 7 times, most recently from 3717acf to 540e375CompareFebruary 4, 2021 08:49
@ovr
ovr marked this pull request as ready for review February 4, 2021 09:05
@ovr

ovr commented Feb 4, 2021

Copy link
Copy Markdown
ContributorAuthor

I think this PR is now ready for review/merge.

In the next PRs I am planing to work on:

  • BinaryExpressions for Dates and Intervals
  • ISO8601 intervals
  • Introduce ArrowIntervalType trait

Thanks

@alamb

alamb commented Feb 4, 2021

Copy link
Copy Markdown
Contributor

Thanks @ovr -- I plan to review this carefully later today

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ovr this is looking really nice.

I have some questions / concerns over NULL and fractional month handling, but otherwise I think this PR looks great.

I think getting this PR to a place where we generate errors when we can't represent the intervals precisely is a good enough place to stop for now.

To properly support full precision intervals, I think we would need to add a new type to arrow that was the combination of DateTime and YearMonth -- which we would definitely not do as part of this PR :)

Again, really nice!

Comment threadrust/arrow/src/util/display.rs Outdated
Comment threadrust/arrow/src/util/display.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as below about NULL vs 0 handling

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Yes, it's better to represent NULL as string instead of it. Thanks

Comment threadrust/datafusion/src/sql/planner.rs Outdated
Comment threadrust/datafusion/src/sql/planner.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 agree with this comment.

I think an additional restriction we should perhaps consider is 'only support integral numbers of months + years' as the YearMonthInterval interval type can not capture precisely fractional parts

https://github.com/apache/arrow/blob/master/format/Schema.fbs#L253-L254

Comment threadrust/datafusion/src/sql/planner.rs Outdated
@alambalamb changed the title ARROW-10816: [Rust][DF] Initial support for Interval expressionsARROW-10816: [Rust][DataFusion] Initial support for Interval expressionsFeb 4, 2021

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good enough to merge. I am sure there are plenty of more improvements, but for now, this is a wonderful start. Thanks so much @ovr

@jorgecarleitao / @andygrove / @Dandandan any thoughts?

Comment threadrust/datafusion/src/sql/planner.rs Outdated
@alamb

alamb commented Feb 6, 2021

Copy link
Copy Markdown
Contributor

I'll plan to merge this tomorrow (Sunday) or Monday unless anyone else has any comments

@alamb

alamb commented Feb 7, 2021

Copy link
Copy Markdown
Contributor

Thanks again for sticking with this @ovr -- nice work and thank you

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@ovr@codecov-io@alamb@Dandandan