use of io.confluent.ksql.execution.expression.tree.CreateStructExpression in project ksql by confluentinc.
the class CoercionUtilTest method shouldNotCoerceStructWithDifferentExpression.
@Test
public void shouldNotCoerceStructWithDifferentExpression() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateStructExpression(ImmutableList.of(new Field("a", new IntegerLiteral(10)))), new CreateStructExpression(ImmutableList.of(new Field("a", STRING_EXPRESSION))));
// When:
final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
// Then:
assertThat(e.getMessage(), startsWith("operator does not exist: STRUCT<`a` INTEGER> = STRUCT<`a` STRING> (STRUCT(a:=STR))"));
}
use of io.confluent.ksql.execution.expression.tree.CreateStructExpression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteStructExpression.
@Test
public void shouldRewriteStructExpression() {
// Given:
final CreateStructExpression parsed = parseExpression("STRUCT(FOO := 'foo', BAR := col4[1])");
final Expression fooVal = parsed.getFields().stream().filter(f -> f.getName().equals("FOO")).findFirst().get().getValue();
final Expression barVal = parsed.getFields().stream().filter(f -> f.getName().equals("BAR")).findFirst().get().getValue();
when(processor.apply(fooVal, context)).thenReturn(expr1);
when(processor.apply(barVal, context)).thenReturn(expr2);
// When:
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new CreateStructExpression(ImmutableList.of(new Field("FOO", expr1), new Field("BAR", expr2)))));
}
use of io.confluent.ksql.execution.expression.tree.CreateStructExpression in project ksql by confluentinc.
the class GenericExpressionResolverTest method shouldResolveArbitraryExpressions.
@Test
public void shouldResolveArbitraryExpressions() {
// Given:
final SqlType type = SqlTypes.struct().field("FOO", SqlTypes.STRING).build();
final Expression exp = new CreateStructExpression(ImmutableList.of(new Field("FOO", new FunctionCall(FunctionName.of("CONCAT"), ImmutableList.of(new StringLiteral("bar"), new StringLiteral("baz"))))));
// When:
final Object o = new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp);
// Then:
assertThat(o, is(new Struct(SchemaBuilder.struct().field("FOO", Schema.OPTIONAL_STRING_SCHEMA).optional().build()).put("FOO", "barbaz")));
}
use of io.confluent.ksql.execution.expression.tree.CreateStructExpression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateStructDereference.
@Test
public void shouldEvaluateStructDereference() {
// Given:
final Expression expression1 = new DereferenceExpression(Optional.empty(), new CreateStructExpression(ImmutableList.of(new Field("A", new IntegerLiteral(10)), new Field("B", new StringLiteral("abc")))), "A");
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
// Then:
assertThat(interpreter1.evaluate(ROW), is(10));
}
Aggregations