Search in sources :

Example 46 with GenericRow

use of io.confluent.ksql.GenericRow in project ksql by confluentinc.

the class JsonFormatTest method testJsonStreamExtractor.

@Test
public void testJsonStreamExtractor() throws Exception {
    final String streamName = "JSONSTREAM";
    final String queryString = String.format("CREATE STREAM %s AS SELECT EXTRACTJSONFIELD" + "(message, '$.log.cloud') " + "FROM %s;", streamName, messageLogStream);
    executePersistentQuery(queryString);
    Schema resultSchema = SchemaUtil.removeImplicitRowTimeRowKeyFromSchema(metaStore.getSource(streamName).getSchema());
    Map<String, GenericRow> expectedResults = new HashMap<>();
    expectedResults.put("1", new GenericRow(Collections.singletonList("aws")));
    Map<String, GenericRow> results = readNormalResults(streamName, resultSchema, expectedResults.size());
    assertThat(results, equalTo(expectedResults));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) HashMap(java.util.HashMap) Schema(org.apache.kafka.connect.data.Schema) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 47 with GenericRow

use of io.confluent.ksql.GenericRow in project ksql by confluentinc.

the class JsonFormatTest method testJsonStreamExtractorNested.

@Test
public void testJsonStreamExtractorNested() throws Exception {
    final String streamName = "JSONSTREAM";
    final String queryString = String.format("CREATE STREAM %s AS SELECT EXTRACTJSONFIELD" + "(message, '$.log.logs[0].entry') " + "FROM %s;", streamName, messageLogStream);
    executePersistentQuery(queryString);
    Schema resultSchema = SchemaUtil.removeImplicitRowTimeRowKeyFromSchema(metaStore.getSource(streamName).getSchema());
    Map<String, GenericRow> expectedResults = new HashMap<>();
    expectedResults.put("1", new GenericRow(Collections.singletonList("first")));
    Map<String, GenericRow> results = readNormalResults(streamName, resultSchema, expectedResults.size());
    assertThat(results, equalTo(expectedResults));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) HashMap(java.util.HashMap) Schema(org.apache.kafka.connect.data.Schema) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 48 with GenericRow

use of io.confluent.ksql.GenericRow in project ksql by confluentinc.

the class StreamsSelectAndProjectIntTest method testSelectProjectKeyTimestamp.

private void testSelectProjectKeyTimestamp(String resultStream, String inputStreamName, DataSource.DataSourceSerDe dataSourceSerDe, Map<String, RecordMetadata> recordMetadataMap) throws Exception {
    ksqlContext.sql(String.format("CREATE STREAM %s AS SELECT ROWKEY AS RKEY, ROWTIME " + "AS RTIME, ITEMID FROM %s WHERE ORDERUNITS > 20 AND ITEMID = " + "'ITEM_8';", resultStream, inputStreamName));
    Schema resultSchema = ksqlContext.getMetaStore().getSource(resultStream).getSchema();
    Map<String, GenericRow> results = testHarness.consumeData(resultStream, resultSchema, dataProvider.data().size(), new StringDeserializer(), IntegrationTestHarness.RESULTS_POLL_MAX_TIME_MS, dataSourceSerDe);
    Map<String, GenericRow> expectedResults = Collections.singletonMap("8", new GenericRow(Arrays.asList(null, null, "8", recordMetadataMap.get("8").timestamp(), "ITEM_8")));
    assertThat(results, equalTo(expectedResults));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) Schema(org.apache.kafka.connect.data.Schema)

Example 49 with GenericRow

use of io.confluent.ksql.GenericRow in project ksql by confluentinc.

the class StreamsSelectAndProjectIntTest method testSelectProjectAvroJson.

@Test
public void testSelectProjectAvroJson() throws Exception {
    String resultStream = "PROJECT_STREAM_AVRO";
    ksqlContext.sql(String.format("CREATE STREAM %s WITH ( value_format = 'JSON') AS SELECT " + "ITEMID, " + "ORDERUNITS, " + "PRICEARRAY FROM %s;", resultStream, avroStreamName));
    Schema resultSchema = ksqlContext.getMetaStore().getSource(resultStream).getSchema();
    Map<String, GenericRow> easyOrdersData = testHarness.consumeData(resultStream, resultSchema, dataProvider.data().size(), new StringDeserializer(), IntegrationTestHarness.RESULTS_POLL_MAX_TIME_MS, DataSource.DataSourceSerDe.JSON);
    GenericRow value = easyOrdersData.values().iterator().next();
    // skip over first to values (rowKey, rowTime)
    Assert.assertEquals("ITEM_1", value.getColumns().get(2).toString());
}
Also used : GenericRow(io.confluent.ksql.GenericRow) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) Schema(org.apache.kafka.connect.data.Schema) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 50 with GenericRow

use of io.confluent.ksql.GenericRow in project ksql by confluentinc.

the class StreamsSelectAndProjectIntTest method testSelectStar.

private void testSelectStar(String resultStream, String inputStreamName, DataSource.DataSourceSerDe dataSourceSerDe) throws Exception {
    ksqlContext.sql(String.format("CREATE STREAM %s AS SELECT * FROM %s;", resultStream, inputStreamName));
    Map<String, GenericRow> easyOrdersData = testHarness.consumeData(resultStream, dataProvider.schema(), dataProvider.data().size(), new StringDeserializer(), IntegrationTestHarness.RESULTS_POLL_MAX_TIME_MS, dataSourceSerDe);
    assertThat(easyOrdersData, equalTo(dataProvider.data()));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer)

Aggregations

GenericRow (io.confluent.ksql.GenericRow)65 Test (org.junit.Test)38 HashMap (java.util.HashMap)27 Schema (org.apache.kafka.connect.data.Schema)19 List (java.util.List)15 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)15 ArrayList (java.util.ArrayList)11 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)9 IntegrationTest (io.confluent.common.utils.IntegrationTest)8 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 KsqlTopicSerDe (io.confluent.ksql.serde.KsqlTopicSerDe)5 KafkaTopicClient (io.confluent.ksql.util.KafkaTopicClient)5 KafkaTopicClientImpl (io.confluent.ksql.util.KafkaTopicClientImpl)5 KsqlConfig (io.confluent.ksql.util.KsqlConfig)5 Map (java.util.Map)5 GenericRecord (org.apache.avro.generic.GenericRecord)4 Windowed (org.apache.kafka.streams.kstream.Windowed)4 KafkaAvroDeserializer (io.confluent.kafka.serializers.KafkaAvroDeserializer)3 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)3