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;
}
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;
}
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;
}
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();
}
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);
}
}
Aggregations