use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldFailIfDefaultHasDifferentTypeToWhen.
@Test
public void shouldFailIfDefaultHasDifferentTypeToWhen() {
// Given:
final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(Type.EQUAL, TestExpressions.COL0, new IntegerLiteral(10)), new StringLiteral("good"))), Optional.of(new BooleanLiteral("true")));
// When:
final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), containsString("Invalid Case expression. Type for the default clause should be the same as for 'THEN' clauses." + System.lineSeparator() + "THEN type: STRING." + System.lineSeparator() + "DEFAULT type: BOOLEAN."));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class KsqlParserTest method testProjectFilter.
@Test
public void testProjectFilter() {
final String queryStr = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100;";
final Statement statement = KsqlParserTestUtil.buildSingleAst(queryStr, metaStore).getStatement();
assertThat(statement, is(instanceOf(Query.class)));
final Query query = (Query) statement;
Assert.assertTrue(query.getWhere().get() instanceof ComparisonExpression);
final ComparisonExpression comparisonExpression = (ComparisonExpression) query.getWhere().get();
assertThat(comparisonExpression.toString(), is("(COL0 > 100)"));
assertThat(query.getSelect().getSelectItems(), hasSize(3));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SchemaKStreamTest method shouldRewriteTimeComparisonInFilter.
@Test
@SuppressWarnings("rawtypes")
public void shouldRewriteTimeComparisonInFilter() {
// Given:
final PlanNode logicalPlan = givenInitialKStreamOf("SELECT col0, col2, col3 FROM test1 " + "WHERE ROWTIME = '1984-01-01T00:00:00+00:00' EMIT CHANGES;");
final FilterNode filterNode = (FilterNode) logicalPlan.getSources().get(0).getSources().get(0);
// When:
final SchemaKStream<?> filteredSchemaKStream = initialSchemaKStream.filter(filterNode.getPredicate(), childContextStacker);
// Then:
final StreamFilter step = (StreamFilter) filteredSchemaKStream.getSourceStep();
assertThat(step.getFilterExpression(), equalTo(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("ROWTIME")), new LongLiteral(441763200000L))));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForDecimalDecimalLEQ.
@Test
public void shouldGenerateCorrectCodeForDecimalDecimalLEQ() {
// Given:
final ComparisonExpression compExp = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN_OR_EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("COL8")), new UnqualifiedColumnReferenceExp(ColumnName.of("COL9")));
// When:
final String java = sqlToJavaVisitor.process(compExp);
// Then:
assertThat(java, containsString("(COL8.compareTo(COL9) <= 0))"));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForTimestampStringEQ.
@Test
public void shouldGenerateCorrectCodeForTimestampStringEQ() {
// Given:
final ComparisonExpression compExp = new ComparisonExpression(Type.EQUAL, TIMESTAMPCOL, new StringLiteral("2020-01-01T00:00:00"));
// When:
final String java = sqlToJavaVisitor.process(compExp);
// Then:
assertThat(java, containsString("(COL10.compareTo(SqlTimeTypes.parseTimestamp(\"2020-01-01T00:00:00\")) == 0)"));
}
Aggregations