Skip to content

Commit e22a835

Browse files
authored
SQL: Polish grammar for intervals (#35853)
1 parent a204d1c commit e22a835

7 files changed

Lines changed: 786 additions & 892 deletions

File tree

x-pack/plugin/sql/src/main/antlr/SqlBase.g4

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,6 @@ interval
288288
: INTERVAL sign=(PLUS | MINUS)? (valueNumeric=number | valuePattern=string) leading=intervalField (TO trailing=intervalField)?
289289
;
290290

291-
intervalValue
292-
: number
293-
| string
294-
;
295-
296291
intervalField
297292
: YEAR | YEARS | MONTH | MONTHS | DAY | DAYS | HOUR | HOURS | MINUTE | MINUTES | SECOND | SECONDS
298293
;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/ExpressionBuilder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,10 @@ public Literal visitIntervalLiteral(IntervalLiteralContext ctx) {
544544
"Invalid interval declaration; trailing unit [{}] specified but the value is with numeric (single unit), "
545545
+ "use the string notation instead", trailing);
546546
}
547-
value = of(interval.valueNumeric, negative, leading);
547+
value = of(interval.valueNumeric, leading);
548548
valueAsText = interval.valueNumeric.getText();
549549
} else {
550-
value = visitIntervalValue(interval.valuePattern, negative, intervalType);
550+
value = of(interval.valuePattern, negative, intervalType);
551551
valueAsText = interval.valuePattern.getText();
552552
}
553553

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

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

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

574-
private TemporalAmount visitIntervalValue(StringContext valuePattern, boolean negative, DataType intervalType) {
575+
private TemporalAmount of(StringContext valuePattern, boolean negative, DataType intervalType) {
575576
String valueString = string(valuePattern);
576577
Location loc = source(valuePattern);
577578
TemporalAmount interval = Intervals.parseInterval(loc, valueString, intervalType);

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseBaseListener.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -995,18 +995,6 @@ class SqlBaseBaseListener implements SqlBaseListener {
995995
* <p>The default implementation does nothing.</p>
996996
*/
997997
@Override public void exitInterval(SqlBaseParser.IntervalContext ctx) { }
998-
/**
999-
* {@inheritDoc}
1000-
*
1001-
* <p>The default implementation does nothing.</p>
1002-
*/
1003-
@Override public void enterIntervalValue(SqlBaseParser.IntervalValueContext ctx) { }
1004-
/**
1005-
* {@inheritDoc}
1006-
*
1007-
* <p>The default implementation does nothing.</p>
1008-
*/
1009-
@Override public void exitIntervalValue(SqlBaseParser.IntervalValueContext ctx) { }
1010998
/**
1011999
* {@inheritDoc}
10121000
*

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseBaseVisitor.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -585,13 +585,6 @@ class SqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SqlBa
585585
* {@link #visitChildren} on {@code ctx}.</p>
586586
*/
587587
@Override public T visitInterval(SqlBaseParser.IntervalContext ctx) { return visitChildren(ctx); }
588-
/**
589-
* {@inheritDoc}
590-
*
591-
* <p>The default implementation returns the result of calling
592-
* {@link #visitChildren} on {@code ctx}.</p>
593-
*/
594-
@Override public T visitIntervalValue(SqlBaseParser.IntervalValueContext ctx) { return visitChildren(ctx); }
595588
/**
596589
* {@inheritDoc}
597590
*

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/SqlBaseListener.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -923,16 +923,6 @@ interface SqlBaseListener extends ParseTreeListener {
923923
* @param ctx the parse tree
924924
*/
925925
void exitInterval(SqlBaseParser.IntervalContext ctx);
926-
/**
927-
* Enter a parse tree produced by {@link SqlBaseParser#intervalValue}.
928-
* @param ctx the parse tree
929-
*/
930-
void enterIntervalValue(SqlBaseParser.IntervalValueContext ctx);
931-
/**
932-
* Exit a parse tree produced by {@link SqlBaseParser#intervalValue}.
933-
* @param ctx the parse tree
934-
*/
935-
void exitIntervalValue(SqlBaseParser.IntervalValueContext ctx);
936926
/**
937927
* Enter a parse tree produced by {@link SqlBaseParser#intervalField}.
938928
* @param ctx the parse tree

0 commit comments

Comments
 (0)