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