Search in sources :

Example 21 with LogicalBinaryExpression

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

the class ExpressionTreeRewriterTest method shouldRewriteLogicalBinaryExpression.

@Test
public void shouldRewriteLogicalBinaryExpression() {
    // Given:
    final LogicalBinaryExpression parsed = parseExpression("true OR false");
    when(processor.apply(parsed.getLeft(), context)).thenReturn(expr1);
    when(processor.apply(parsed.getRight(), context)).thenReturn(expr2);
    // When:
    final Expression rewritten = expressionRewriter.rewrite(parsed, context);
    // Then:
    assertThat(rewritten, equalTo(new LogicalBinaryExpression(parsed.getLocation(), parsed.getType(), expr1, expr2)));
}
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) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) 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) Test(org.junit.Test)

Example 22 with LogicalBinaryExpression

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

the class FilterTypeValidatorTest method shouldThrowOnBadTypeCompoundComparison_rightError.

@Test
public void shouldThrowOnBadTypeCompoundComparison_rightError() {
    // Given:
    final Expression left1 = new UnqualifiedColumnReferenceExp(COLUMN2);
    final Expression right1 = new IntegerLiteral(10);
    final Expression comparision1 = new ComparisonExpression(Type.EQUAL, left1, right1);
    final Expression left2 = new UnqualifiedColumnReferenceExp(COLUMN1);
    final Expression right2 = new UnqualifiedColumnReferenceExp(COLUMN2);
    final Expression comparision2 = new ComparisonExpression(Type.EQUAL, left2, right2);
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, comparision1, comparision2);
    when(schema.findValueColumn(COLUMN1)).thenReturn(Optional.of(Column.of(COLUMN1, STRING, VALUE, 10)));
    when(schema.findValueColumn(COLUMN2)).thenReturn(Optional.of(Column.of(COLUMN2, INTEGER, VALUE, 10)));
    // When:
    assertThrows("Error in WHERE expression: " + "Cannot compare col1 (STRING) to col2 (INTEGER) with EQUAL.", KsqlException.class, () -> validator.validateFilterExpression(expression));
}
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) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 23 with LogicalBinaryExpression

use of io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression 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 24 with LogicalBinaryExpression

use of io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression 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)

Example 25 with LogicalBinaryExpression

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

the class ExpressionFormatterTest method shouldFormatLambdaExpression.

@Test
public void shouldFormatLambdaExpression() {
    // Given:
    final LambdaFunctionCall expression = new LambdaFunctionCall(Optional.of(LOCATION), ImmutableList.of("X", "Y"), new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR, new LambdaVariable("X"), new LambdaVariable("Y")));
    // When:
    final String text = ExpressionFormatter.formatExpression(expression);
    // Then:
    assertThat(text, equalTo("(X, Y) => (X OR Y)"));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) LambdaVariable(io.confluent.ksql.execution.expression.tree.LambdaVariable) Test(org.junit.Test)

Aggregations

LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)37 Test (org.junit.Test)37 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)35 Expression (io.confluent.ksql.execution.expression.tree.Expression)35 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)33 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)33 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)32 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)29 WindowBounds (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds)11 WindowRange (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds.WindowRange)11 KsqlException (io.confluent.ksql.util.KsqlException)10 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)6 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)4 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)3 BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)3 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)3 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)3 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)3 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)3 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)3