public static KsqlTopicsList build( final String statementText, final Collection<KsqlTopic> ksqlTopics) { final List<KsqlTopicInfo> ksqlTopicInfoList = new ArrayList<>(); for (final KsqlTopic ksqlTopic: ksqlTopics) { ksqlTopicInfoList.add(new KsqlTopicInfo(ksqlTopic)); } return new KsqlTopicsList(statementText, ksqlTopicInfoList); }
@Override public int hashCode() { return Objects.hash(getName(), getKafkaTopic(), getFormat()); } }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof KsqlTopicInfo)) { return false; } final KsqlTopicInfo topicInfo = (KsqlTopicInfo) o; return Objects.equals(getName(), topicInfo.getName()) && Objects.equals(getKafkaTopic(), topicInfo.getKafkaTopic()) && getFormat() == topicInfo.getFormat(); }
@Test public void testSerde() throws Exception { final ObjectMapper mapper = JsonMapper.INSTANCE.mapper; final KsqlTopicsList expected = new KsqlTopicsList( "SHOW TOPICS;", ImmutableList.of(new KsqlTopicInfo("ksqltopic", "kafkatopic", DataSourceSerDe.JSON)) ); final String json = mapper.writeValueAsString(expected); assertEquals( "{\"@type\":\"ksql_topics\",\"statementText\":\"SHOW TOPICS;\"," + "\"topics\":[{\"name\":\"ksqltopic\",\"kafkaTopic\":\"kafkatopic\",\"format\":\"JSON\"}]}", json); final KsqlTopicsList actual = mapper.readValue(json, KsqlTopicsList.class); assertEquals(expected, actual); } }
@Override public Table buildTable(final KsqlTopicsList entity) { final Stream<List<String>> rows = entity.getTopics().stream() .map(t -> ImmutableList.of(t.getName(), t.getKafkaTopic(), t.getFormat().name())); return new Builder() .withColumnHeaders(HEADERS) .withRows(rows) .build(); } }
new StreamsList("e", ImmutableList.of(new SourceInfo.Stream("TestStream", "TestTopic", "AVRO"))), new TablesList("e", ImmutableList.of(new SourceInfo.Table("TestTable", "TestTopic", "JSON", false))), new KsqlTopicsList("e", ImmutableList.of(new KsqlTopicInfo("TestTopic", "TestKafkaTopic", DataSource.DataSourceSerDe.JSON))), new KafkaTopicsList("e", ImmutableList.of(new KafkaTopicInfo("TestKafkaTopic", true, ImmutableList.of(1), 1, 1))), new ExecutionPlan("Test Execution Plan")