use of io.confluent.ksql.rest.entity.SourceDescriptionEntity in project ksql by confluentinc.
the class ListSourceExecutorTest method shouldShowColumnsSource.
@Test
public void shouldShowColumnsSource() {
// Given:
engine.givenSource(DataSourceType.KSTREAM, "SOURCE");
final ExecuteResult result = engine.getEngine().execute(engine.getServiceContext(), engine.configure("CREATE STREAM SINK AS SELECT * FROM source;"));
final PersistentQueryMetadata metadata = (PersistentQueryMetadata) result.getQuery().orElseThrow(IllegalArgumentException::new);
final DataSource stream = engine.getEngine().getMetaStore().getSource(SourceName.of("SINK"));
// When:
final SourceDescriptionEntity sourceDescription = (SourceDescriptionEntity) CUSTOM_EXECUTORS.showColumns().execute(ConfiguredStatement.of(PreparedStatement.of("DESCRIBE SINK;", new ShowColumns(SourceName.of("SINK"), false)), SessionConfig.of(engine.getKsqlConfig(), ImmutableMap.of())), SESSION_PROPERTIES, engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
// Then:
final QueryStatusCount queryStatusCount = QueryStatusCount.fromStreamsStateCounts(Collections.singletonMap(metadata.getState(), 1));
assertThat(sourceDescription.getSourceDescription(), equalTo(SourceDescriptionFactory.create(stream, false, ImmutableList.of(), ImmutableList.of(new RunningQuery(metadata.getStatementString(), ImmutableSet.of(metadata.getSinkName().get().toString(FormatOptions.noEscape())), ImmutableSet.of(metadata.getResultTopic().get().getKafkaTopicName()), metadata.getQueryId(), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT)), Optional.empty(), ImmutableList.of(), ImmutableList.of(), new MetricCollectors())));
}
use of io.confluent.ksql.rest.entity.SourceDescriptionEntity in project ksql by confluentinc.
the class ClientTest method shouldFailToDescribeSourceViaExecuteStatement.
@Test
public void shouldFailToDescribeSourceViaExecuteStatement() {
// Given
final SourceDescriptionEntity entity = new SourceDescriptionEntity("describe source;", new io.confluent.ksql.rest.entity.SourceDescription("name", Optional.empty(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), "type", "timestamp", "statistics", "errorStats", false, "keyFormat", "valueFormat", "topic", 4, 1, "statement", Collections.emptyList(), Collections.emptyList()), Collections.emptyList());
testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
// When
final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
ExecutionException.class, () -> javaClient.executeStatement("describe source;").get());
// Then
assertThat(e.getCause(), instanceOf(KsqlClientException.class));
assertThat(e.getCause().getMessage(), containsString(EXECUTE_STATEMENT_USAGE_DOC));
assertThat(e.getCause().getMessage(), containsString("does not currently support 'DESCRIBE <STREAM/TABLE>' statements"));
}
use of io.confluent.ksql.rest.entity.SourceDescriptionEntity in project ksql by confluentinc.
the class ClientTest method shouldDescribeSource.
@Test
public void shouldDescribeSource() throws Exception {
// Given
final io.confluent.ksql.rest.entity.SourceDescription sd = new io.confluent.ksql.rest.entity.SourceDescription("name", Optional.of(WindowType.TUMBLING), Collections.singletonList(new RunningQuery("query_sql", ImmutableSet.of("sink"), ImmutableSet.of("sink_topic"), new QueryId("a_persistent_query"), new QueryStatusCount(ImmutableMap.of(KsqlQueryStatus.RUNNING, 1)), KsqlQueryType.PERSISTENT)), Collections.emptyList(), ImmutableList.of(new FieldInfo("f1", new SchemaInfo(SqlBaseType.STRING, null, null), Optional.of(FieldType.KEY)), new FieldInfo("f2", new SchemaInfo(SqlBaseType.INTEGER, null, null), Optional.empty())), "TABLE", "", "", "", false, "KAFKA", "JSON", "topic", 4, 1, "sql", Collections.emptyList(), ImmutableList.of("s1", "s2"));
final SourceDescriptionEntity entity = new SourceDescriptionEntity("describe source;", sd, Collections.emptyList());
testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
// When
final SourceDescription description = javaClient.describeSource("source").get();
// Then
assertThat(description.name(), is("name"));
assertThat(description.type(), is("TABLE"));
assertThat(description.fields(), hasSize(2));
assertThat(description.fields().get(0).name(), is("f1"));
assertThat(description.fields().get(0).type().getType(), is(ColumnType.Type.STRING));
assertThat(description.fields().get(0).isKey(), is(true));
assertThat(description.fields().get(1).name(), is("f2"));
assertThat(description.fields().get(1).type().getType(), is(ColumnType.Type.INTEGER));
assertThat(description.fields().get(1).isKey(), is(false));
assertThat(description.topic(), is("topic"));
assertThat(description.keyFormat(), is("KAFKA"));
assertThat(description.valueFormat(), is("JSON"));
assertThat(description.readQueries(), hasSize(1));
assertThat(description.readQueries().get(0).getQueryType(), is(QueryType.PERSISTENT));
assertThat(description.readQueries().get(0).getId(), is("a_persistent_query"));
assertThat(description.readQueries().get(0).getSql(), is("query_sql"));
assertThat(description.readQueries().get(0).getSink(), is(Optional.of("sink")));
assertThat(description.readQueries().get(0).getSinkTopic(), is(Optional.of("sink_topic")));
assertThat(description.writeQueries(), hasSize(0));
assertThat(description.timestampColumn(), is(Optional.empty()));
assertThat(description.windowType(), is(Optional.of("TUMBLING")));
assertThat(description.sqlStatement(), is("sql"));
assertThat(description.getSourceConstraints(), hasItems("s1", "s2"));
}
use of io.confluent.ksql.rest.entity.SourceDescriptionEntity in project ksql by confluentinc.
the class ConsoleTest method shouldPrintWarnings.
@Test
public void shouldPrintWarnings() {
// Given:
final KsqlEntity entity = new SourceDescriptionEntity("e", sourceDescription, ImmutableList.of(new KsqlWarning("oops"), new KsqlWarning("doh!")));
// When:
console.printKsqlEntityList(ImmutableList.of(entity));
// Then:
final String output = terminal.getOutputString();
Approvals.verify(output, approvalOptions);
}
Aggregations