Search in sources :

Example 11 with KsqlStream

use of io.confluent.ksql.metastore.model.KsqlStream in project ksql by confluentinc.

the class AnalyzerFunctionalTest method shouldNotInheritNamespaceExplicitlySetUpstreamForAvro.

@Test
public void shouldNotInheritNamespaceExplicitlySetUpstreamForAvro() {
    final String simpleQuery = "create stream s1 as select * from S0;";
    final MutableMetaStore newAvroMetaStore = avroMetaStore.copy();
    final KsqlTopic ksqlTopic = new KsqlTopic("s0", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.AVRO.name(), ImmutableMap.of(ConnectProperties.FULL_SCHEMA_NAME, "org.ac.s1")), SerdeFeatures.of()));
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(ColumnName.of("FIELD1"), SqlTypes.BIGINT).build();
    final KsqlStream<?> ksqlStream = new KsqlStream<>("create stream s0 with(KAFKA_TOPIC='s0', VALUE_AVRO_SCHEMA_FULL_NAME='org.ac.s1', VALUE_FORMAT='avro');", SourceName.of("S0"), schema, Optional.empty(), false, ksqlTopic, false);
    newAvroMetaStore.putSource(ksqlStream, false);
    final List<Statement> statements = parse(simpleQuery, newAvroMetaStore);
    final CreateStreamAsSelect createStreamAsSelect = (CreateStreamAsSelect) statements.get(0);
    final Query query = createStreamAsSelect.getQuery();
    final Analyzer analyzer = new Analyzer(newAvroMetaStore, "", ROWPARTITION_ROWOFFSET_ENABLED, PULL_LIMIT_CLAUSE_ENABLED);
    final Analysis analysis = analyzer.analyze(query, Optional.of(createStreamAsSelect.getSink()));
    assertThat(analysis.getInto(), is(not(Optional.empty())));
    assertThat(analysis.getInto().get().getNewTopic().get().getValueFormat(), is(FormatInfo.of(FormatFactory.AVRO.name())));
}
Also used : KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) Query(io.confluent.ksql.parser.tree.Query) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) MutableMetaStore(io.confluent.ksql.metastore.MutableMetaStore) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Test(org.junit.Test)

Example 12 with KsqlStream

use of io.confluent.ksql.metastore.model.KsqlStream in project ksql by confluentinc.

the class ListSourceExecutor method describeStreams.

public static StatementExecutorResponse describeStreams(final ConfiguredStatement<DescribeStreams> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
    final List<KsqlStream<?>> ksqlStreams = getSpecificStreams(executionContext);
    final DescribeStreams describeStreams = statement.getStatement();
    return StatementExecutorResponse.handled(sourceDescriptionList(statement, sessionProperties, executionContext, serviceContext, ksqlStreams, describeStreams.getShowExtended()));
}
Also used : KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) DescribeStreams(io.confluent.ksql.parser.tree.DescribeStreams)

Example 13 with KsqlStream

use of io.confluent.ksql.metastore.model.KsqlStream 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)

Aggregations

KsqlStream (io.confluent.ksql.metastore.model.KsqlStream)13 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)7 Test (org.junit.Test)5 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)4 MetaStoreImpl (io.confluent.ksql.metastore.MetaStoreImpl)3 Before (org.junit.Before)3 CreateStreamCommand (io.confluent.ksql.execution.ddl.commands.CreateStreamCommand)2 InternalFunctionRegistry (io.confluent.ksql.function.InternalFunctionRegistry)2 MutableMetaStore (io.confluent.ksql.metastore.MutableMetaStore)2 KsqlTable (io.confluent.ksql.metastore.model.KsqlTable)2 StreamsList (io.confluent.ksql.rest.entity.StreamsList)2 KsqlConfig (io.confluent.ksql.util.KsqlConfig)2 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)1 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)1 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)1 SourceName (io.confluent.ksql.name.SourceName)1 DefaultKsqlParser (io.confluent.ksql.parser.DefaultKsqlParser)1 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)1 AliasedRelation (io.confluent.ksql.parser.tree.AliasedRelation)1 CreateStream (io.confluent.ksql.parser.tree.CreateStream)1