Search in sources :

Example 1 with TumblingWindowExpression

use of io.confluent.ksql.parser.tree.TumblingWindowExpression 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 2 with TumblingWindowExpression

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

the class AstBuilder method visitWindowExpression.

@Override
public Node visitWindowExpression(SqlBaseParser.WindowExpressionContext ctx) {
    String windowName = DEFAULT_WINDOW_NAME;
    if (ctx.IDENTIFIER() != null) {
        windowName = ctx.IDENTIFIER().getText();
    }
    windowName = windowName.toUpperCase();
    if (ctx.tumblingWindowExpression() != null) {
        TumblingWindowExpression tumblingWindowExpression = (TumblingWindowExpression) visitTumblingWindowExpression(ctx.tumblingWindowExpression());
        return new WindowExpression(windowName, tumblingWindowExpression);
    } else if (ctx.hoppingWindowExpression() != null) {
        HoppingWindowExpression hoppingWindowExpression = (HoppingWindowExpression) visitHoppingWindowExpression(ctx.hoppingWindowExpression());
        return new WindowExpression(windowName, hoppingWindowExpression);
    } else if (ctx.sessionWindowExpression() != null) {
        SessionWindowExpression sessionWindowExpression = (SessionWindowExpression) visitSessionWindowExpression(ctx.sessionWindowExpression());
        return new WindowExpression(windowName, sessionWindowExpression);
    }
    throw new KsqlException("Window description is not correct.");
}
Also used : HoppingWindowExpression(io.confluent.ksql.parser.tree.HoppingWindowExpression) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression) HoppingWindowExpression(io.confluent.ksql.parser.tree.HoppingWindowExpression) SessionWindowExpression(io.confluent.ksql.parser.tree.SessionWindowExpression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) KsqlException(io.confluent.ksql.util.KsqlException) SessionWindowExpression(io.confluent.ksql.parser.tree.SessionWindowExpression) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression)

Aggregations

HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)2 TumblingWindowExpression (io.confluent.ksql.parser.tree.TumblingWindowExpression)2 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)2 FunctionCall (io.confluent.ksql.parser.tree.FunctionCall)1 NodeLocation (io.confluent.ksql.parser.tree.NodeLocation)1 SessionWindowExpression (io.confluent.ksql.parser.tree.SessionWindowExpression)1 StringLiteral (io.confluent.ksql.parser.tree.StringLiteral)1 Window (io.confluent.ksql.parser.tree.Window)1 KsqlException (io.confluent.ksql.util.KsqlException)1 Test (org.junit.Test)1