use of io.confluent.ksql.parser.tree.FunctionCall in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatFunctionCallWithWindow.
@Test
public void shouldFormatFunctionCallWithWindow() {
final FunctionCall functionCall = new FunctionCall(new NodeLocation(1, 1), QualifiedName.of("function"), Optional.of(new Window("window", new WindowExpression("blah", new TumblingWindowExpression(1L, TimeUnit.SECONDS)))), false, Collections.singletonList(new StringLiteral("name")));
assertThat(ExpressionFormatter.formatExpression(functionCall), equalTo("function('name') OVER WINDOW WINDOW blah TUMBLING ( SIZE 1 SECONDS ) "));
}
use of io.confluent.ksql.parser.tree.FunctionCall in project ksql by confluentinc.
the class AstBuilder method visitNormalize.
@Override
public Node visitNormalize(SqlBaseParser.NormalizeContext context) {
Expression str = (Expression) visit(context.valueExpression());
String normalForm = Optional.ofNullable(context.normalForm()).map(ParserRuleContext::getText).orElse("NFC");
return new FunctionCall(getLocation(context), QualifiedName.of("NORMALIZE"), ImmutableList.of(str, new StringLiteral(getLocation(context), normalForm)));
}
use of io.confluent.ksql.parser.tree.FunctionCall 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