Search in sources :

Example 1 with QualifiedName

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

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

the class AstBuilder method visitPrintTopic.

@Override
public Node visitPrintTopic(SqlBaseParser.PrintTopicContext context) {
    boolean fromBeginning = context.FROM() != null;
    QualifiedName topicName = null;
    if (context.STRING() != null) {
        topicName = QualifiedName.of(unquote(context.STRING().getText(), "'"));
    } else {
        topicName = getQualifiedName(context.qualifiedName());
    }
    if (context.number() == null) {
        return new PrintTopic(getLocation(context), topicName, fromBeginning, null);
    } else if (context.number() instanceof SqlBaseParser.IntegerLiteralContext) {
        SqlBaseParser.IntegerLiteralContext integerLiteralContext = (SqlBaseParser.IntegerLiteralContext) context.number();
        return new PrintTopic(getLocation(context), topicName, fromBeginning, (LongLiteral) visitIntegerLiteral(integerLiteralContext));
    } else {
        throw new KsqlException("Interval value should be integer in 'PRINT' command!");
    }
}
Also used : LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) QualifiedName(io.confluent.ksql.parser.tree.QualifiedName) PrintTopic(io.confluent.ksql.parser.tree.PrintTopic) KsqlException(io.confluent.ksql.util.KsqlException)

Example 3 with QualifiedName

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

the class AstBuilder method visitDereference.

@Override
public Node visitDereference(SqlBaseParser.DereferenceContext context) {
    String fieldName = getIdentifierText(context.identifier());
    Expression baseExpression;
    QualifiedName tableName = QualifiedName.of(context.primaryExpression().getText().toUpperCase());
    baseExpression = new QualifiedNameReference(getLocation(context.primaryExpression()), tableName);
    DereferenceExpression dereferenceExpression = new DereferenceExpression(getLocation(context), baseExpression, fieldName);
    return dereferenceExpression;
}
Also used : DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) 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) QualifiedNameReference(io.confluent.ksql.parser.tree.QualifiedNameReference)

Aggregations

QualifiedName (io.confluent.ksql.parser.tree.QualifiedName)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 Expression (io.confluent.ksql.parser.tree.Expression)2 HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)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 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 SubqueryExpression (io.confluent.ksql.parser.tree.SubqueryExpression)2 SubscriptExpression (io.confluent.ksql.parser.tree.SubscriptExpression)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