Search in sources :

Example 1 with SubscriptExpression

use of io.crate.sql.tree.SubscriptExpression in project crate by crate.

the class TestStatementBuilder method testSubscriptExpression.

@Test
public void testSubscriptExpression() {
    Expression expression = SqlParser.createExpression("a['sub']");
    assertThat(expression, instanceOf(SubscriptExpression.class));
    SubscriptExpression subscript = (SubscriptExpression) expression;
    assertThat(subscript.index(), instanceOf(StringLiteral.class));
    assertThat(((StringLiteral) subscript.index()).getValue(), is("sub"));
    assertThat(subscript.base(), instanceOf(QualifiedNameReference.class));
    expression = SqlParser.createExpression("[1,2,3][1]");
    assertThat(expression, instanceOf(SubscriptExpression.class));
    subscript = (SubscriptExpression) expression;
    assertThat(subscript.index(), instanceOf(IntegerLiteral.class));
    assertThat(((IntegerLiteral) subscript.index()).getValue(), is(1));
    assertThat(subscript.base(), instanceOf(ArrayLiteral.class));
}
Also used : EscapedCharStringLiteral(io.crate.sql.tree.EscapedCharStringLiteral) StringLiteral(io.crate.sql.tree.StringLiteral) SubqueryExpression(io.crate.sql.tree.SubqueryExpression) SubscriptExpression(io.crate.sql.tree.SubscriptExpression) ParameterExpression(io.crate.sql.tree.ParameterExpression) ArrayComparisonExpression(io.crate.sql.tree.ArrayComparisonExpression) Expression(io.crate.sql.tree.Expression) ComparisonExpression(io.crate.sql.tree.ComparisonExpression) NegativeExpression(io.crate.sql.tree.NegativeExpression) SubscriptExpression(io.crate.sql.tree.SubscriptExpression) ArrayLiteral(io.crate.sql.tree.ArrayLiteral) QualifiedNameReference(io.crate.sql.tree.QualifiedNameReference) IntegerLiteral(io.crate.sql.tree.IntegerLiteral) Test(org.junit.Test)

Example 2 with SubscriptExpression

use of io.crate.sql.tree.SubscriptExpression in project crate by crate.

the class SubscriptValidatorTest method analyzeSubscript.

private SubscriptContext analyzeSubscript(String expressionString) {
    SubscriptContext context = new SubscriptContext();
    Expression expression = SqlParser.createExpression(expressionString);
    SubscriptValidator.validate((SubscriptExpression) expression, context);
    return context;
}
Also used : SubscriptExpression(io.crate.sql.tree.SubscriptExpression) Expression(io.crate.sql.tree.Expression)

Aggregations

Expression (io.crate.sql.tree.Expression)2 SubscriptExpression (io.crate.sql.tree.SubscriptExpression)2 ArrayComparisonExpression (io.crate.sql.tree.ArrayComparisonExpression)1 ArrayLiteral (io.crate.sql.tree.ArrayLiteral)1 ComparisonExpression (io.crate.sql.tree.ComparisonExpression)1 EscapedCharStringLiteral (io.crate.sql.tree.EscapedCharStringLiteral)1 IntegerLiteral (io.crate.sql.tree.IntegerLiteral)1 NegativeExpression (io.crate.sql.tree.NegativeExpression)1 ParameterExpression (io.crate.sql.tree.ParameterExpression)1 QualifiedNameReference (io.crate.sql.tree.QualifiedNameReference)1 StringLiteral (io.crate.sql.tree.StringLiteral)1 SubqueryExpression (io.crate.sql.tree.SubqueryExpression)1 Test (org.junit.Test)1