Search in sources :

Example 6 with QueryMetadata

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

the class WindowingIntTest method shouldAggregateHoppingWindow.

@Test
public void shouldAggregateHoppingWindow() throws Exception {
    testHarness.publishTestData(topicName, dataProvider, now);
    final String streamName = "HOPPING_AGGTEST";
    final String queryString = String.format("CREATE TABLE %s AS SELECT %s FROM ORDERS WINDOW %s WHERE ITEMID = 'ITEM_1' GROUP BY ITEMID;", streamName, "ITEMID, COUNT(ITEMID), SUM(ORDERUNITS)", "HOPPING ( SIZE 10 SECONDS, ADVANCE BY 5 SECONDS)");
    ksqlContext.sql(queryString);
    Schema resultSchema = ksqlContext.getMetaStore().getSource(streamName).getSchema();
    final GenericRow expected = new GenericRow(Arrays.asList(null, null, "ITEM_1", 2, /**
     * 2 x items *
     */
    20.0));
    final Map<String, GenericRow> results = new HashMap<>();
    TestUtils.waitForCondition(() -> {
        final Map<Windowed<String>, GenericRow> windowedResults = testHarness.consumeData(streamName, resultSchema, 1, new TimeWindowedDeserializer<>(new StringDeserializer()), 1000);
        updateResults(results, windowedResults);
        final GenericRow actual = results.get("ITEM_1");
        return expected.equals(actual);
    }, 60000, "didn't receive correct results within timeout");
    AdminClient adminClient = AdminClient.create(testHarness.ksqlConfig.getKsqlStreamConfigProps());
    KafkaTopicClient topicClient = new KafkaTopicClientImpl(adminClient);
    Set<String> topicBeforeCleanup = topicClient.listTopicNames();
    assertThat("Expected to have 5 topics instead have : " + topicBeforeCleanup.size(), topicBeforeCleanup.size(), equalTo(5));
    QueryMetadata queryMetadata = ksqlContext.getRunningQueries().iterator().next();
    queryMetadata.close();
    Set<String> topicsAfterCleanUp = topicClient.listTopicNames();
    assertThat("Expected to see 3 topics after clean up but seeing " + topicsAfterCleanUp.size(), topicsAfterCleanUp.size(), equalTo(3));
    assertThat(topicClient.getTopicCleanupPolicy(streamName), equalTo(KafkaTopicClient.TopicCleanupPolicy.DELETE));
}
Also used : QueryMetadata(io.confluent.ksql.util.QueryMetadata) HashMap(java.util.HashMap) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) Schema(org.apache.kafka.connect.data.Schema) GenericRow(io.confluent.ksql.GenericRow) Windowed(org.apache.kafka.streams.kstream.Windowed) KafkaTopicClient(io.confluent.ksql.util.KafkaTopicClient) KafkaTopicClientImpl(io.confluent.ksql.util.KafkaTopicClientImpl) AdminClient(org.apache.kafka.clients.admin.AdminClient) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 7 with QueryMetadata

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

the class PhysicalPlanBuilderTest method shouldHaveOutputNode.

@Test
public void shouldHaveOutputNode() throws Exception {
    final QueryMetadata queryMetadata = buildPhysicalPlan(simpleSelectFilter);
    assertThat(queryMetadata.getOutputNode(), instanceOf(KsqlBareOutputNode.class));
}
Also used : QueryMetadata(io.confluent.ksql.util.QueryMetadata) KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) Test(org.junit.Test)

Example 8 with QueryMetadata

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

the class PhysicalPlanBuilderTest method shouldHaveKStreamDataSource.

@Test
public void shouldHaveKStreamDataSource() throws Exception {
    final QueryMetadata metadata = buildPhysicalPlan(simpleSelectFilter);
    assertThat(metadata.getDataSourceType(), equalTo(DataSource.DataSourceType.KSTREAM));
}
Also used : QueryMetadata(io.confluent.ksql.util.QueryMetadata) Test(org.junit.Test)

Example 9 with QueryMetadata

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

the class KsqlEngineTest method shouldCreatePersistentQueries.

@Test
public void shouldCreatePersistentQueries() throws Exception {
    final List<QueryMetadata> queries = ksqlEngine.createQueries("create table bar as select * from test2;" + "create table foo as select * from test2;");
    assertThat(queries.size(), equalTo(2));
    final PersistentQueryMetadata queryOne = (PersistentQueryMetadata) queries.get(0);
    final PersistentQueryMetadata queryTwo = (PersistentQueryMetadata) queries.get(1);
    assertThat(queryOne.getEntity(), equalTo("BAR"));
    assertThat(queryTwo.getEntity(), equalTo("FOO"));
}
Also used : QueryMetadata(io.confluent.ksql.util.QueryMetadata) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Test(org.junit.Test)

Example 10 with QueryMetadata

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

the class StatementExecutor method handleRunScript.

private void handleRunScript(Command command) throws Exception {
    if (command.getKsqlProperties().containsKey(KsqlConstants.RUN_SCRIPT_STATEMENTS_CONTENT)) {
        String queries = (String) command.getKsqlProperties().get(KsqlConstants.RUN_SCRIPT_STATEMENTS_CONTENT);
        List<QueryMetadata> queryMetadataList = ksqlEngine.buildMultipleQueries(queries, command.getKsqlProperties());
        for (QueryMetadata queryMetadata : queryMetadataList) {
            if (queryMetadata instanceof PersistentQueryMetadata) {
                PersistentQueryMetadata persistentQueryMetadata = (PersistentQueryMetadata) queryMetadata;
                persistentQueryMetadata.getKafkaStreams().start();
            }
        }
    } else {
        throw new KsqlException("No statements received for LOAD FROM FILE.");
    }
}
Also used : PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) QueryMetadata(io.confluent.ksql.util.QueryMetadata) KsqlException(io.confluent.ksql.util.KsqlException) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata)

Aggregations

QueryMetadata (io.confluent.ksql.util.QueryMetadata)23 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)13 Test (org.junit.Test)10 KsqlException (io.confluent.ksql.util.KsqlException)5 IntegrationTest (io.confluent.common.utils.IntegrationTest)4 GenericRow (io.confluent.ksql.GenericRow)4 KafkaTopicClient (io.confluent.ksql.util.KafkaTopicClient)4 KafkaTopicClientImpl (io.confluent.ksql.util.KafkaTopicClientImpl)4 HashMap (java.util.HashMap)4 AdminClient (org.apache.kafka.clients.admin.AdminClient)4 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)4 Schema (org.apache.kafka.connect.data.Schema)4 Windowed (org.apache.kafka.streams.kstream.Windowed)3 QueryId (io.confluent.ksql.query.QueryId)2 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)2 WakeupException (org.apache.kafka.common.errors.WakeupException)2 CreateStreamCommand (io.confluent.ksql.ddl.commands.CreateStreamCommand)1 CreateTableCommand (io.confluent.ksql.ddl.commands.CreateTableCommand)1 DdlCommandExec (io.confluent.ksql.ddl.commands.DdlCommandExec)1 DropSourceCommand (io.confluent.ksql.ddl.commands.DropSourceCommand)1