use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class AstSanitizerTest method shouldAllowNestedLambdaFunctionsWithoutDuplicate.
@Test
public void shouldAllowNestedLambdaFunctionsWithoutDuplicate() {
// Given:
final Statement stmt = givenQuery("SELECT TRANSFORM_ARRAY(Col4, (X,Y,Z) => TRANSFORM_MAP(Col4, Q => 4, H => 5), (X,Y,Z) => 0) FROM TEST1;");
// When:
final Query result = (Query) AstSanitizer.sanitize(stmt, META_STORE, true);
// Then:
assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column(TEST1_NAME, "COL4"), new LambdaFunctionCall(ImmutableList.of("X", "Y", "Z"), new FunctionCall(FunctionName.of("TRANSFORM_MAP"), ImmutableList.of(column(TEST1_NAME, "COL4"), new LambdaFunctionCall(ImmutableList.of("Q"), new IntegerLiteral(4)), new LambdaFunctionCall(ImmutableList.of("H"), new IntegerLiteral(5))))), new LambdaFunctionCall(ImmutableList.of("X", "Y", "Z"), new IntegerLiteral(0)))), Optional.of(ColumnName.of("KSQL_COL_0")))))));
}
use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class SchemaKGroupedTable method aggregate.
@Override
public SchemaKTable<GenericKey> aggregate(final List<ColumnName> nonAggregateColumns, final List<FunctionCall> aggregations, final Optional<WindowExpression> windowExpression, final FormatInfo valueFormat, final Stacker contextStacker) {
if (windowExpression.isPresent()) {
throw new KsqlException("Windowing not supported for table aggregations.");
}
final List<String> unsupportedFunctionNames = aggregations.stream().map(call -> UdafUtil.resolveAggregateFunction(functionRegistry, call, schema, ksqlConfig)).filter(function -> !(function instanceof TableAggregationFunction)).map(KsqlAggregateFunction::name).map(FunctionName::text).distinct().collect(Collectors.toList());
if (!unsupportedFunctionNames.isEmpty()) {
final String postfix = unsupportedFunctionNames.size() == 1 ? "" : "s";
throw new KsqlException("The aggregation function" + postfix + " " + GrammaticalJoiner.and().join(unsupportedFunctionNames) + " cannot be applied to a table source, only to a stream source.");
}
final TableAggregate step = ExecutionStepFactory.tableAggregate(contextStacker, sourceTableStep, InternalFormats.of(keyFormat, valueFormat), nonAggregateColumns, aggregations);
return new SchemaKTable<>(step, resolveSchema(step), keyFormat, ksqlConfig, functionRegistry);
}
use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class AggregateAnalyzerTest method shouldNotThrowOnNonAggregateFunctionIfAllParamsAreInGroupBy.
@Test
public void shouldNotThrowOnNonAggregateFunctionIfAllParamsAreInGroupBy() {
// Given:
final Expression someExpression = mock(Expression.class);
givenSelectExpression(new FunctionCall(FunctionName.of("UCASE"), ImmutableList.of(GROUP_BY_1, someExpression)));
// When:
analyzer.analyze(analysis, selects);
// Then: did not throw.
}
use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class AggregateAnalyzerTest method shouldThrowOnNonExistentFunctionCall.
@Test
public void shouldThrowOnNonExistentFunctionCall() {
// Given:
givenSelectExpression(new FunctionCall(FunctionName.of("NOT_FOUND"), ImmutableList.of(COL2)));
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> analyzer.analyze(analysis, selects));
// Then:
assertThat(e.getMessage(), containsString("Can't find any functions with the name 'NOT_FOUND'"));
}
use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.
the class AggregateAnalyzerTest method shouldAddDefaultArgToFunctionCallWithNoArgs.
@Test
public void shouldAddDefaultArgToFunctionCallWithNoArgs() {
// Given:
final FunctionCall emptyFunc = new FunctionCall(FunctionName.of("COUNT"), new ArrayList<>());
givenSelectExpression(emptyFunc);
// When:
final AggregateAnalysisResult result = analyzer.analyze(analysis, selects);
// Then:
assertThat(result.getAggregateFunctions(), hasSize(2));
assertThat(result.getAggregateFunctions().get(1).getName(), is(emptyFunc.getName()));
assertThat(result.getAggregateFunctions().get(1).getArguments(), contains(DEFAULT_ARGUMENT));
}
Aggregations