use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteBetweenPredicateUsingPlugin.
@Test
public void shouldRewriteBetweenPredicateUsingPlugin() {
// Given:
final Expression parsed = parseExpression("1 BETWEEN 0 AND 2");
// When/Then:
shouldRewriteUsingPlugin(parsed);
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteSearchedCaseExpressionUsingPlugin.
@Test
public void shouldRewriteSearchedCaseExpressionUsingPlugin() {
// Given:
final Expression parsed = parseExpression("CASE WHEN col0=1 THEN 'one' WHEN col0=2 THEN 'two' ELSE 'three' END");
// When/Then:
shouldRewriteUsingPlugin(parsed);
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteSearchedCaseExpression.
@Test
public void shouldRewriteSearchedCaseExpression() {
// Given:
final SearchedCaseExpression parsed = parseExpression("CASE WHEN col0=1 THEN 'one' WHEN col0=2 THEN 'two' ELSE 'three' END");
when(processor.apply(parsed.getWhenClauses().get(0), context)).thenReturn(when1);
when(processor.apply(parsed.getWhenClauses().get(1), context)).thenReturn(when2);
when(processor.apply(any(StringLiteral.class), any())).thenReturn(expr1);
// When:
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new SearchedCaseExpression(parsed.getLocation(), ImmutableList.of(when1, when2), Optional.of(expr1))));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldThrowOnTypeMismatchCannotCoerce.
@Test
public void shouldThrowOnTypeMismatchCannotCoerce() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.INTEGER).build();
final List<ColumnName> names = ImmutableList.of(KEY, COL0);
final Expression exp = new StringLiteral("a");
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> recordFactory.build(names, ImmutableList.of(exp, exp), schema, DataSourceType.KSTREAM));
// Then:
assertThat(e.getMessage(), containsString("Expected type"));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldBuildPartialColumns.
@Test
public void shouldBuildPartialColumns() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).valueColumn(COL1, SqlTypes.STRING).build();
final List<ColumnName> names = ImmutableList.of(KEY, COL0);
final Expression exp = new StringLiteral("a");
// When:
final KsqlGenericRecord record = recordFactory.build(names, ImmutableList.of(exp, exp), schema, DataSourceType.KSTREAM);
// Then:
assertThat(record, is(KsqlGenericRecord.of(GenericKey.genericKey("a"), GenericRow.genericRow("a", null), 0)));
}
Aggregations