Skip to content

Commit

Permalink
fix: support uppercase when parsing Interval (#8478)
Browse files Browse the repository at this point in the history
* fix: interval uppercase unit

* feat: add test

* chore: fmt

* chore: remove redundant test
  • Loading branch information
QuenKar authored Dec 11, 2023
1 parent 1861c3d commit 171a5fd
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions datafusion/sql/src/expr/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {

// TODO make interval parsing better in arrow-rs / expose `IntervalType`
fn has_units(val: &str) -> bool {
let val = val.to_lowercase();
val.ends_with("century")
|| val.ends_with("centuries")
|| val.ends_with("decade")
Expand Down
80 changes: 80 additions & 0 deletions datafusion/sqllogictest/test_files/interval.slt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,86 @@ select interval '5' nanoseconds
----
0 years 0 mons 0 days 0 hours 0 mins 0.000000005 secs

query ?
select interval '5 YEAR'
----
0 years 60 mons 0 days 0 hours 0 mins 0.000000000 secs

query ?
select interval '5 MONTH'
----
0 years 5 mons 0 days 0 hours 0 mins 0.000000000 secs

query ?
select interval '5 WEEK'
----
0 years 0 mons 35 days 0 hours 0 mins 0.000000000 secs

query ?
select interval '5 DAY'
----
0 years 0 mons 5 days 0 hours 0 mins 0.000000000 secs

query ?
select interval '5 HOUR'
----
0 years 0 mons 0 days 5 hours 0 mins 0.000000000 secs

query ?
select interval '5 HOURS'
----
0 years 0 mons 0 days 5 hours 0 mins 0.000000000 secs

query ?
select interval '5 MINUTE'
----
0 years 0 mons 0 days 0 hours 5 mins 0.000000000 secs

query ?
select interval '5 SECOND'
----
0 years 0 mons 0 days 0 hours 0 mins 5.000000000 secs

query ?
select interval '5 SECONDS'
----
0 years 0 mons 0 days 0 hours 0 mins 5.000000000 secs

query ?
select interval '5 MILLISECOND'
----
0 years 0 mons 0 days 0 hours 0 mins 0.005000000 secs

query ?
select interval '5 MILLISECONDS'
----
0 years 0 mons 0 days 0 hours 0 mins 0.005000000 secs

query ?
select interval '5 MICROSECOND'
----
0 years 0 mons 0 days 0 hours 0 mins 0.000005000 secs

query ?
select interval '5 MICROSECONDS'
----
0 years 0 mons 0 days 0 hours 0 mins 0.000005000 secs

query ?
select interval '5 NANOSECOND'
----
0 years 0 mons 0 days 0 hours 0 mins 0.000000005 secs

query ?
select interval '5 NANOSECONDS'
----
0 years 0 mons 0 days 0 hours 0 mins 0.000000005 secs

query ?
select interval '5 YEAR 5 MONTH 5 DAY 5 HOUR 5 MINUTE 5 SECOND 5 MILLISECOND 5 MICROSECOND 5 NANOSECOND'
----
0 years 65 mons 5 days 5 hours 5 mins 5.005005005 secs

# Interval with string literal addition
query ?
select interval '1 month' + '1 month'
Expand Down

0 comments on commit 171a5fd

Please sign in to comment.