Skip to content

Commit

Permalink
[CALCITE-5554] In EXTRACT function, add DAYOFWEEK and DAYOFYEAR as sy…
Browse files Browse the repository at this point in the history
…nonyms for DOW, DOY

Add operator tests, and re-enable some of the tests disabled
in [CALCITE-2539].

Close apache#3094
  • Loading branch information
tanclary authored and julianhyde committed Mar 18, 2023
1 parent b9aaba1 commit 5e3d45b
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 149 deletions.
24 changes: 24 additions & 0 deletions babel/src/test/resources/sql/big-query.iq
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,30 @@ SELECT EXTRACT(DAY FROM DATE '2013-12-25') AS the_day;

!ok

SELECT
EXTRACT(DAYOFWEEK FROM DATE '2008-12-25') as day_of_week,
EXTRACT(DOW FROM DATE '2008-12-25') as dow;
+-------------+-----+
| day_of_week | dow |
+-------------+-----+
| 5 | 5 |
+-------------+-----+
(1 row)

!ok

SELECT
EXTRACT(DAYOFYEAR FROM DATE '2008-12-25') as day_of_year,
EXTRACT(DOY FROM DATE '2008-12-25') as doy;
+-------------+-----+
| day_of_year | doy |
+-------------+-----+
| 360 | 360 |
+-------------+-----+
(1 row)

!ok

# In the following example, EXTRACT returns values corresponding to
# different date parts from a column of dates near the end of the
# year.
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/codegen/default_config.fmpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ parser: {
"DATETIME_DIFF"
"DATETIME_INTERVAL_CODE"
"DATETIME_INTERVAL_PRECISION"
"DAYOFWEEK"
"DAYOFYEAR"
"DAYS"
"DECADE"
"DEFAULTS"
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/codegen/templates/Parser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -5126,6 +5126,8 @@ SqlIntervalQualifier TimeUnit() : {
| <MINUTE> { return new SqlIntervalQualifier(TimeUnit.MINUTE, null, getPos()); }
| <HOUR> { return new SqlIntervalQualifier(TimeUnit.HOUR, null, getPos()); }
| <DAY> { return new SqlIntervalQualifier(TimeUnit.DAY, null, getPos()); }
| <DAYOFWEEK> { return new SqlIntervalQualifier(TimeUnit.DOW, null, getPos()); }
| <DAYOFYEAR> { return new SqlIntervalQualifier(TimeUnit.DOY, null, getPos()); }
| <DOW> { return new SqlIntervalQualifier(TimeUnit.DOW, null, getPos()); }
| <DOY> { return new SqlIntervalQualifier(TimeUnit.DOY, null, getPos()); }
| <ISODOW> { return new SqlIntervalQualifier(TimeUnit.ISODOW, null, getPos()); }
Expand Down Expand Up @@ -7784,6 +7786,8 @@ SqlPostfixOperator PostfixRowOperator() :
| < DATETIME_INTERVAL_PRECISION: "DATETIME_INTERVAL_PRECISION" >
| < DATE_DIFF: "DATE_DIFF" >
| < DAY: "DAY" >
| < DAYOFWEEK: "DAYOFWEEK" >
| < DAYOFYEAR: "DAYOFYEAR" >
| < DAYS: "DAYS" >
| < DEALLOCATE: "DEALLOCATE" >
| < DEC: "DEC" >
Expand Down
2 changes: 2 additions & 0 deletions site/_docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ DATETIME_INTERVAL_PRECISION,
DATE_DIFF,
DATE_TRUNC,
**DAY**,
DAYOFWEEK,
DAYOFYEAR,
DAYS,
**DEALLOCATE**,
**DEC**,
Expand Down

0 comments on commit 5e3d45b

Please sign in to comment.