use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class FilterTypeValidatorTest method shouldThrowOnBadTypeComparison_twoVars.
@Test
public void shouldThrowOnBadTypeComparison_twoVars() {
// Given:
final Expression left = new UnqualifiedColumnReferenceExp(COLUMN1);
final Expression right = new UnqualifiedColumnReferenceExp(COLUMN2);
final Expression comparision = new ComparisonExpression(Type.EQUAL, left, right);
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(comparision));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class FilterTypeValidatorTest method shouldNotThrowOnGoodTypeComparison.
@Test
public void shouldNotThrowOnGoodTypeComparison() {
// Given:
final Expression left = new UnqualifiedColumnReferenceExp(COLUMN1);
final Expression right = new IntegerLiteral(10);
final Expression comparision = new ComparisonExpression(Type.EQUAL, left, right);
when(schema.findValueColumn(any())).thenReturn(Optional.of(Column.of(COLUMN1, INTEGER, VALUE, 10)));
// When:
validator.validateFilterExpression(comparision);
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression 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.ComparisonExpression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateSearchedCase.
@Test
public void shouldEvaluateSearchedCase() {
// Given:
final Expression case1 = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL7, new IntegerLiteral(10)), new StringLiteral("Large")), new WhenClause(new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL7, new IntegerLiteral(5)), new StringLiteral("Medium")), new WhenClause(new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL7, new IntegerLiteral(2)), new StringLiteral("Small"))), Optional.of(new StringLiteral("Tiny")));
final Expression case2 = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, COL7, new IntegerLiteral(6)), new StringLiteral("Blah"))), Optional.empty());
// When:
InterpretedExpression interpreter1 = interpreter(case1);
InterpretedExpression interpreter2 = interpreter(case2);
// Then:
assertThat(interpreter1.evaluate(make(7, 12)), is("Large"));
assertThat(interpreter1.evaluate(make(7, 9)), is("Medium"));
assertThat(interpreter1.evaluate(make(7, 3)), is("Small"));
assertThat(interpreter1.evaluate(make(7, 1)), is("Tiny"));
assertThat(interpreter2.evaluate(make(7, 1)), is("Blah"));
assertThat(interpreter2.evaluate(make(7, 10)), nullValue());
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForDoubleDecimalEQ.
@Test
public void shouldGenerateCorrectCodeForDoubleDecimalEQ() {
// Given:
final ComparisonExpression compExp = new ComparisonExpression(ComparisonExpression.Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("COL3")), new UnqualifiedColumnReferenceExp(ColumnName.of("COL8")));
// When:
final String java = sqlToJavaVisitor.process(compExp);
// Then:
assertThat(java, containsString("(BigDecimal.valueOf(COL3).compareTo(COL8) == 0))"));
}
Aggregations