use of io.crate.sql.tree.IntervalLiteral in project crate by crate.
the class AstBuilder method visitIntervalLiteral.
@Override
public Node visitIntervalLiteral(SqlBaseParser.IntervalLiteralContext context) {
IntervalLiteral.IntervalField startField = getIntervalFieldType((Token) context.from.getChild(0).getPayload());
IntervalLiteral.IntervalField endField = null;
if (context.to != null) {
Token token = (Token) context.to.getChild(0).getPayload();
endField = getIntervalFieldType(token);
}
if (endField != null) {
if (startField.compareTo(endField) > 0) {
throw new IllegalArgumentException("Startfield must be less significant than Endfield");
}
}
IntervalLiteral.Sign sign = IntervalLiteral.Sign.PLUS;
if (context.sign != null) {
sign = getIntervalSign(context.sign);
}
return new IntervalLiteral(((StringLiteral) visit(context.stringLiteral())).getValue(), sign, startField, endField);
}
use of io.crate.sql.tree.IntervalLiteral in project crate by crate.
the class IntervalLiteralTest method testMinute.
@Test
public void testMinute() {
IntervalLiteral interval = (IntervalLiteral) SqlParser.createExpression("INTERVAL +'1' MINUTE");
assertThat(interval.getValue(), is("1"));
assertThat(interval.getSign(), is(IntervalLiteral.Sign.PLUS));
assertThat(interval.getStartField(), is(IntervalLiteral.IntervalField.MINUTE));
assertThat(interval.getEndField(), is(nullValue()));
}
use of io.crate.sql.tree.IntervalLiteral in project crate by crate.
the class IntervalLiteralTest method testYear.
@Test
public void testYear() {
IntervalLiteral interval = (IntervalLiteral) SqlParser.createExpression("INTERVAL +'1' YEAR");
assertThat(interval.getValue(), is("1"));
assertThat(interval.getSign(), is(IntervalLiteral.Sign.PLUS));
assertThat(interval.getStartField(), is(IntervalLiteral.IntervalField.YEAR));
assertThat(interval.getEndField(), is(nullValue()));
}
use of io.crate.sql.tree.IntervalLiteral in project crate by crate.
the class IntervalLiteralTest method testHour.
@Test
public void testHour() {
IntervalLiteral interval = (IntervalLiteral) SqlParser.createExpression("INTERVAL +'1' HOUR");
assertThat(interval.getValue(), is("1"));
assertThat(interval.getSign(), is(IntervalLiteral.Sign.PLUS));
assertThat(interval.getStartField(), is(IntervalLiteral.IntervalField.HOUR));
assertThat(interval.getEndField(), is(nullValue()));
}
use of io.crate.sql.tree.IntervalLiteral in project crate by crate.
the class IntervalLiteralTest method testSecond.
@Test
public void testSecond() {
IntervalLiteral interval = (IntervalLiteral) SqlParser.createExpression("INTERVAL +'1' SECOND");
assertThat(interval.getValue(), is("1"));
assertThat(interval.getSign(), is(IntervalLiteral.Sign.PLUS));
assertThat(interval.getStartField(), is(IntervalLiteral.IntervalField.SECOND));
assertThat(interval.getEndField(), is(nullValue()));
}
Aggregations