Search in sources :

Example 1 with ArrayComparisonExpression

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

the class TestStatementBuilder method testArrayComparison.

@Test
public void testArrayComparison() {
    Expression anyExpression = SqlParser.createExpression("1 = ANY (arrayColumnRef)");
    assertThat(anyExpression, instanceOf(ArrayComparisonExpression.class));
    ArrayComparisonExpression arrayComparisonExpression = (ArrayComparisonExpression) anyExpression;
    assertThat(arrayComparisonExpression.quantifier(), is(ArrayComparisonExpression.Quantifier.ANY));
    assertThat(arrayComparisonExpression.getLeft(), instanceOf(IntegerLiteral.class));
    assertThat(arrayComparisonExpression.getRight(), instanceOf(QualifiedNameReference.class));
    Expression someExpression = SqlParser.createExpression("1 = SOME (arrayColumnRef)");
    assertThat(someExpression, instanceOf(ArrayComparisonExpression.class));
    ArrayComparisonExpression someArrayComparison = (ArrayComparisonExpression) someExpression;
    assertThat(someArrayComparison.quantifier(), is(ArrayComparisonExpression.Quantifier.ANY));
    assertThat(someArrayComparison.getLeft(), instanceOf(IntegerLiteral.class));
    assertThat(someArrayComparison.getRight(), instanceOf(QualifiedNameReference.class));
    Expression allExpression = SqlParser.createExpression("'StringValue' = ALL (arrayColumnRef)");
    assertThat(allExpression, instanceOf(ArrayComparisonExpression.class));
    ArrayComparisonExpression allArrayComparison = (ArrayComparisonExpression) allExpression;
    assertThat(allArrayComparison.quantifier(), is(ArrayComparisonExpression.Quantifier.ALL));
    assertThat(allArrayComparison.getLeft(), instanceOf(StringLiteral.class));
    assertThat(allArrayComparison.getRight(), instanceOf(QualifiedNameReference.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) ArrayComparisonExpression(io.crate.sql.tree.ArrayComparisonExpression) IntegerLiteral(io.crate.sql.tree.IntegerLiteral) QualifiedNameReference(io.crate.sql.tree.QualifiedNameReference) Test(org.junit.Test)

Example 2 with ArrayComparisonExpression

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

the class TestStatementBuilder method testArrayComparisonSubSelect.

@Test
public void testArrayComparisonSubSelect() {
    Expression anyExpression = SqlParser.createExpression("1 = ANY ((SELECT 5))");
    assertThat(anyExpression, instanceOf(ArrayComparisonExpression.class));
    ArrayComparisonExpression arrayComparisonExpression = (ArrayComparisonExpression) anyExpression;
    assertThat(arrayComparisonExpression.quantifier(), is(ArrayComparisonExpression.Quantifier.ANY));
    assertThat(arrayComparisonExpression.getLeft(), instanceOf(IntegerLiteral.class));
    assertThat(arrayComparisonExpression.getRight(), instanceOf(SubqueryExpression.class));
    // It's possible to omit the parenthesis
    anyExpression = SqlParser.createExpression("1 = ANY (SELECT 5)");
    assertThat(anyExpression, instanceOf(ArrayComparisonExpression.class));
    arrayComparisonExpression = (ArrayComparisonExpression) anyExpression;
    assertThat(arrayComparisonExpression.quantifier(), is(ArrayComparisonExpression.Quantifier.ANY));
    assertThat(arrayComparisonExpression.getLeft(), instanceOf(IntegerLiteral.class));
    assertThat(arrayComparisonExpression.getRight(), instanceOf(SubqueryExpression.class));
}
Also used : 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) ArrayComparisonExpression(io.crate.sql.tree.ArrayComparisonExpression) IntegerLiteral(io.crate.sql.tree.IntegerLiteral) SubqueryExpression(io.crate.sql.tree.SubqueryExpression) Test(org.junit.Test)

Aggregations

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