use of io.confluent.ksql.topic.SourceTopicsExtractor in project ksql by confluentinc.
the class KsqlAuthorizationValidatorImpl method getCreateAsSelectSinkTopic.
private KsqlTopic getCreateAsSelectSinkTopic(final MetaStore metaStore, final CreateAsSelect createAsSelect) {
final CreateSourceAsProperties properties = createAsSelect.getProperties();
final String sinkTopicName;
final KeyFormat sinkKeyFormat;
final ValueFormat sinkValueFormat;
if (!properties.getKafkaTopic().isPresent()) {
final DataSource dataSource = metaStore.getSource(createAsSelect.getName());
if (dataSource != null) {
sinkTopicName = dataSource.getKafkaTopicName();
sinkKeyFormat = dataSource.getKsqlTopic().getKeyFormat();
sinkValueFormat = dataSource.getKsqlTopic().getValueFormat();
} else {
throw new KsqlException("Cannot validate for topic access from an unknown stream/table: " + createAsSelect.getName());
}
} else {
sinkTopicName = properties.getKafkaTopic().get();
// If no format is specified for the sink topic, then use the format from the primary
// source topic.
final SourceTopicsExtractor extractor = new SourceTopicsExtractor(metaStore);
extractor.process(createAsSelect.getQuery(), null);
final KsqlTopic primaryKsqlTopic = extractor.getPrimarySourceTopic();
final Optional<Format> keyFormat = properties.getKeyFormat().map(formatName -> FormatFactory.fromName(formatName));
final Optional<Format> valueFormat = properties.getValueFormat().map(formatName -> FormatFactory.fromName(formatName));
sinkKeyFormat = keyFormat.map(format -> KeyFormat.of(FormatInfo.of(format.name()), format.supportsFeature(SerdeFeature.SCHEMA_INFERENCE) ? SerdeFeatures.of(SerdeFeature.SCHEMA_INFERENCE) : SerdeFeatures.of(), Optional.empty())).orElse(primaryKsqlTopic.getKeyFormat());
sinkValueFormat = valueFormat.map(format -> ValueFormat.of(FormatInfo.of(format.name()), format.supportsFeature(SerdeFeature.SCHEMA_INFERENCE) ? SerdeFeatures.of(SerdeFeature.SCHEMA_INFERENCE) : SerdeFeatures.of())).orElse(primaryKsqlTopic.getValueFormat());
}
return new KsqlTopic(sinkTopicName, sinkKeyFormat, sinkValueFormat);
}
use of io.confluent.ksql.topic.SourceTopicsExtractor in project ksql by confluentinc.
the class KsqlAuthorizationValidatorImpl method extractQueryTopics.
private Set<KsqlTopic> extractQueryTopics(final Query query, final MetaStore metaStore) {
final SourceTopicsExtractor extractor = new SourceTopicsExtractor(metaStore);
extractor.process(query, null);
return extractor.getSourceTopics();
}
Aggregations