-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Strict INTERVAL literal syntax #23157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -720,11 +720,12 @@ booleanValue | |
| ; | ||
|
|
||
| interval | ||
| : INTERVAL sign=(PLUS | MINUS)? string from=intervalField (TO to=intervalField)? | ||
| ; | ||
|
|
||
| intervalField | ||
| : YEAR | MONTH | DAY | HOUR | MINUTE | SECOND | ||
| : INTERVAL sign=(PLUS | MINUS)? string from=YEAR (TO to=MONTH)? | ||
| | INTERVAL sign=(PLUS | MINUS)? string from=MONTH | ||
| | INTERVAL sign=(PLUS | MINUS)? string from=DAY (TO to=(HOUR | MINUTE | SECOND))? | ||
| | INTERVAL sign=(PLUS | MINUS)? string from=HOUR (TO to=(MINUTE | SECOND))? | ||
| | INTERVAL sign=(PLUS | MINUS)? string from=MINUTE (TO to=SECOND)? | ||
| | INTERVAL sign=(PLUS | MINUS)? string from=SECOND | ||
|
Comment on lines
+723
to
+728
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rules basically say:
From the above the only valid combinations are: The changes seem to match this. And significance is defined in the order |
||
| ; | ||
|
|
||
| normalForm | ||
|
|
@@ -733,7 +734,12 @@ normalForm | |
|
|
||
| type | ||
| : ROW '(' rowField (',' rowField)* ')' #rowType | ||
| | INTERVAL from=intervalField (TO to=intervalField)? #intervalType | ||
| | INTERVAL from=YEAR (TO to=MONTH)? #yearMonthIntervalDataType | ||
| | INTERVAL from=MONTH #yearMonthIntervalDataType | ||
| | INTERVAL from=DAY (TO to=(HOUR | MINUTE | SECOND))? #dayTimeIntervalDataType | ||
| | INTERVAL from=HOUR (TO to=(MINUTE | SECOND))? #dayTimeIntervalDataType | ||
| | INTERVAL from=MINUTE (TO to=MINUTE)? #dayTimeIntervalDataType | ||
| | INTERVAL from=SECOND #dayTimeIntervalDataType | ||
|
Comment on lines
+737
to
+742
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is the sign part missing here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also since you've changed the type names here I guess |
||
| | base=TIMESTAMP ('(' precision = typeParameter ')')? (WITHOUT TIME ZONE)? #dateTimeType | ||
| | base=TIMESTAMP ('(' precision = typeParameter ')')? WITH TIME ZONE #dateTimeType | ||
| | base=TIME ('(' precision = typeParameter ')')? (WITHOUT TIME ZONE)? #dateTimeType | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,12 @@ public void testLiterals() | |
|
|
||
| assertThatThrownBy(assertions.expression("INTERVAL '--124--30' YEAR TO MONTH")::evaluate) | ||
| .hasMessage("line 1:12: '--124--30' is not a valid INTERVAL literal"); | ||
|
|
||
| assertThatThrownBy(assertions.expression("INTERVAL '124' YEAR TO YEAR"):: evaluate) | ||
| .hasMessage("line 1:35: mismatched input 'YEAR'. Expecting: 'MONTH'"); | ||
|
|
||
| assertThatThrownBy(assertions.expression("INTERVAL '124' MONTH TO MONTH"):: evaluate) | ||
| .hasMessageContaining("line 1:33: mismatched input 'TO'."); | ||
|
Comment on lines
+87
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how this is better than the older behaviour? |
||
| } | ||
|
|
||
| private static SqlIntervalYearMonth interval(int year, int month) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First thing I notice - the grammar in ANSI SQL matches what we had earlier. The restrictions on what combination of
fromandtoare valid is mentioned in the "Syntax Rules" section.