Search in sources :

Example 26 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class ListPropertiesExecutorTest method shouldListProperties.

@Test
public void shouldListProperties() {
    // When:
    final PropertiesList properties = (PropertiesList) CUSTOM_EXECUTORS.listProperties().execute((ConfiguredStatement<ListProperties>) engine.configure("LIST PROPERTIES;"), mock(SessionProperties.class), engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(toStringMap(properties), equalTo(engine.getKsqlConfig().getAllConfigPropsWithSecretsObfuscated()));
    assertThat(properties.getOverwrittenProperties(), is(empty()));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) Test(org.junit.Test)

Example 27 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class ListPropertiesExecutorTest method shouldListUnresolvedStreamsTopicProperties.

@Test
public void shouldListUnresolvedStreamsTopicProperties() {
    // When:
    final PropertiesList properties = (PropertiesList) CUSTOM_EXECUTORS.listProperties().execute((ConfiguredStatement<ListProperties>) engine.configure("LIST PROPERTIES;").withConfig(new KsqlConfig(ImmutableMap.of("ksql.streams.topic.min.insync.replicas", "2"))), mock(SessionProperties.class), engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(properties.getProperties(), hasItem(new Property("ksql.streams.topic.min.insync.replicas", "KSQL", "2")));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Property(io.confluent.ksql.rest.entity.PropertiesList.Property) Test(org.junit.Test)

Example 28 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement 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)

Example 29 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class ListSourceExecutorTest method shouldDescribeTables.

@Test
public void shouldDescribeTables() {
    // Given:
    final KsqlTable<?> table1 = engine.givenSource(DataSourceType.KTABLE, "table1");
    final KsqlTable<?> table2 = engine.givenSource(DataSourceType.KTABLE, "table2", ImmutableSet.of(SourceName.of("table1")));
    engine.givenSource(DataSourceType.KSTREAM, "stream");
    // When:
    final SourceDescriptionList descriptionList = (SourceDescriptionList) CUSTOM_EXECUTORS.describeTables().execute((ConfiguredStatement<DescribeTables>) engine.configure("DESCRIBE TABLES;"), SESSION_PROPERTIES, engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(descriptionList.getSourceDescriptions(), containsInAnyOrder(SourceDescriptionFactory.create(table1, false, ImmutableList.of(), ImmutableList.of(), Optional.of(topicWith1PartitionAndRfOf1), ImmutableList.of(), ImmutableList.of("table2"), new MetricCollectors()), SourceDescriptionFactory.create(table2, false, ImmutableList.of(), ImmutableList.of(), Optional.of(topicWith1PartitionAndRfOf1), ImmutableList.of(), ImmutableList.of(), new MetricCollectors())));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) Test(org.junit.Test)

Example 30 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class ListSourceExecutorTest method shouldThrowOnDescribeMissingSource.

@Test
public void shouldThrowOnDescribeMissingSource() {
    // When:
    final Exception e = assertThrows(KsqlStatementException.class, () -> CUSTOM_EXECUTORS.showColumns().execute((ConfiguredStatement<ShowColumns>) engine.configure("DESCRIBE S;"), SESSION_PROPERTIES, engine.getEngine(), engine.getServiceContext()));
    // Then:
    assertThat(e.getMessage(), containsString("Could not find STREAM/TABLE 'S' in the Metastore"));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Aggregations

ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)84 Test (org.junit.Test)57 KsqlException (io.confluent.ksql.util.KsqlException)23 Statement (io.confluent.ksql.parser.tree.Statement)22 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)19 Optional (java.util.Optional)19 ServiceContext (io.confluent.ksql.services.ServiceContext)18 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)18 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)17 KsqlConfig (io.confluent.ksql.util.KsqlConfig)16 Map (java.util.Map)14 DataSource (io.confluent.ksql.metastore.model.DataSource)12 QueryId (io.confluent.ksql.query.QueryId)12 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)12 Collectors (java.util.stream.Collectors)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 ListQueries (io.confluent.ksql.parser.tree.ListQueries)11 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)11 List (java.util.List)11 Query (io.confluent.ksql.parser.tree.Query)10