Search in sources :

Example 31 with SourceName

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

the class DefaultSchemaInjectorTest 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 32 with SourceName

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

the class DistributingExecutor method checkIfNotExistsResponse.

// CHECKSTYLE_RULES.OFF: CyclomaticComplexity
private Optional<StatementExecutorResponse> checkIfNotExistsResponse(final KsqlExecutionContext executionContext, final ConfiguredStatement<?> statement) {
    SourceName sourceName = null;
    String type = "";
    if (statement.getStatement() instanceof CreateStream && ((CreateStream) statement.getStatement()).isNotExists()) {
        type = "stream";
        sourceName = ((CreateStream) statement.getStatement()).getName();
    } else if (statement.getStatement() instanceof CreateTable && ((CreateTable) statement.getStatement()).isNotExists()) {
        type = "table";
        sourceName = ((CreateTable) statement.getStatement()).getName();
    } else if (statement.getStatement() instanceof CreateTableAsSelect && ((CreateTableAsSelect) statement.getStatement()).isNotExists()) {
        type = "table";
        sourceName = ((CreateTableAsSelect) statement.getStatement()).getName();
    } else if (statement.getStatement() instanceof CreateStreamAsSelect && ((CreateStreamAsSelect) statement.getStatement()).isNotExists()) {
        type = "stream";
        sourceName = ((CreateStreamAsSelect) statement.getStatement()).getName();
    }
    if (sourceName != null && executionContext.getMetaStore().getSource(sourceName) != null) {
        return Optional.of(StatementExecutorResponse.handled(Optional.of(new WarningEntity(statement.getStatementText(), String.format("Cannot add %s %s: A %s with the same name already exists.", type, sourceName, type)))));
    } else {
        return Optional.empty();
    }
}
Also used : CreateTableAsSelect(io.confluent.ksql.parser.tree.CreateTableAsSelect) CreateTable(io.confluent.ksql.parser.tree.CreateTable) SourceName(io.confluent.ksql.name.SourceName) CreateStream(io.confluent.ksql.parser.tree.CreateStream) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) WarningEntity(io.confluent.ksql.rest.entity.WarningEntity)

Example 33 with SourceName

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

the class CreateSourceFactoryTest method shouldThrowInCreateStreamOrReplaceOnSourceStreams.

@Test
public void shouldThrowInCreateStreamOrReplaceOnSourceStreams() {
    // Given:
    final SourceName existingStreamName = SourceName.of("existingStreamName");
    final KsqlStream existingStream = mock(KsqlStream.class);
    when(existingStream.getDataSourceType()).thenReturn(DataSourceType.KSTREAM);
    when(existingStream.isSource()).thenReturn(true);
    when(metaStore.getSource(existingStreamName)).thenReturn(existingStream);
    final CreateStream ddlStatement = new CreateStream(existingStreamName, STREAM_ELEMENTS, true, false, withProperties, false);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createStreamCommand(ddlStatement, ksqlConfig));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot add stream 'existingStreamName': CREATE OR REPLACE is not supported on " + "source streams."));
}
Also used : KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) SourceName(io.confluent.ksql.name.SourceName) CreateStream(io.confluent.ksql.parser.tree.CreateStream) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 34 with SourceName

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

the class CreateSourceFactoryTest method shouldThrowInCreateStreamOrReplaceOnSourceTables.

@Test
public void shouldThrowInCreateStreamOrReplaceOnSourceTables() {
    // Given:
    final SourceName existingTableName = SourceName.of("existingTableName");
    final KsqlTable existingTable = mock(KsqlTable.class);
    when(existingTable.getDataSourceType()).thenReturn(DataSourceType.KTABLE);
    when(existingTable.isSource()).thenReturn(true);
    when(metaStore.getSource(existingTableName)).thenReturn(existingTable);
    final CreateTable ddlStatement = new CreateTable(existingTableName, TableElements.of(tableElement("COL1", new Type(BIGINT), PRIMARY_KEY_CONSTRAINT), tableElement("COL2", new Type(SqlTypes.STRING))), true, false, withProperties, false);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createTableCommand(ddlStatement, ksqlConfig));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot add table 'existingTableName': CREATE OR REPLACE is not supported on " + "source tables."));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) CreateTable(io.confluent.ksql.parser.tree.CreateTable) SourceName(io.confluent.ksql.name.SourceName) KsqlException(io.confluent.ksql.util.KsqlException) 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