Search in sources :

Example 76 with ConfiguredStatement

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

the class ListTopicsExecutorTest method shouldListKafkaTopicsIncludingInternalTopics.

@Test
public void shouldListKafkaTopicsIncludingInternalTopics() {
    // Given:
    engine.givenKafkaTopic("topic1");
    engine.givenKafkaTopic("topic2");
    engine.givenKafkaTopic("_confluent_any_topic");
    // When:
    final KafkaTopicsList topicsList = (KafkaTopicsList) CUSTOM_EXECUTORS.listTopics().execute((ConfiguredStatement<ListTopics>) engine.configure("LIST ALL TOPICS;"), mock(SessionProperties.class), engine.getEngine(), serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(topicsList.getTopics(), containsInAnyOrder(new KafkaTopicInfo("topic1", ImmutableList.of(1)), new KafkaTopicInfo("topic2", ImmutableList.of(1)), new KafkaTopicInfo("_confluent_any_topic", ImmutableList.of(1))));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KafkaTopicInfo(io.confluent.ksql.rest.entity.KafkaTopicInfo) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) Test(org.junit.Test)

Example 77 with ConfiguredStatement

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

the class TerminateQueryExecutorTest method shouldFailToTerminateTransientQuery.

@Test
public void shouldFailToTerminateTransientQuery() {
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CUSTOM_EXECUTORS.terminateQuery().execute((ConfiguredStatement<TerminateQuery>) engine.configure("TERMINATE TRANSIENT_QUERY;"), mock(SessionProperties.class), engine.getEngine(), this.engine.getServiceContext()));
    // Then:
    assertThat(e.getMessage(), containsString("Failed to terminate query with query ID: 'TRANSIENT_QUERY'"));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 78 with ConfiguredStatement

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

the class RemoteHostExecutorTest method setup.

@SuppressWarnings("unchecked")
@Before
public void setup() throws MalformedURLException {
    when(sessionProperties.getInternalRequest()).thenReturn(false);
    when(sessionProperties.getLocalUrl()).thenReturn(new URL("https://address"));
    augmenter = RemoteHostExecutor.create((ConfiguredStatement<DescribeStreams>) engine.configure("describe streams;"), sessionProperties, executionContext, ksqlClient);
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) URL(java.net.URL) Before(org.junit.Before)

Example 79 with ConfiguredStatement

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

the class FeatureFlagCheckerTest method shouldNotThrowOnCreateStreamWithHeadersIfFeatureFlagIsEnabled.

@Test
public void shouldNotThrowOnCreateStreamWithHeadersIfFeatureFlagIsEnabled() {
    // Given
    final KsqlConfig config = new KsqlConfig(ImmutableMap.of(KsqlConfig.KSQL_HEADERS_COLUMNS_ENABLED, true));
    final CreateStream createStream = new CreateStream(SourceName.of("stream1"), TableElements.of(new TableElement(ColumnName.of("col1"), new Type(SqlTypes.INTEGER), new ColumnConstraints.Builder().headers().build())), false, false, CreateSourceProperties.from(ImmutableMap.of(CommonCreateConfigs.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral("topic1"))), false);
    final ConfiguredStatement configuredStatement = configured(config, createStream);
    // When/Then
    FeatureFlagChecker.throwOnDisabledFeatures(configuredStatement);
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Type(io.confluent.ksql.execution.expression.tree.Type) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ColumnConstraints(io.confluent.ksql.parser.tree.ColumnConstraints) KsqlConfig(io.confluent.ksql.util.KsqlConfig) CreateStream(io.confluent.ksql.parser.tree.CreateStream) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Example 80 with ConfiguredStatement

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

the class ListSourceExecutor method sourceDescriptionList.

private static Optional<KsqlEntity> sourceDescriptionList(final ConfiguredStatement<? extends StatementWithExtendedClause> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext, final List<? extends DataSource> sources, final boolean extended) {
    final RemoteHostExecutor remoteHostExecutor = RemoteHostExecutor.create(statement, sessionProperties, executionContext, serviceContext.getKsqlClient());
    final Multimap<String, SourceDescription> remoteSourceDescriptions = extended ? RemoteSourceDescriptionExecutor.fetchSourceDescriptions(remoteHostExecutor) : ImmutableMultimap.of();
    final List<SourceDescriptionWithWarnings> descriptions = sources.stream().map(s -> describeSource(statement.getSessionConfig().getConfig(false), executionContext, serviceContext, s.getName(), extended, statement, sessionProperties, remoteSourceDescriptions.get(s.getName().toString()))).collect(Collectors.toList());
    return Optional.of(new SourceDescriptionList(statement.getStatementText(), descriptions.stream().map(d -> d.description).collect(Collectors.toList()), descriptions.stream().flatMap(d -> d.warnings.stream()).collect(Collectors.toList())));
}
Also used : DataSource(io.confluent.ksql.metastore.model.DataSource) StreamsList(io.confluent.ksql.rest.entity.StreamsList) SessionProperties(io.confluent.ksql.rest.SessionProperties) SourceName(io.confluent.ksql.name.SourceName) QueryOffsetSummary(io.confluent.ksql.rest.entity.QueryOffsetSummary) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) DescribeTables(io.confluent.ksql.parser.tree.DescribeTables) ServiceContext(io.confluent.ksql.services.ServiceContext) KafkaException(org.apache.kafka.common.KafkaException) QueryTopicOffsetSummary(io.confluent.ksql.rest.entity.QueryTopicOffsetSummary) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) Map(java.util.Map) QueryId(io.confluent.ksql.query.QueryId) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) TopicPartition(org.apache.kafka.common.TopicPartition) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlConfig(io.confluent.ksql.util.KsqlConfig) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) Collectors(java.util.stream.Collectors) List(java.util.List) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) Entry(java.util.Map.Entry) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) Optional(java.util.Optional) KsqlConstants(io.confluent.ksql.util.KsqlConstants) KsqlRestApplication(io.confluent.ksql.rest.server.KsqlRestApplication) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) HashSet(java.util.HashSet) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) ImmutableList(com.google.common.collect.ImmutableList) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) MetaStore(io.confluent.ksql.metastore.MetaStore) ShowColumns(io.confluent.ksql.parser.tree.ShowColumns) DescribeStreams(io.confluent.ksql.parser.tree.DescribeStreams) TablesList(io.confluent.ksql.rest.entity.TablesList) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) LinkedList(java.util.LinkedList) ListTables(io.confluent.ksql.parser.tree.ListTables) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Table(io.confluent.ksql.rest.entity.SourceInfo.Table) ListStreams(io.confluent.ksql.parser.tree.ListStreams) QueryApplicationId(io.confluent.ksql.util.QueryApplicationId) SourceDescriptionFactory(io.confluent.ksql.rest.entity.SourceDescriptionFactory) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) StatementWithExtendedClause(io.confluent.ksql.parser.tree.StatementWithExtendedClause) ConsumerPartitionOffsets(io.confluent.ksql.rest.entity.ConsumerPartitionOffsets) Stream(io.confluent.ksql.rest.entity.SourceInfo.Stream) Collections(java.util.Collections) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription)

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