use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateLambdaArgsToType.
@Test
public void shouldEvaluateLambdaArgsToType() {
// Given:
givenUdfWithNameAndReturnType("TRANSFORM", SqlTypes.STRING);
when(function.parameters()).thenReturn(ImmutableList.of(ArrayType.of(DoubleType.INSTANCE), StringType.INSTANCE, LambdaType.of(ImmutableList.of(DoubleType.INSTANCE, StringType.INSTANCE), StringType.INSTANCE)));
final Expression expression = new FunctionCall(FunctionName.of("TRANSFORM"), ImmutableList.of(ARRAYCOL, new StringLiteral("Q"), new LambdaFunctionCall(ImmutableList.of("A", "B"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("A"), new LambdaVariable("B")))));
// When:
final Exception e = assertThrows(Exception.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), Matchers.containsString("Unsupported arithmetic types. DOUBLE STRING"));
}
use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldHandleNestedLambdas.
@Test
public void shouldHandleNestedLambdas() {
// Given:
givenUdfWithNameAndReturnType("TRANSFORM", SqlTypes.INTEGER);
when(function.parameters()).thenReturn(ImmutableList.of(ArrayType.of(LongType.INSTANCE), IntegerType.INSTANCE, LambdaType.of(ImmutableList.of(DoubleType.INSTANCE, DoubleType.INSTANCE), StringType.INSTANCE), LambdaType.of(ImmutableList.of(DoubleType.INSTANCE, DoubleType.INSTANCE), StringType.INSTANCE)));
final Expression expression = new ArithmeticBinaryExpression(Operator.ADD, new FunctionCall(FunctionName.of("TRANSFORM"), ImmutableList.of(ARRAYCOL, new IntegerLiteral(0), new LambdaFunctionCall(ImmutableList.of("A", "B"), new ArithmeticBinaryExpression(Operator.ADD, new FunctionCall(FunctionName.of("TRANSFORM"), ImmutableList.of(ARRAYCOL, new IntegerLiteral(0), new LambdaFunctionCall(ImmutableList.of("Q", "V"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("Q"), new LambdaVariable("V"))))), new LambdaVariable("B"))))), new IntegerLiteral(5));
// When:
final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
assertThat(result, is(SqlTypes.INTEGER));
}
use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteFunctionCall.
@Test
public void shouldRewriteFunctionCall() {
// Given:
final FunctionCall parsed = parseExpression("STRLEN('foo')");
when(processor.apply(parsed.getArguments().get(0), context)).thenReturn(expr1);
// When:
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new FunctionCall(parsed.getLocation(), parsed.getName(), ImmutableList.of(expr1))));
}
use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldBuildExpression.
@Test
public void shouldBuildExpression() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).build();
final List<ColumnName> names = ImmutableList.of(KEY, COL0);
final Expression exp = new FunctionCall(FunctionName.of("CONCAT"), ImmutableList.of(new StringLiteral("a"), new StringLiteral("b")));
// When:
final KsqlGenericRecord record = recordFactory.build(names, ImmutableList.of(exp, exp), schema, DataSourceType.KSTREAM);
// Then:
assertThat(record, is(KsqlGenericRecord.of(GenericKey.genericKey("ab"), GenericRow.genericRow("ab"), 0)));
}
use of io.confluent.ksql.execution.expression.tree.FunctionCall 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")));
}
Aggregations