Search in sources :

Example 6 with FunctionCall

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 ) "));
}
Also used : Window(io.confluent.ksql.parser.tree.Window) NodeLocation(io.confluent.ksql.parser.tree.NodeLocation) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression) HoppingWindowExpression(io.confluent.ksql.parser.tree.HoppingWindowExpression) FunctionCall(io.confluent.ksql.parser.tree.FunctionCall) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression) Test(org.junit.Test)

Example 7 with FunctionCall

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)));
}
Also used : StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) InListExpression(io.confluent.ksql.parser.tree.InListExpression) NullIfExpression(io.confluent.ksql.parser.tree.NullIfExpression) SimpleCaseExpression(io.confluent.ksql.parser.tree.SimpleCaseExpression) ComparisonExpression(io.confluent.ksql.parser.tree.ComparisonExpression) DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) Expression(io.confluent.ksql.parser.tree.Expression) LogicalBinaryExpression(io.confluent.ksql.parser.tree.LogicalBinaryExpression) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression) ArithmeticBinaryExpression(io.confluent.ksql.parser.tree.ArithmeticBinaryExpression) NotExpression(io.confluent.ksql.parser.tree.NotExpression) HoppingWindowExpression(io.confluent.ksql.parser.tree.HoppingWindowExpression) SubscriptExpression(io.confluent.ksql.parser.tree.SubscriptExpression) SessionWindowExpression(io.confluent.ksql.parser.tree.SessionWindowExpression) SearchedCaseExpression(io.confluent.ksql.parser.tree.SearchedCaseExpression) LambdaExpression(io.confluent.ksql.parser.tree.LambdaExpression) SubqueryExpression(io.confluent.ksql.parser.tree.SubqueryExpression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) ArithmeticUnaryExpression(io.confluent.ksql.parser.tree.ArithmeticUnaryExpression) FunctionCall(io.confluent.ksql.parser.tree.FunctionCall)

Example 8 with FunctionCall

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

FunctionCall (io.confluent.ksql.parser.tree.FunctionCall)8 StringLiteral (io.confluent.ksql.parser.tree.StringLiteral)4 Test (org.junit.Test)4 Expression (io.confluent.ksql.parser.tree.Expression)3 HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)3 TumblingWindowExpression (io.confluent.ksql.parser.tree.TumblingWindowExpression)3 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)3 ArithmeticBinaryExpression (io.confluent.ksql.parser.tree.ArithmeticBinaryExpression)2 ArithmeticUnaryExpression (io.confluent.ksql.parser.tree.ArithmeticUnaryExpression)2 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)2 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)2 InListExpression (io.confluent.ksql.parser.tree.InListExpression)2 LambdaExpression (io.confluent.ksql.parser.tree.LambdaExpression)2 LogicalBinaryExpression (io.confluent.ksql.parser.tree.LogicalBinaryExpression)2 NodeLocation (io.confluent.ksql.parser.tree.NodeLocation)2 NotExpression (io.confluent.ksql.parser.tree.NotExpression)2 NullIfExpression (io.confluent.ksql.parser.tree.NullIfExpression)2 SearchedCaseExpression (io.confluent.ksql.parser.tree.SearchedCaseExpression)2 SessionWindowExpression (io.confluent.ksql.parser.tree.SessionWindowExpression)2 SimpleCaseExpression (io.confluent.ksql.parser.tree.SimpleCaseExpression)2