Search in sources :

Example 1 with KsqlAggregateFunction

use of io.confluent.ksql.function.KsqlAggregateFunction in project ksql by confluentinc.

the class IntegerSumKudafTest method getIntegerSumKudaf.

private IntegerSumKudaf getIntegerSumKudaf() {
    KsqlAggregateFunction aggregateFunction = new SumAggFunctionFactory().getProperAggregateFunction(Collections.singletonList(Schema.INT32_SCHEMA));
    assertThat(aggregateFunction, instanceOf(IntegerSumKudaf.class));
    return (IntegerSumKudaf) aggregateFunction;
}
Also used : KsqlAggregateFunction(io.confluent.ksql.function.KsqlAggregateFunction)

Example 2 with KsqlAggregateFunction

use of io.confluent.ksql.function.KsqlAggregateFunction in project ksql by confluentinc.

the class IntegerMaxKudafTest method getIntegerMaxKudaf.

private IntegerMaxKudaf getIntegerMaxKudaf() {
    KsqlAggregateFunction aggregateFunction = new MaxAggFunctionFactory().getProperAggregateFunction(Collections.singletonList(Schema.INT32_SCHEMA));
    assertThat(aggregateFunction, instanceOf(IntegerMaxKudaf.class));
    return (IntegerMaxKudaf) aggregateFunction;
}
Also used : KsqlAggregateFunction(io.confluent.ksql.function.KsqlAggregateFunction)

Example 3 with KsqlAggregateFunction

use of io.confluent.ksql.function.KsqlAggregateFunction in project ksql by confluentinc.

the class IntegerMinKudafTest method getIntegerMinKudaf.

private IntegerMinKudaf getIntegerMinKudaf() {
    KsqlAggregateFunction aggregateFunction = new MinAggFunctionFactory().getProperAggregateFunction(Collections.singletonList(Schema.INT32_SCHEMA));
    assertThat(aggregateFunction, instanceOf(IntegerMinKudaf.class));
    return (IntegerMinKudaf) aggregateFunction;
}
Also used : KsqlAggregateFunction(io.confluent.ksql.function.KsqlAggregateFunction)

Example 4 with KsqlAggregateFunction

use of io.confluent.ksql.function.KsqlAggregateFunction in project ksql by confluentinc.

the class AggregateNode method buildAggregateSchema.

private Schema buildAggregateSchema(final Schema schema, final FunctionRegistry functionRegistry) {
    final SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    final List<Field> fields = schema.fields();
    for (int i = 0; i < getRequiredColumnList().size(); i++) {
        schemaBuilder.field(fields.get(i).name(), fields.get(i).schema());
    }
    for (int aggFunctionVarSuffix = 0; aggFunctionVarSuffix < getFunctionList().size(); aggFunctionVarSuffix++) {
        String udafName = getFunctionList().get(aggFunctionVarSuffix).getName().getSuffix();
        KsqlAggregateFunction aggregateFunction = functionRegistry.getAggregateFunction(udafName, getFunctionList().get(aggFunctionVarSuffix).getArguments(), schema);
        schemaBuilder.field(AggregateExpressionRewriter.AGGREGATE_FUNCTION_VARIABLE_PREFIX + aggFunctionVarSuffix, aggregateFunction.getReturnType());
    }
    return schemaBuilder.build();
}
Also used : KsqlAggregateFunction(io.confluent.ksql.function.KsqlAggregateFunction) Field(org.apache.kafka.connect.data.Field) SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder)

Example 5 with KsqlAggregateFunction

use of io.confluent.ksql.function.KsqlAggregateFunction in project ksql by confluentinc.

the class AggregateNode method createAggValToFunctionMap.

private Map<Integer, KsqlAggregateFunction> createAggValToFunctionMap(final Map<String, Integer> expressionNames, final SchemaKStream aggregateArgExpanded, final SchemaBuilder aggregateSchema, final KudafInitializer initializer, final int initialUdafIndex, final FunctionRegistry functionRegistry) {
    try {
        int udafIndexInAggSchema = initialUdafIndex;
        final Map<Integer, KsqlAggregateFunction> aggValToAggFunctionMap = new HashMap<>();
        for (FunctionCall functionCall : getFunctionList()) {
            KsqlAggregateFunction aggregateFunctionInfo = functionRegistry.getAggregateFunction(functionCall.getName().toString(), functionCall.getArguments(), aggregateArgExpanded.getSchema());
            KsqlAggregateFunction aggregateFunction = aggregateFunctionInfo.getInstance(expressionNames, functionCall.getArguments());
            aggValToAggFunctionMap.put(udafIndexInAggSchema++, aggregateFunction);
            initializer.addAggregateIntializer(aggregateFunction.getInitialValueSupplier());
            aggregateSchema.field("AGG_COL_" + udafIndexInAggSchema, aggregateFunction.getReturnType());
        }
        return aggValToAggFunctionMap;
    } catch (final Exception e) {
        throw new KsqlException(String.format("Failed to create aggregate val to function map. expressionNames:%s", expressionNames), e);
    }
}
Also used : KsqlAggregateFunction(io.confluent.ksql.function.KsqlAggregateFunction) HashMap(java.util.HashMap) FunctionCall(io.confluent.ksql.parser.tree.FunctionCall) KsqlException(io.confluent.ksql.util.KsqlException) KsqlException(io.confluent.ksql.util.KsqlException)

Aggregations

KsqlAggregateFunction (io.confluent.ksql.function.KsqlAggregateFunction)5 FunctionCall (io.confluent.ksql.parser.tree.FunctionCall)1 KsqlException (io.confluent.ksql.util.KsqlException)1 HashMap (java.util.HashMap)1 Field (org.apache.kafka.connect.data.Field)1 SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)1