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