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));
}
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));
}
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));
}
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());
}
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()));
}
Aggregations