use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatFunctionWithDistinct.
@Test
public void shouldFormatFunctionWithDistinct() {
final FunctionCall functionCall = new FunctionCall(FunctionName.of("COUNT"), Collections.singletonList(new StringLiteral("name")));
assertThat(ExpressionFormatter.formatExpression(functionCall), equalTo("COUNT('name')"));
}
use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class AstBuilderTest method shouldBuildNestedLambdaFunction.
@Test
public void shouldBuildNestedLambdaFunction() {
// Given:
final SingleStatementContext stmt = givenQuery("SELECT TRANSFORM_ARRAY(Col4, (X,Y) => TRANSFORM_ARRAY(Col4, X => 5)) FROM TEST1;");
// When:
final Query result = (Query) builder.buildStatement(stmt);
// Then:
assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column("COL4"), new LambdaFunctionCall(ImmutableList.of("X", "Y"), new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column("COL4"), new LambdaFunctionCall(ImmutableList.of("X"), new IntegerLiteral(5))))))), Optional.empty())))));
}
use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class StreamFlatMapBuilder method buildSchema.
public static LogicalSchema buildSchema(final LogicalSchema inputSchema, final List<FunctionCall> tableFunctions, final FunctionRegistry functionRegistry) {
final LogicalSchema.Builder schemaBuilder = LogicalSchema.builder();
final List<Column> cols = inputSchema.value();
// We copy all the original columns to the output schema
schemaBuilder.keyColumns(inputSchema.key());
for (final Column col : cols) {
schemaBuilder.valueColumn(col);
}
final ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(inputSchema, functionRegistry);
// And add new columns representing the exploded values at the end
for (int i = 0; i < tableFunctions.size(); i++) {
final FunctionCall functionCall = tableFunctions.get(i);
final ColumnName colName = ColumnNames.synthesisedSchemaColumn(i);
final SqlType fieldType = expressionTypeManager.getExpressionSqlType(functionCall);
schemaBuilder.valueColumn(colName, fieldType);
}
return schemaBuilder.build();
}
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)));
}
Aggregations