Skip to content

SQL: Polish grammar for intervals #35853

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

Merged
merged 1 commit into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions x-pack/plugin/sql/src/main/antlr/SqlBase.g4
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,6 @@ interval
: INTERVAL sign=(PLUS | MINUS)? (valueNumeric=number | valuePattern=string) leading=intervalField (TO trailing=intervalField)?
;

intervalValue
: number
| string
;

intervalField
: YEAR | YEARS | MONTH | MONTHS | DAY | DAYS | HOUR | HOURS | MINUTE | MINUTES | SECOND | SECONDS
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,10 @@ public Literal visitIntervalLiteral(IntervalLiteralContext ctx) {
"Invalid interval declaration; trailing unit [{}] specified but the value is with numeric (single unit), "
+ "use the string notation instead", trailing);
}
value = of(interval.valueNumeric, negative, leading);
value = of(interval.valueNumeric, leading);
valueAsText = interval.valueNumeric.getText();
} else {
value = visitIntervalValue(interval.valuePattern, negative, intervalType);
value = of(interval.valuePattern, negative, intervalType);
valueAsText = interval.valuePattern.getText();
}

Expand All @@ -559,8 +559,9 @@ public Literal visitIntervalLiteral(IntervalLiteralContext ctx) {
return new Literal(source(ctx), name, timeInterval, intervalType);
}

private TemporalAmount of(NumberContext valueNumeric, boolean negative, TimeUnit unit) {
private TemporalAmount of(NumberContext valueNumeric, TimeUnit unit) {
// expect numbers for now
// as the number parsing handles the -, there's no need to look at that
Literal value = (Literal) visit(valueNumeric);
Number numeric = (Number) value.fold();

Expand All @@ -571,7 +572,7 @@ private TemporalAmount of(NumberContext valueNumeric, boolean negative, TimeUnit
return Intervals.of(source(valueNumeric), numeric.longValue(), unit);
}

private TemporalAmount visitIntervalValue(StringContext valuePattern, boolean negative, DataType intervalType) {
private TemporalAmount of(StringContext valuePattern, boolean negative, DataType intervalType) {
String valueString = string(valuePattern);
Location loc = source(valuePattern);
TemporalAmount interval = Intervals.parseInterval(loc, valueString, intervalType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,18 +995,6 @@ class SqlBaseBaseListener implements SqlBaseListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitInterval(SqlBaseParser.IntervalContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterIntervalValue(SqlBaseParser.IntervalValueContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitIntervalValue(SqlBaseParser.IntervalValueContext ctx) { }
/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,6 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitInterval(SqlBaseParser.IntervalContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitIntervalValue(SqlBaseParser.IntervalValueContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,16 +923,6 @@ interface SqlBaseListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitInterval(SqlBaseParser.IntervalContext ctx);
/**
* Enter a parse tree produced by {@link SqlBaseParser#intervalValue}.
* @param ctx the parse tree
*/
void enterIntervalValue(SqlBaseParser.IntervalValueContext ctx);
/**
* Exit a parse tree produced by {@link SqlBaseParser#intervalValue}.
* @param ctx the parse tree
*/
void exitIntervalValue(SqlBaseParser.IntervalValueContext ctx);
/**
* Enter a parse tree produced by {@link SqlBaseParser#intervalField}.
* @param ctx the parse tree
Expand Down
Loading