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));
}
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;
}
Aggregations