Search in sources :

Example 16 with BooleanLiteral

use of io.confluent.ksql.execution.expression.tree.BooleanLiteral in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldThrowIfNotComparisonExpression.

@Test
public void shouldThrowIfNotComparisonExpression() {
    // Given:
    final Expression expression = new BooleanLiteral(true);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
    // Then:
    assertThat(e.getMessage(), containsString("Unsupported expression in WHERE clause: true."));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 17 with BooleanLiteral

use of io.confluent.ksql.execution.expression.tree.BooleanLiteral in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldThrowOnInvalidTimestampType.

@Test
public void shouldThrowOnInvalidTimestampType() {
    // Given:
    final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression windowStart = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWSTART")), new BooleanLiteral(false));
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp, windowStart);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, true, plannerOptions));
    // Then:
    assertThat(e.getMessage(), containsString("Window bounds must resolve to an INT, BIGINT, or " + "STRING containing a datetime."));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) KsqlException(io.confluent.ksql.util.KsqlException) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 18 with BooleanLiteral

use of io.confluent.ksql.execution.expression.tree.BooleanLiteral in project ksql by confluentinc.

the class ImplicitlyCastResolverTest method shouldNotCastToDecimal.

@Test
public void shouldNotCastToDecimal() {
    // Given
    final List<Literal> fromLiterals = Arrays.asList(new BooleanLiteral("true"), new StringLiteral("10.2"), new DecimalLiteral(BigDecimal.valueOf(10.133)));
    for (final Literal literal : fromLiterals) {
        // When
        final Expression expression = ImplicitlyCastResolver.resolve(literal, DECIMAL_5_2);
        // Then
        assertThat("Should not cast " + literal.getClass().getSimpleName() + " to " + DECIMAL_5_2, expression, instanceOf(literal.getClass()));
        assertThat("Should not cast " + literal.getClass().getSimpleName() + " to " + DECIMAL_5_2, expression.equals(literal), is(true));
    }
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) Expression(io.confluent.ksql.execution.expression.tree.Expression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Literal(io.confluent.ksql.execution.expression.tree.Literal) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) Test(org.junit.Test)

Example 19 with BooleanLiteral

use of io.confluent.ksql.execution.expression.tree.BooleanLiteral in project ksql by confluentinc.

the class InterpretedExpressionTest method shouldEvaluateLogicalExpressions_or.

@Test
public void shouldEvaluateLogicalExpressions_or() {
    // Given:
    final Expression expression1 = new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR, COL11, new BooleanLiteral(true));
    final Expression expression2 = new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR, COL11, new BooleanLiteral(false));
    // When:
    InterpretedExpression interpreter1 = interpreter(expression1);
    InterpretedExpression interpreter2 = interpreter(expression2);
    // Then:
    assertThat(interpreter1.evaluate(make(11, true)), is(true));
    assertThat(interpreter1.evaluate(make(11, false)), is(true));
    assertThat(interpreter2.evaluate(make(11, true)), is(true));
    assertThat(interpreter2.evaluate(make(11, false)), is(false));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Test(org.junit.Test)

Example 20 with BooleanLiteral

use of io.confluent.ksql.execution.expression.tree.BooleanLiteral in project ksql by confluentinc.

the class InterpretedExpressionTest method shouldEvaluateLogicalExpressions_and.

@Test
public void shouldEvaluateLogicalExpressions_and() {
    // Given:
    final Expression expression1 = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, COL11, new BooleanLiteral(true));
    final Expression expression2 = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, COL11, new BooleanLiteral(false));
    // When:
    InterpretedExpression interpreter1 = interpreter(expression1);
    InterpretedExpression interpreter2 = interpreter(expression2);
    // Then:
    assertThat(interpreter1.evaluate(make(11, true)), is(true));
    assertThat(interpreter1.evaluate(make(11, false)), is(false));
    assertThat(interpreter2.evaluate(make(11, true)), is(false));
    assertThat(interpreter2.evaluate(make(11, false)), is(false));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Test(org.junit.Test)

Aggregations

BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)22 Test (org.junit.Test)22 Expression (io.confluent.ksql.execution.expression.tree.Expression)14 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)12 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)11 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)11 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)11 KsqlException (io.confluent.ksql.util.KsqlException)11 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)9 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)6 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)4 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)4 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)3 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)3 Literal (io.confluent.ksql.execution.expression.tree.Literal)3 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)3 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)3 DecimalLiteral (io.confluent.ksql.execution.expression.tree.DecimalLiteral)2