use of io.confluent.ksql.parser.tree.CreateStream 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);
}
Aggregations