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