use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.
the class TestExecutorTest method givenDataSourceTopic.
private void givenDataSourceTopic(final LogicalSchema schema) {
final KsqlTopic topic = mock(KsqlTopic.class);
when(topic.getKeyFormat()).thenReturn(KeyFormat.of(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of(), Optional.empty()));
when(topic.getValueFormat()).thenReturn(ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of()));
final SourceName sourceName = SourceName.of(TestExecutorTest.SINK_TOPIC_NAME + "_source");
final DataSource dataSource = mock(DataSource.class);
when(dataSource.getKsqlTopic()).thenReturn(topic);
when(dataSource.getSchema()).thenReturn(schema);
when(dataSource.getKafkaTopicName()).thenReturn(TestExecutorTest.SINK_TOPIC_NAME);
when(dataSource.getName()).thenReturn(sourceName);
when(dataSource.getDataSourceType()).thenReturn(DataSourceType.KSTREAM);
allSources.put(sourceName, dataSource);
}
use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.
the class DefaultFormatInjectorTest method setupCopy.
private static Object setupCopy(final InvocationOnMock inv, final CreateSource source, final CreateSource mock) {
final SourceName name = source.getName();
when(mock.getName()).thenReturn(name);
when(mock.getElements()).thenReturn(inv.getArgument(0));
when(mock.accept(any(), any())).thenCallRealMethod();
when(mock.getProperties()).thenReturn(inv.getArgument(1));
return mock;
}
use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.
the class AssertExecutor method assertSourceMatch.
private static void assertSourceMatch(final KsqlExecutionContext engine, final KsqlConfig config, final CreateSource statement) {
final SourceName source = statement.getName();
final DataSource dataSource = engine.getMetaStore().getSource(source);
MUST_MATCH.forEach(prop -> prop.compare(dataSource, statement, config));
}
use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.
the class SourceTopicsExtractor method visitAliasedRelation.
@Override
protected AstNode visitAliasedRelation(final AliasedRelation node, final Void context) {
final SourceName structuredDataSourceName = ((Table) node.getRelation()).getName();
final DataSource source = metaStore.getSource(structuredDataSourceName);
if (source == null) {
throw new KsqlException(structuredDataSourceName.text() + " does not exist.");
}
// This method is called first with the primary kafka topic (or the node.getFrom() node)
if (primarySourceTopic == null) {
primarySourceTopic = source.getKsqlTopic();
}
sourceTopics.add(source.getKsqlTopic());
return node;
}
use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.
the class TopicDeleteInjector method inject.
@SuppressWarnings({ "unchecked", "UnstableApiUsage" })
@Override
public <T extends Statement> ConfiguredStatement<T> inject(final ConfiguredStatement<T> statement) {
if (!(statement.getStatement() instanceof DropStatement)) {
return statement;
}
final DropStatement dropStatement = (DropStatement) statement.getStatement();
if (!dropStatement.isDeleteTopic()) {
return statement;
}
final SourceName sourceName = dropStatement.getName();
final DataSource source = metastore.getSource(sourceName);
if (source != null) {
if (source.isSource()) {
throw new KsqlException("Cannot delete topic for read-only source: " + sourceName.text());
}
checkTopicRefs(source);
deleteTopic(source);
final Closer closer = Closer.create();
closer.register(() -> deleteKeySubject(source));
closer.register(() -> deleteValueSubject(source));
try {
closer.close();
} catch (final KsqlException e) {
throw e;
} catch (final Exception e) {
throw new KsqlException(e);
}
} else if (!dropStatement.getIfExists()) {
throw new KsqlException("Could not find source to delete topic for: " + statement);
}
final T withoutDelete = (T) dropStatement.withoutDeleteClause();
final String withoutDeleteText = SqlFormatter.formatSql(withoutDelete) + ";";
return statement.withStatement(withoutDeleteText, withoutDelete);
}
Aggregations