Search in sources :

Example 1 with SourceTopicsExtractor

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);
}
Also used : ValueFormat(io.confluent.ksql.serde.ValueFormat) KeyFormat(io.confluent.ksql.serde.KeyFormat) ValueFormat(io.confluent.ksql.serde.ValueFormat) Format(io.confluent.ksql.serde.Format) CreateSourceAsProperties(io.confluent.ksql.parser.properties.with.CreateSourceAsProperties) SourceTopicsExtractor(io.confluent.ksql.topic.SourceTopicsExtractor) KeyFormat(io.confluent.ksql.serde.KeyFormat) KsqlException(io.confluent.ksql.util.KsqlException) DataSource(io.confluent.ksql.metastore.model.DataSource) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic)

Example 2 with SourceTopicsExtractor

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();
}
Also used : SourceTopicsExtractor(io.confluent.ksql.topic.SourceTopicsExtractor)

Aggregations

SourceTopicsExtractor (io.confluent.ksql.topic.SourceTopicsExtractor)2 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 DataSource (io.confluent.ksql.metastore.model.DataSource)1 CreateSourceAsProperties (io.confluent.ksql.parser.properties.with.CreateSourceAsProperties)1 Format (io.confluent.ksql.serde.Format)1 KeyFormat (io.confluent.ksql.serde.KeyFormat)1 ValueFormat (io.confluent.ksql.serde.ValueFormat)1 KsqlException (io.confluent.ksql.util.KsqlException)1