Search in sources :

Example 11 with SourceDescriptionEntity

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())));
}
Also used : RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) ShowColumns(io.confluent.ksql.parser.tree.ShowColumns) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) ExecuteResult(io.confluent.ksql.KsqlExecutionContext.ExecuteResult) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 12 with SourceDescriptionEntity

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"));
}
Also used : KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) KsqlApiException(io.confluent.ksql.api.server.KsqlApiException) ExecutionException(java.util.concurrent.ExecutionException) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) KsqlException(io.confluent.ksql.api.client.exception.KsqlException) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 13 with SourceDescriptionEntity

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"));
}
Also used : QueryId(io.confluent.ksql.query.QueryId) PushQueryId(io.confluent.ksql.rest.entity.PushQueryId) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) SchemaInfo(io.confluent.ksql.rest.entity.SchemaInfo) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 14 with SourceDescriptionEntity

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);
}
Also used : SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) Matchers.containsString(org.hamcrest.Matchers.containsString) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) Test(org.junit.Test)

Aggregations

SourceDescriptionEntity (io.confluent.ksql.rest.entity.SourceDescriptionEntity)14 Test (org.junit.Test)12 RunningQuery (io.confluent.ksql.rest.entity.RunningQuery)8 QueryId (io.confluent.ksql.query.QueryId)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 FieldInfo (io.confluent.ksql.rest.entity.FieldInfo)5 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)5 BaseApiTest (io.confluent.ksql.api.BaseApiTest)3 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)3 ShowColumns (io.confluent.ksql.parser.tree.ShowColumns)3 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)3 KsqlWarning (io.confluent.ksql.rest.entity.KsqlWarning)2 QueryStatusCount (io.confluent.ksql.rest.entity.QueryStatusCount)2 SourceDescription (io.confluent.ksql.rest.entity.SourceDescription)2 ExecuteResult (io.confluent.ksql.KsqlExecutionContext.ExecuteResult)1 KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)1 KsqlException (io.confluent.ksql.api.client.exception.KsqlException)1 KsqlApiException (io.confluent.ksql.api.server.KsqlApiException)1 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 DataSource (io.confluent.ksql.metastore.model.DataSource)1