Search in sources :

Example 1 with Window

use of io.confluent.ksql.parser.tree.Window in project ksql by confluentinc.

the class AstBuilder method visitFunctionCall.

@Override
public Node visitFunctionCall(SqlBaseParser.FunctionCallContext context) {
    Optional<Window> window = visitIfPresent(context.over(), Window.class);
    QualifiedName name = getQualifiedName(context.qualifiedName());
    boolean distinct = false;
    if (name.toString().equals("NULLIF")) {
        check(context.expression().size() == 2, "Invalid number of arguments for 'nullif' function", context);
        check(!window.isPresent(), "OVER clause not valid for 'nullif' function", context);
        check(!distinct, "DISTINCT not valid for 'nullif' function", context);
        return new NullIfExpression(getLocation(context), (Expression) visit(context.expression(0)), (Expression) visit(context.expression(1)));
    }
    return new FunctionCall(getLocation(context), getQualifiedName(context.qualifiedName()), window, distinct, visit(context.expression(), Expression.class));
}
Also used : Window(io.confluent.ksql.parser.tree.Window) 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) QualifiedName(io.confluent.ksql.parser.tree.QualifiedName) NullIfExpression(io.confluent.ksql.parser.tree.NullIfExpression) FunctionCall(io.confluent.ksql.parser.tree.FunctionCall)

Example 2 with Window

use of io.confluent.ksql.parser.tree.Window 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)

Aggregations

FunctionCall (io.confluent.ksql.parser.tree.FunctionCall)2 HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)2 TumblingWindowExpression (io.confluent.ksql.parser.tree.TumblingWindowExpression)2 Window (io.confluent.ksql.parser.tree.Window)2 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)2 ArithmeticBinaryExpression (io.confluent.ksql.parser.tree.ArithmeticBinaryExpression)1 ArithmeticUnaryExpression (io.confluent.ksql.parser.tree.ArithmeticUnaryExpression)1 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)1 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)1 Expression (io.confluent.ksql.parser.tree.Expression)1 InListExpression (io.confluent.ksql.parser.tree.InListExpression)1 LambdaExpression (io.confluent.ksql.parser.tree.LambdaExpression)1 LogicalBinaryExpression (io.confluent.ksql.parser.tree.LogicalBinaryExpression)1 NodeLocation (io.confluent.ksql.parser.tree.NodeLocation)1 NotExpression (io.confluent.ksql.parser.tree.NotExpression)1 NullIfExpression (io.confluent.ksql.parser.tree.NullIfExpression)1 QualifiedName (io.confluent.ksql.parser.tree.QualifiedName)1 SearchedCaseExpression (io.confluent.ksql.parser.tree.SearchedCaseExpression)1 SessionWindowExpression (io.confluent.ksql.parser.tree.SessionWindowExpression)1 SimpleCaseExpression (io.confluent.ksql.parser.tree.SimpleCaseExpression)1