Search in sources :

Example 1 with KsqlStream

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

the class SqlFormatterTest method setUp.

@Before
public void setUp() {
    final Table left = new Table(SourceName.of("left"));
    final Table right = new Table(SourceName.of("right"));
    final Table right2 = new Table(SourceName.of("right2"));
    leftAlias = new AliasedRelation(left, SourceName.of("L"));
    rightAlias = new AliasedRelation(right, SourceName.of("R"));
    right2Alias = new AliasedRelation(right2, SourceName.of("R2"));
    criteria = new JoinOn(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new StringLiteral("left.col0"), new StringLiteral("right.col0")));
    criteria2 = new JoinOn(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new StringLiteral("left.col0"), new StringLiteral("right2.col0")));
    metaStore = MetaStoreFixture.getNewMetaStore(mock(FunctionRegistry.class));
    final KsqlTopic ksqlTopicOrders = new KsqlTopic("orders_topic", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of()));
    final KsqlStream<?> ksqlStreamOrders = new KsqlStream<>("sqlexpression", SourceName.of("ADDRESS"), ORDERS_SCHEMA, Optional.empty(), false, ksqlTopicOrders, false);
    metaStore.putSource(ksqlStreamOrders, false);
    final KsqlTopic ksqlTopicItems = new KsqlTopic("item_topic", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of()));
    final KsqlTable<String> ksqlTableOrders = new KsqlTable<>("sqlexpression", SourceName.of("ITEMID"), ITEM_INFO_SCHEMA, Optional.empty(), false, ksqlTopicItems, false);
    metaStore.putSource(ksqlTableOrders, false);
    final KsqlTable<String> ksqlTableTable = new KsqlTable<>("sqlexpression", SourceName.of("TABLE"), TABLE_SCHEMA, Optional.empty(), false, ksqlTopicItems, false);
    metaStore.putSource(ksqlTableTable, false);
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) CreateTable(io.confluent.ksql.parser.tree.CreateTable) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) DropTable(io.confluent.ksql.parser.tree.DropTable) Table(io.confluent.ksql.parser.tree.Table) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) StringContains.containsString(org.hamcrest.core.StringContains.containsString) JoinOn(io.confluent.ksql.parser.tree.JoinOn) AliasedRelation(io.confluent.ksql.parser.tree.AliasedRelation) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Before(org.junit.Before)

Example 2 with KsqlStream

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

the class ListSourceExecutor method streams.

public static StatementExecutorResponse streams(final ConfiguredStatement<ListStreams> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
    final List<KsqlStream<?>> ksqlStreams = getSpecificStreams(executionContext);
    final ListStreams listStreams = statement.getStatement();
    if (listStreams.getShowExtended()) {
        return StatementExecutorResponse.handled(sourceDescriptionList(statement, sessionProperties, executionContext, serviceContext, ksqlStreams, listStreams.getShowExtended()));
    }
    return StatementExecutorResponse.handled(Optional.of(new StreamsList(statement.getStatementText(), ksqlStreams.stream().map(ListSourceExecutor::sourceSteam).collect(Collectors.toList()))));
}
Also used : KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) ListStreams(io.confluent.ksql.parser.tree.ListStreams) StreamsList(io.confluent.ksql.rest.entity.StreamsList)

Example 3 with KsqlStream

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

the class SchemaRegisterInjectorTest method setUp.

@Before
public void setUp() throws IOException, RestClientException {
    metaStore = new MetaStoreImpl(new InternalFunctionRegistry());
    config = new KsqlConfig(ImmutableMap.of(KsqlConfig.SCHEMA_REGISTRY_URL_PROPERTY, "foo:8081"));
    injector = new SchemaRegisterInjector(executionContext, serviceContext);
    when(serviceContext.getSchemaRegistryClient()).thenReturn(schemaRegistryClient);
    when(serviceContext.getTopicClient()).thenReturn(topicClient);
    when(serviceContext.getConsumerGroupClient()).thenReturn(consumerGroupClient);
    when(executionContext.createSandbox(any())).thenReturn(executionSandbox);
    when(keyFeatures.enabled(SerdeFeature.UNWRAP_SINGLES)).thenReturn(true);
    when(ddlCommand.getSchema()).thenReturn(SCHEMA);
    when(ddlCommand.getTopicName()).thenReturn("SINK");
    when(ddlCommand.getFormats()).thenReturn(formats);
    when(formats.getKeyFormat()).thenReturn(FormatInfo.of(FormatFactory.AVRO.name()));
    when(formats.getKeyFeatures()).thenReturn(keyFeatures);
    when(formats.getValueFormat()).thenReturn(FormatInfo.of(FormatFactory.AVRO.name()));
    when(formats.getValueFeatures()).thenReturn(valFeatures);
    when(schemaRegistryClient.getLatestSchemaMetadata(any())).thenThrow(new RestClientException("foo", 404, SchemaRegistryUtil.SUBJECT_NOT_FOUND_ERROR_CODE));
    final KsqlTopic sourceTopic = new KsqlTopic("source", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), valFeatures));
    final KsqlStream<?> source = new KsqlStream<>("", SourceName.of("SOURCE"), SCHEMA, Optional.empty(), false, sourceTopic, false);
    metaStore.putSource(source, false);
}
Also used : KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) KsqlConfig(io.confluent.ksql.util.KsqlConfig) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Before(org.junit.Before)

Example 4 with KsqlStream

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

the class SourceDescriptionFactoryTest method buildDataSource.

private static DataSource buildDataSource(final String kafkaTopicName, final Optional<TimestampColumn> timestampColumn) {
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(ColumnName.of("field0"), SqlTypes.INTEGER).build();
    final KsqlTopic topic = new KsqlTopic(kafkaTopicName, KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of()));
    return new KsqlStream<>("query", SourceName.of("stream"), schema, timestampColumn, false, topic, false);
}
Also used : KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic)

Example 5 with KsqlStream

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

the class ListSourceExecutorTest method shouldShowStreams.

@Test
public void shouldShowStreams() {
    // Given:
    final KsqlStream<?> stream1 = engine.givenSource(DataSourceType.KSTREAM, "stream1");
    final KsqlStream<?> stream2 = engine.givenSource(DataSourceType.KSTREAM, "stream2");
    engine.givenSource(DataSourceType.KTABLE, "table");
    // When:
    final StreamsList descriptionList = (StreamsList) CUSTOM_EXECUTORS.listStreams().execute((ConfiguredStatement<ListStreams>) engine.configure("SHOW STREAMS;"), SESSION_PROPERTIES, engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(descriptionList.getStreams(), containsInAnyOrder(new SourceInfo.Stream(stream1.getName().toString(FormatOptions.noEscape()), stream1.getKafkaTopicName(), stream1.getKsqlTopic().getKeyFormat().getFormat(), stream1.getKsqlTopic().getValueFormat().getFormat(), stream1.getKsqlTopic().getKeyFormat().isWindowed()), new SourceInfo.Stream(stream2.getName().toString(FormatOptions.noEscape()), stream2.getKafkaTopicName(), stream2.getKsqlTopic().getKeyFormat().getFormat(), stream2.getKsqlTopic().getValueFormat().getFormat(), stream1.getKsqlTopic().getKeyFormat().isWindowed())));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) StreamsList(io.confluent.ksql.rest.entity.StreamsList) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) 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