Search in sources :

Example 6 with TransientQueryMetadata

use of io.confluent.ksql.util.TransientQueryMetadata in project ksql by confluentinc.

the class QueryRegistryImplTest method shouldGetQuery.

@Test
public void shouldGetQuery() {
    // Given:
    final TransientQueryMetadata q1 = givenCreateTransient(registry, "transient1");
    final PersistentQueryMetadata q2 = givenCreate(registry, "q1", "source", Optional.of("sink1"), CREATE_AS);
    final PersistentQueryMetadata q3 = givenCreate(registry, "q2", "source", Optional.empty(), CREATE_SOURCE);
    // When:
    final QueryMetadata queryMetadata1 = registry.getQuery(q1.getQueryId()).get();
    final QueryMetadata queryMetadata2 = registry.getQuery(q2.getQueryId()).get();
    final QueryMetadata queryMetadata3 = registry.getQuery(q3.getQueryId()).get();
    // Then:
    assertThat(queryMetadata1, is(q1));
    assertThat(queryMetadata2, is(q2));
    assertThat(queryMetadata3, is(q3));
}
Also used : TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) QueryMetadata(io.confluent.ksql.util.QueryMetadata) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Test(org.junit.Test)

Example 7 with TransientQueryMetadata

use of io.confluent.ksql.util.TransientQueryMetadata in project ksql by confluentinc.

the class EndToEndIntegrationTest method shouldSupportConfigurableUdfs.

@Test
public void shouldSupportConfigurableUdfs() throws Exception {
    // When:
    final TransientQueryMetadata queryMetadata = executeStatement("SELECT E2EConfigurableUdf(registertime) AS x from %s EMIT CHANGES;", USER_TABLE);
    // Then:
    final List<GenericRow> rows = verifyAvailableRows(queryMetadata, 5);
    assertThat(ConfigurableUdf.PASSED_CONFIG, is(ImmutableMap.of(KSQL_FUNCTIONS_PROPERTY_PREFIX + "e2econfigurableudf.some.setting", "foo-bar", KSQL_FUNCTIONS_PROPERTY_PREFIX + "_global_.expected-param", "expected-value")));
    rows.forEach(row -> assertThat(row.get(0), is(-1L)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) IntegrationTest(org.apache.kafka.test.IntegrationTest) Test(org.junit.Test)

Example 8 with TransientQueryMetadata

use of io.confluent.ksql.util.TransientQueryMetadata in project ksql by confluentinc.

the class EndToEndIntegrationTest method verifyAvailableRows.

private static List<GenericRow> verifyAvailableRows(final TransientQueryMetadata queryMetadata, final int expectedRows) {
    final BlockingRowQueue rowQueue = queryMetadata.getRowQueue();
    assertThatEventually(expectedRows + " rows were not available after 30 seconds", () -> rowQueue.size() >= expectedRows, is(true), 30, TimeUnit.SECONDS);
    final List<KeyValueMetadata<List<?>, GenericRow>> rows = new ArrayList<>();
    rowQueue.drainTo(rows);
    return rows.stream().map(kvm -> kvm.getKeyValue().value()).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) Matchers.either(org.hamcrest.Matchers.either) KeyValue(io.confluent.ksql.util.KeyValue) BlockingRowQueue(io.confluent.ksql.query.BlockingRowQueue) AssertEventually.assertThatEventually(io.confluent.ksql.test.util.AssertEventually.assertThatEventually) LoggerFactory(org.slf4j.LoggerFactory) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) After(org.junit.After) QueryId(io.confluent.ksql.query.QueryId) ClassRule(org.junit.ClassRule) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Parameterized(org.junit.runners.Parameterized) ZooKeeperClientException(kafka.zookeeper.ZooKeeperClientException) QueryMetadata(io.confluent.ksql.util.QueryMetadata) Configurable(org.apache.kafka.common.Configurable) KSQL_FUNCTIONS_PROPERTY_PREFIX(io.confluent.ksql.util.KsqlConfig.KSQL_FUNCTIONS_PROPERTY_PREFIX) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) KsqlConfig(io.confluent.ksql.util.KsqlConfig) TopicListing(org.apache.kafka.clients.admin.TopicListing) RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Objects(java.util.Objects) List(java.util.List) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) UserDataProvider(io.confluent.ksql.util.UserDataProvider) KsqlConstants(io.confluent.ksql.util.KsqlConstants) ConsumerInterceptor(org.apache.kafka.clients.consumer.ConsumerInterceptor) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StreamsConfig(org.apache.kafka.streams.StreamsConfig) PageViewDataProvider(io.confluent.ksql.util.PageViewDataProvider) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) JSON(io.confluent.ksql.serde.FormatFactory.JSON) ProducerInterceptor(org.apache.kafka.clients.producer.ProducerInterceptor) RunWith(org.junit.runner.RunWith) IntegrationTest(org.apache.kafka.test.IntegrationTest) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) ArrayList(java.util.ArrayList) KeyValueMetadata(io.confluent.ksql.util.KeyValueMetadata) Timeout(org.junit.rules.Timeout) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Before(org.junit.Before) UdfDescription(io.confluent.ksql.function.udf.UdfDescription) Logger(org.slf4j.Logger) Udf(io.confluent.ksql.function.udf.Udf) KAFKA(io.confluent.ksql.serde.FormatFactory.KAFKA) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) RuleChain(org.junit.rules.RuleChain) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Rule(org.junit.Rule) GenericRow(io.confluent.ksql.GenericRow) Format(io.confluent.ksql.serde.Format) ListTopicsResult(org.apache.kafka.clients.admin.ListTopicsResult) ArrayList(java.util.ArrayList) KeyValueMetadata(io.confluent.ksql.util.KeyValueMetadata) BlockingRowQueue(io.confluent.ksql.query.BlockingRowQueue)

Example 9 with TransientQueryMetadata

use of io.confluent.ksql.util.TransientQueryMetadata in project ksql by confluentinc.

the class QueryRegistryImpl method createTransientQuery.

// CHECKSTYLE_RULES.OFF: ParameterNumberCheck
@Override
public TransientQueryMetadata createTransientQuery(final SessionConfig config, final ServiceContext serviceContext, final ProcessingLogContext processingLogContext, final MetaStore metaStore, final String statementText, final QueryId queryId, final Set<SourceName> sources, final ExecutionStep<?> physicalPlan, final String planSummary, final LogicalSchema schema, final OptionalInt limit, final Optional<WindowInfo> windowInfo, final boolean excludeTombstones) {
    // CHECKSTYLE_RULES.ON: ParameterNumberCheck
    final QueryBuilder queryBuilder = queryBuilderFactory.create(config, processingLogContext, serviceContext, metaStore, streams, !sandbox);
    final TransientQueryMetadata query = queryBuilder.buildTransientQuery(statementText, queryId, sources, physicalPlan, planSummary, schema, limit, windowInfo, excludeTombstones, new ListenerImpl(), new StreamsBuilder(), Optional.empty(), metricCollectors);
    query.initialize();
    registerTransientQuery(serviceContext, metaStore, query);
    return query;
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) SandboxedTransientQueryMetadata(io.confluent.ksql.util.SandboxedTransientQueryMetadata) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata)

Example 10 with TransientQueryMetadata

use of io.confluent.ksql.util.TransientQueryMetadata in project ksql by confluentinc.

the class QueryDescriptionFactoryTest method shouldHandleRowKeyInValueSchemaForTransientQuery.

@Test
public void shouldHandleRowKeyInValueSchemaForTransientQuery() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().valueColumn(ColumnName.of("field1"), SqlTypes.INTEGER).valueColumn(ColumnName.of("ROWKEY"), SqlTypes.STRING).valueColumn(ColumnName.of("field2"), SqlTypes.STRING).build();
    transientQuery = new TransientQueryMetadata(SQL_TEXT, schema, SOURCE_NAMES, "execution plan", queryQueue, QUERY_ID, "app id", topology, kafkaStreamsBuilder, STREAMS_PROPS, PROP_OVERRIDES, closeTimeout, 10, ResultType.STREAM, 0L, 0L, listener);
    transientQuery.initialize();
    // When:
    transientQueryDescription = QueryDescriptionFactory.forQueryMetadata(transientQuery, Collections.emptyMap());
    // Then:
    assertThat(transientQueryDescription.getFields(), contains(new FieldInfo("field1", new SchemaInfo(SqlBaseType.INTEGER, null, null), Optional.empty()), new FieldInfo("ROWKEY", new SchemaInfo(SqlBaseType.STRING, null, null), Optional.empty()), new FieldInfo("field2", new SchemaInfo(SqlBaseType.STRING, null, null), Optional.empty())));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) Test(org.junit.Test)

Aggregations

TransientQueryMetadata (io.confluent.ksql.util.TransientQueryMetadata)22 Test (org.junit.Test)10 QueryId (io.confluent.ksql.query.QueryId)5 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)5 QueryMetadata (io.confluent.ksql.util.QueryMetadata)5 GenericRow (io.confluent.ksql.GenericRow)4 KsqlConfig (io.confluent.ksql.util.KsqlConfig)4 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)4 IntegrationTest (org.apache.kafka.test.IntegrationTest)4 Before (org.junit.Before)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Query (io.confluent.ksql.parser.tree.Query)3 BlockingRowQueue (io.confluent.ksql.query.BlockingRowQueue)3 KeyValue (io.confluent.ksql.util.KeyValue)3 KeyValueMetadata (io.confluent.ksql.util.KeyValueMetadata)3 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2