Search in sources :

Example 26 with Expression

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

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

the class AstBuilder method visitLambda.

@Override
public Node visitLambda(SqlBaseParser.LambdaContext context) {
    List<String> arguments = context.identifier().stream().map(AstBuilder::getIdentifierText).collect(toList());
    Expression body = (Expression) visit(context.expression());
    return new LambdaExpression(arguments, body);
}
Also used : 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) LambdaExpression(io.confluent.ksql.parser.tree.LambdaExpression)

Example 28 with Expression

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

the class KsqlEngine method addInto.

public Query addInto(final Query query, final QuerySpecification querySpecification, final String intoName, final Map<String, Expression> intoProperties, final Optional<Expression> partitionByExpression) {
    Table intoTable = new Table(QualifiedName.of(intoName));
    if (partitionByExpression.isPresent()) {
        Map<String, Expression> newIntoProperties = new HashMap<>();
        newIntoProperties.putAll(intoProperties);
        newIntoProperties.put(DdlConfig.PARTITION_BY_PROPERTY, partitionByExpression.get());
        intoTable.setProperties(newIntoProperties);
    } else {
        intoTable.setProperties(intoProperties);
    }
    QuerySpecification newQuerySpecification = new QuerySpecification(querySpecification.getSelect(), intoTable, querySpecification.getFrom(), querySpecification.getWindowExpression(), querySpecification.getWhere(), querySpecification.getGroupBy(), querySpecification.getHaving(), querySpecification.getLimit());
    return new Query(newQuerySpecification, query.getLimit());
}
Also used : QuerySpecification(io.confluent.ksql.parser.tree.QuerySpecification) CreateTable(io.confluent.ksql.parser.tree.CreateTable) DropTable(io.confluent.ksql.parser.tree.DropTable) Table(io.confluent.ksql.parser.tree.Table) Query(io.confluent.ksql.parser.tree.Query) Expression(io.confluent.ksql.parser.tree.Expression) HashMap(java.util.HashMap)

Example 29 with Expression

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

the class QueryEngine method maybeAddFieldsFromSchemaRegistry.

private Pair<DdlStatement, String> maybeAddFieldsFromSchemaRegistry(AbstractStreamCreateStatement streamCreateStatement) {
    if (streamCreateStatement.getProperties().containsKey(DdlConfig.TOPIC_NAME_PROPERTY)) {
        String ksqlRegisteredTopicName = StringUtil.cleanQuotes(streamCreateStatement.getProperties().get(DdlConfig.TOPIC_NAME_PROPERTY).toString().toUpperCase());
        KsqlTopic ksqlTopic = ksqlEngine.getMetaStore().getTopic(ksqlRegisteredTopicName);
        if (ksqlTopic == null) {
            throw new KsqlException(String.format("Could not find %s topic in the metastore.", ksqlRegisteredTopicName));
        }
        Map<String, Expression> newProperties = new HashMap<>();
        newProperties.put(DdlConfig.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral(ksqlTopic.getKafkaTopicName()));
        newProperties.put(DdlConfig.VALUE_FORMAT_PROPERTY, new StringLiteral(ksqlTopic.getKsqlTopicSerDe().getSerDe().toString()));
        streamCreateStatement = streamCreateStatement.copyWith(streamCreateStatement.getElements(), newProperties);
    }
    Pair<AbstractStreamCreateStatement, String> avroCheckResult = new AvroUtil().checkAndSetAvroSchema(streamCreateStatement, new HashMap<>(), ksqlEngine.getSchemaRegistryClient());
    if (avroCheckResult.getRight() != null) {
        if (avroCheckResult.getLeft() instanceof CreateStream) {
            return new Pair<>((CreateStream) avroCheckResult.getLeft(), avroCheckResult.getRight());
        } else if (avroCheckResult.getLeft() instanceof CreateTable) {
            return new Pair<>((CreateTable) avroCheckResult.getLeft(), avroCheckResult.getRight());
        }
    }
    return new Pair<>(null, null);
}
Also used : HashMap(java.util.HashMap) CreateTable(io.confluent.ksql.parser.tree.CreateTable) CreateStream(io.confluent.ksql.parser.tree.CreateStream) AbstractStreamCreateStatement(io.confluent.ksql.parser.tree.AbstractStreamCreateStatement) KsqlException(io.confluent.ksql.util.KsqlException) AvroUtil(io.confluent.ksql.util.AvroUtil) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) Expression(io.confluent.ksql.parser.tree.Expression) KsqlTopic(io.confluent.ksql.metastore.KsqlTopic) Pair(io.confluent.ksql.util.Pair)

Example 30 with Expression

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

the class Analyzer method analyzeExpressions.

private void analyzeExpressions() {
    Schema schema = analysis.getFromDataSources().get(0).getLeft().getSchema();
    boolean isJoinSchema = false;
    if (analysis.getJoin() != null) {
        schema = analysis.getJoin().getSchema();
        isJoinSchema = true;
    }
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(schema, isJoinSchema);
    for (Expression selectExpression : analysis.getSelectExpressions()) {
        expressionAnalyzer.analyzeExpression(selectExpression);
    }
    if (analysis.getWhereExpression() != null) {
        expressionAnalyzer.analyzeExpression(analysis.getWhereExpression());
    }
    if (!analysis.getGroupByExpressions().isEmpty()) {
        for (Expression expression : analysis.getGroupByExpressions()) {
            expressionAnalyzer.analyzeExpression(expression);
        }
    }
    if (analysis.getHavingExpression() != null) {
        expressionAnalyzer.analyzeExpression(analysis.getHavingExpression());
    }
}
Also used : ComparisonExpression(io.confluent.ksql.parser.tree.ComparisonExpression) DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) Expression(io.confluent.ksql.parser.tree.Expression) Schema(org.apache.kafka.connect.data.Schema)

Aggregations

Expression (io.confluent.ksql.parser.tree.Expression)36 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)17 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)13 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)10 HashMap (java.util.HashMap)10 ArithmeticBinaryExpression (io.confluent.ksql.parser.tree.ArithmeticBinaryExpression)8 ArithmeticUnaryExpression (io.confluent.ksql.parser.tree.ArithmeticUnaryExpression)8 InListExpression (io.confluent.ksql.parser.tree.InListExpression)8 LogicalBinaryExpression (io.confluent.ksql.parser.tree.LogicalBinaryExpression)8 NotExpression (io.confluent.ksql.parser.tree.NotExpression)8 NullIfExpression (io.confluent.ksql.parser.tree.NullIfExpression)8 QualifiedNameReference (io.confluent.ksql.parser.tree.QualifiedNameReference)8 SearchedCaseExpression (io.confluent.ksql.parser.tree.SearchedCaseExpression)8 SimpleCaseExpression (io.confluent.ksql.parser.tree.SimpleCaseExpression)8 StringLiteral (io.confluent.ksql.parser.tree.StringLiteral)8 SubqueryExpression (io.confluent.ksql.parser.tree.SubqueryExpression)8 SubscriptExpression (io.confluent.ksql.parser.tree.SubscriptExpression)8 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)7