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