use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForTimestampTimestampLT.
@Test
public void shouldGenerateCorrectCodeForTimestampTimestampLT() {
// Given:
final ComparisonExpression compExp = new ComparisonExpression(Type.LESS_THAN, TIMESTAMPCOL, TIMESTAMPCOL);
// When:
final String java = sqlToJavaVisitor.process(compExp);
// Then:
assertThat(java, containsString("(COL10.compareTo(COL10) < 0)"));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldFailOnInconsistentWhenResultType.
@Test
public void shouldFailOnInconsistentWhenResultType() {
// Given:
final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(Type.EQUAL, TestExpressions.COL0, new IntegerLiteral(100)), new StringLiteral("one-hundred")), new WhenClause(new ComparisonExpression(Type.EQUAL, TestExpressions.COL0, new IntegerLiteral(10)), new IntegerLiteral(10))), Optional.empty());
// When:
final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), containsString("Invalid Case expression. Type for all 'THEN' clauses should be the same." + System.lineSeparator() + "THEN expression 'WHEN (COL0 = 10) THEN 10' has type: INTEGER." + System.lineSeparator() + "Previous THEN expression(s) type: STRING."));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldGetCorrectSchemaForSearchedCaseWhenStruct.
@Test
public void shouldGetCorrectSchemaForSearchedCaseWhenStruct() {
// Given:
final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(Type.EQUAL, TestExpressions.COL0, new IntegerLiteral(10)), ADDRESS)), Optional.empty());
// When:
final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
// Then:
final SqlType sqlType = SCHEMA.findColumn(ADDRESS.getColumnName()).get().type();
assertThat(result, is(sqlType));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteComparisonExpression.
@Test
public void shouldRewriteComparisonExpression() {
// Given:
final ComparisonExpression parsed = parseExpression("1 < 2");
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 ComparisonExpression(parsed.getLocation(), parsed.getType(), expr1, expr2)));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SchemaKTableTest method shouldRewriteTimeComparisonInFilter.
@Test
public void shouldRewriteTimeComparisonInFilter() {
// Given:
final String selectQuery = "SELECT col0, col2, col3 FROM test2 " + "WHERE ROWTIME = '1984-01-01T00:00:00+00:00' EMIT CHANGES;";
final PlanNode logicalPlan = buildLogicalPlan(selectQuery);
final FilterNode filterNode = (FilterNode) logicalPlan.getSources().get(0).getSources().get(0);
initialSchemaKTable = buildSchemaKTableFromPlan(logicalPlan);
// When:
final SchemaKTable<?> filteredSchemaKTable = initialSchemaKTable.filter(filterNode.getPredicate(), childContextStacker);
// Then:
final TableFilter<?> step = (TableFilter) filteredSchemaKTable.getSourceTableStep();
assertThat(step.getFilterExpression(), Matchers.equalTo(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("ROWTIME")), new LongLiteral(441763200000L))));
}
Aggregations