Search in sources :

Example 6 with FunctionName

use of io.confluent.ksql.name.FunctionName 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);
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) GrammaticalJoiner(io.confluent.ksql.util.GrammaticalJoiner) KeyFormat(io.confluent.ksql.serde.KeyFormat) KGroupedTableHolder(io.confluent.ksql.execution.plan.KGroupedTableHolder) KsqlAggregateFunction(io.confluent.ksql.function.KsqlAggregateFunction) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) ExecutionStepFactory(io.confluent.ksql.execution.streams.ExecutionStepFactory) ExecutionStep(io.confluent.ksql.execution.plan.ExecutionStep) FunctionName(io.confluent.ksql.name.FunctionName) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) TableAggregate(io.confluent.ksql.execution.plan.TableAggregate) KsqlConfig(io.confluent.ksql.util.KsqlConfig) InternalFormats(io.confluent.ksql.serde.InternalFormats) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) UdafUtil(io.confluent.ksql.execution.function.UdafUtil) Objects(java.util.Objects) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) List(java.util.List) Stacker(io.confluent.ksql.execution.context.QueryContext.Stacker) TableAggregationFunction(io.confluent.ksql.execution.function.TableAggregationFunction) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) GenericKey(io.confluent.ksql.GenericKey) FormatInfo(io.confluent.ksql.serde.FormatInfo) FunctionName(io.confluent.ksql.name.FunctionName) TableAggregate(io.confluent.ksql.execution.plan.TableAggregate) TableAggregationFunction(io.confluent.ksql.execution.function.TableAggregationFunction) KsqlException(io.confluent.ksql.util.KsqlException)

Aggregations

FunctionName (io.confluent.ksql.name.FunctionName)6 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)3 KsqlConfig (io.confluent.ksql.util.KsqlConfig)3 KsqlException (io.confluent.ksql.util.KsqlException)3 List (java.util.List)3 Objects (java.util.Objects)3 Expression (io.confluent.ksql.execution.expression.tree.Expression)2 ParamType (io.confluent.ksql.function.types.ParamType)2 Kudf (io.confluent.ksql.function.udf.Kudf)2 ColumnName (io.confluent.ksql.name.ColumnName)2 Function (java.util.function.Function)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Immutable (com.google.errorprone.annotations.Immutable)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 GenericKey (io.confluent.ksql.GenericKey)1 Stacker (io.confluent.ksql.execution.context.QueryContext.Stacker)1 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)1 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)1 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)1 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)1