Search in sources :

Example 56 with DataSource

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

the class WindowingIntTest method givenTable.

private void givenTable(final String sql) {
    ksqlContext.sql(String.format(sql, resultStream0));
    final DataSource source = ksqlContext.getMetaStore().getSource(SourceName.of(resultStream0));
    resultSchema = PhysicalSchema.from(source.getSchema(), source.getKsqlTopic().getKeyFormat().getFeatures(), source.getKsqlTopic().getValueFormat().getFeatures());
}
Also used : DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 57 with DataSource

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

the class UdfIntTest method consumeOutputMessages.

private Map<GenericKey, GenericRow> consumeOutputMessages() {
    final DataSource source = ksqlContext.getMetaStore().getSource(SourceName.of(resultStreamName));
    final PhysicalSchema resultSchema = PhysicalSchema.from(source.getSchema(), source.getKsqlTopic().getKeyFormat().getFeatures(), source.getKsqlTopic().getValueFormat().getFeatures());
    return TEST_HARNESS.verifyAvailableUniqueRows(resultStreamName, 1, KAFKA, testData.format, resultSchema);
}
Also used : PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 58 with DataSource

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

the class JoinIntTest method shouldUseTimeStampFieldFromStream.

@Test
public void shouldUseTimeStampFieldFromStream() {
    final String queryString = "CREATE STREAM JOINED AS " + "SELECT " + ORDER_STREAM_NAME_AVRO + ".ITEMID, ORDERID, ORDERUNITS, DESCRIPTION " + "FROM " + ORDER_STREAM_NAME_AVRO + " LEFT JOIN " + ITEM_TABLE_NAME_AVRO + " " + "ON " + ORDER_STREAM_NAME_AVRO + ".ITEMID = " + ITEM_TABLE_NAME_AVRO + ".ID " + "WHERE " + ORDER_STREAM_NAME_AVRO + ".ITEMID = 'ITEM_1';" + "" + "CREATE STREAM OUTPUT AS " + "SELECT ITEMID, ORDERID, DESCRIPTION, ROWTIME AS RT " + "FROM JOINED;";
    ksqlContext.sql(queryString);
    final DataSource source = ksqlContext.getMetaStore().getSource(SourceName.of("OUTPUT"));
    final Map<GenericKey, GenericRow> expectedResults = ImmutableMap.of(genericKey("ITEM_1"), genericRow("ORDER_1", "home cinema", 1L));
    assertExpectedResults(expectedResults, source, orderStreamTopicAvro, KAFKA, AVRO, 120000);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) DataSource(io.confluent.ksql.metastore.model.DataSource) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 59 with DataSource

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

the class JoinIntTest method shouldLeftJoinOrderAndItems.

private void shouldLeftJoinOrderAndItems(final String testStreamName, final String orderStreamTopic, final String orderStreamName, final String itemTableName, final Format valueFormat) {
    final String queryString = "CREATE STREAM " + testStreamName + " AS " + "SELECT " + orderStreamName + ".ITEMID, ORDERID, ORDERUNITS, DESCRIPTION " + "FROM " + orderStreamName + " LEFT JOIN " + itemTableName + " " + "on " + orderStreamName + ".ITEMID = " + itemTableName + ".ID " + "WHERE " + orderStreamName + ".ITEMID = 'ITEM_1' ;";
    ksqlContext.sql(queryString);
    final DataSource source = ksqlContext.getMetaStore().getSource(SourceName.of(testStreamName));
    final Map<GenericKey, GenericRow> expectedResults = ImmutableMap.of(genericKey("ITEM_1"), genericRow("ORDER_1", 10.0, "home cinema"));
    assertExpectedResults(expectedResults, source, orderStreamTopic, KAFKA, valueFormat);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 60 with DataSource

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

the class JoinIntTest method shouldInsertLeftJoinOrderAndItems.

@Test
public void shouldInsertLeftJoinOrderAndItems() {
    final String testStreamName = "OrderedWithDescription".toUpperCase();
    final String commonSql = "SELECT " + ORDER_STREAM_NAME_JSON + ".ITEMID, ORDERID, ORDERUNITS, DESCRIPTION " + "FROM " + ORDER_STREAM_NAME_JSON + " LEFT JOIN " + ITEM_TABLE_NAME_JSON + " " + " on " + ORDER_STREAM_NAME_JSON + ".ITEMID = " + ITEM_TABLE_NAME_JSON + ".ID ";
    final String csasQueryString = "CREATE STREAM " + testStreamName + " AS " + commonSql + "WHERE " + ORDER_STREAM_NAME_JSON + ".ITEMID = 'Hello' ;";
    final String insertQueryString = "INSERT INTO " + testStreamName + " " + commonSql + "WHERE " + ORDER_STREAM_NAME_JSON + ".ITEMID = 'ITEM_1' ;";
    ksqlContext.sql(csasQueryString);
    ksqlContext.sql(insertQueryString);
    final DataSource source = ksqlContext.getMetaStore().getSource(SourceName.of(testStreamName));
    final Map<GenericKey, GenericRow> expectedResults = ImmutableMap.of(genericKey("ITEM_1"), genericRow("ORDER_1", 10.0, "home cinema"));
    assertExpectedResults(expectedResults, source, orderStreamTopicJson, KAFKA, JSON);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) DataSource(io.confluent.ksql.metastore.model.DataSource) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Aggregations

DataSource (io.confluent.ksql.metastore.model.DataSource)70 Test (org.junit.Test)25 KsqlException (io.confluent.ksql.util.KsqlException)24 SourceName (io.confluent.ksql.name.SourceName)21 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)12 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)12 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)10 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)9 Collectors (java.util.stream.Collectors)9 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)8 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)7 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)7 Optional (java.util.Optional)7 ImmutableList (com.google.common.collect.ImmutableList)6 GenericKey (io.confluent.ksql.GenericKey)6 QueryId (io.confluent.ksql.query.QueryId)6 ServiceContext (io.confluent.ksql.services.ServiceContext)6 KsqlConfig (io.confluent.ksql.util.KsqlConfig)6 Collections (java.util.Collections)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6