Search in sources :

Example 21 with SourceName

use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.

the class JoinNode method ensureMatchingPartitionCounts.

private void ensureMatchingPartitionCounts(final KafkaTopicClient kafkaTopicClient) {
    final int leftPartitions = left.getPartitions(kafkaTopicClient);
    final int rightPartitions = right.getPartitions(kafkaTopicClient);
    if (leftPartitions == rightPartitions) {
        return;
    }
    final SourceName leftSource = getSourceName(left);
    final SourceName rightSource = getSourceName(right);
    throw new KsqlException("Can't join " + leftSource + " with " + rightSource + " since the number of partitions don't " + "match. " + leftSource + " partitions = " + leftPartitions + "; " + rightSource + " partitions = " + rightPartitions + ". Please repartition either one so that the " + "number of partitions match.");
}
Also used : SourceName(io.confluent.ksql.name.SourceName) KsqlException(io.confluent.ksql.util.KsqlException)

Example 22 with SourceName

use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.

the class PullQueryExecutionUtil method findMaterializingQuery.

static PersistentQueryMetadata findMaterializingQuery(final EngineContext engineContext, final ImmutableAnalysis analysis) {
    final DataSource source = analysis.getFrom().getDataSource();
    final SourceName sourceName = source.getName();
    final Set<QueryId> queries = engineContext.getQueryRegistry().getQueriesWithSink(sourceName);
    if (source.getDataSourceType() != DataSourceType.KTABLE) {
        throw new KsqlException("Unexpected data source type for table pull query: " + source.getDataSourceType() + " " + PullQueryValidator.PULL_QUERY_SYNTAX_HELP);
    }
    if (queries.isEmpty()) {
        throw notMaterializedException(sourceName);
    }
    if (queries.size() > 1) {
        throw new IllegalStateException("Tables do not support multiple queries writing into them, yet somehow this happened. " + "Source Name: " + sourceName + " Queries: " + queries + ". Please submit " + "a GitHub issue with the queries that were run.");
    }
    final QueryId queryId = Iterables.getOnlyElement(queries);
    return engineContext.getQueryRegistry().getPersistentQuery(queryId).orElseThrow(() -> new KsqlException("Materializing query has been stopped"));
}
Also used : QueryId(io.confluent.ksql.query.QueryId) SourceName(io.confluent.ksql.name.SourceName) KsqlException(io.confluent.ksql.util.KsqlException) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 23 with SourceName

use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.

the class SourceSchemas method sourcesWithField.

/**
 * Find the name of any sources containing the supplied {@code target}.
 *
 * <p>The supplied name can be prefixed with a source name. In which case, only that specific
 * source is checked. If not prefix is present, all sources are checked.
 *
 * @param target the field name to search for. Can be prefixed by source name.
 * @return the set of source names or aliases which contain the supplied {@code target}.
 */
public Set<SourceName> sourcesWithField(final Optional<SourceName> source, final ColumnName target) {
    if (!source.isPresent()) {
        return sourceSchemas.entrySet().stream().filter(e -> e.getValue().findColumn(target).isPresent()).map(Entry::getKey).collect(Collectors.toSet());
    }
    final SourceName sourceName = source.get();
    final LogicalSchema sourceSchema = sourceSchemas.get(sourceName);
    if (sourceSchema == null) {
        return ImmutableSet.of();
    }
    return sourceSchema.findColumn(target).isPresent() ? ImmutableSet.of(sourceName) : ImmutableSet.of();
}
Also used : SourceName(io.confluent.ksql.name.SourceName) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Example 24 with SourceName

use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.

the class TopicDeleteInjectorTest method shouldThrowExceptionIfOtherSourcesUsingTopic.

@Test
public void shouldThrowExceptionIfOtherSourcesUsingTopic() {
    // Given:
    final ConfiguredStatement<DropStream> dropStatement = givenStatement("DROP SOMETHING DELETE TOPIC;", new DropStream(SOURCE_NAME, true, true));
    final DataSource other1 = givenSource(SourceName.of("OTHER1"), TOPIC_NAME);
    final DataSource other2 = givenSource(SourceName.of("OTHER2"), TOPIC_NAME);
    final Map<SourceName, DataSource> sources = new HashMap<>();
    sources.put(SOURCE_NAME, source);
    sources.put(SourceName.of("OTHER1"), other1);
    sources.put(SourceName.of("OTHER2"), other2);
    when(metaStore.getAllDataSources()).thenReturn(sources);
    // When:
    final Exception e = assertThrows(RuntimeException.class, () -> deleteInjector.inject(dropStatement));
    // Then:
    assertThat(e.getMessage(), containsString("Refusing to delete topic. " + "Found other data sources (OTHER1, OTHER2) using topic something"));
}
Also used : HashMap(java.util.HashMap) SourceName(io.confluent.ksql.name.SourceName) DropStream(io.confluent.ksql.parser.tree.DropStream) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) IOException(java.io.IOException) KsqlException(io.confluent.ksql.util.KsqlException) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 25 with SourceName

use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.

the class TopicDeleteInjectorTest method shouldNotThrowIfNoOtherSourcesUsingTopic.

@Test
public void shouldNotThrowIfNoOtherSourcesUsingTopic() {
    // Given:
    final ConfiguredStatement<DropStream> dropStatement = givenStatement("DROP SOMETHING DELETE TOPIC;", new DropStream(SOURCE_NAME, true, true));
    final DataSource other1 = givenSource(SourceName.of("OTHER"), "other");
    final Map<SourceName, DataSource> sources = new HashMap<>();
    sources.put(SOURCE_NAME, source);
    sources.put(SourceName.of("OTHER"), other1);
    when(metaStore.getAllDataSources()).thenReturn(sources);
    // When:
    deleteInjector.inject(dropStatement);
}
Also used : HashMap(java.util.HashMap) SourceName(io.confluent.ksql.name.SourceName) DropStream(io.confluent.ksql.parser.tree.DropStream) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Aggregations

SourceName (io.confluent.ksql.name.SourceName)34 DataSource (io.confluent.ksql.metastore.model.DataSource)21 KsqlException (io.confluent.ksql.util.KsqlException)21 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)11 Collectors (java.util.stream.Collectors)8 Optional (java.util.Optional)7 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)6 Collections (java.util.Collections)6 List (java.util.List)6 Set (java.util.Set)6 QualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp)5 DataSourceType (io.confluent.ksql.metastore.model.DataSource.DataSourceType)5 ColumnName (io.confluent.ksql.name.ColumnName)5 Column (io.confluent.ksql.schema.ksql.Column)5 ImmutableList (com.google.common.collect.ImmutableList)4 Iterables (com.google.common.collect.Iterables)4 ExpressionTreeRewriter (io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter)4 Context (io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter.Context)4 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)4 Expression (io.confluent.ksql.execution.expression.tree.Expression)4