Search in sources :

Example 1 with IntervalLiteral

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);
}
Also used : IntervalLiteral(io.crate.sql.tree.IntervalLiteral) Token(org.antlr.v4.runtime.Token)

Example 2 with IntervalLiteral

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()));
}
Also used : IntervalLiteral(io.crate.sql.tree.IntervalLiteral) Test(org.junit.Test)

Example 3 with IntervalLiteral

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()));
}
Also used : IntervalLiteral(io.crate.sql.tree.IntervalLiteral) Test(org.junit.Test)

Example 4 with IntervalLiteral

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()));
}
Also used : IntervalLiteral(io.crate.sql.tree.IntervalLiteral) Test(org.junit.Test)

Example 5 with IntervalLiteral

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()));
}
Also used : IntervalLiteral(io.crate.sql.tree.IntervalLiteral) Test(org.junit.Test)

Aggregations

IntervalLiteral (io.crate.sql.tree.IntervalLiteral)9 Test (org.junit.Test)8 Token (org.antlr.v4.runtime.Token)1