Search in sources :

Example 26 with SourceName

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);
}
Also used : SourceName(io.confluent.ksql.name.SourceName) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 27 with SourceName

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

Example 28 with SourceName

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));
}
Also used : SourceName(io.confluent.ksql.name.SourceName) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 29 with SourceName

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;
}
Also used : Table(io.confluent.ksql.parser.tree.Table) SourceName(io.confluent.ksql.name.SourceName) KsqlException(io.confluent.ksql.util.KsqlException) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 30 with SourceName

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);
}
Also used : Closer(com.google.common.io.Closer) SourceName(io.confluent.ksql.name.SourceName) KsqlException(io.confluent.ksql.util.KsqlException) DropStatement(io.confluent.ksql.parser.tree.DropStatement) KsqlException(io.confluent.ksql.util.KsqlException) DataSource(io.confluent.ksql.metastore.model.DataSource)

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