use of io.confluent.ksql.rest.entity.QueryDescriptionEntity in project ksql by confluentinc.
the class ExplainExecutorTest method shouldExplainStatementWithStructFieldDereference.
@Test
public void shouldExplainStatementWithStructFieldDereference() {
// Given:
engine.givenSource(DataSourceType.KSTREAM, "Y");
final String statementText = "SELECT address->street FROM Y EMIT CHANGES;";
final ConfiguredStatement<Explain> explain = (ConfiguredStatement<Explain>) engine.configure("EXPLAIN " + statementText);
// When:
final QueryDescriptionEntity query = (QueryDescriptionEntity) customExecutors.explain().execute(explain, sessionProperties, engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
// Then:
assertThat(query.getQueryDescription().getStatementText(), equalTo(statementText));
assertThat(query.getQueryDescription().getSources(), containsInAnyOrder("Y"));
}
use of io.confluent.ksql.rest.entity.QueryDescriptionEntity in project ksql by confluentinc.
the class ExplainExecutorTest method shouldExplainPersistentStatement.
@Test
public void shouldExplainPersistentStatement() {
// Given:
engine.givenSource(DataSourceType.KSTREAM, "Y");
final String statementText = "CREATE STREAM X AS SELECT * FROM Y;";
final ConfiguredStatement<Explain> explain = (ConfiguredStatement<Explain>) engine.configure("EXPLAIN " + statementText);
// When:
final QueryDescriptionEntity query = (QueryDescriptionEntity) customExecutors.explain().execute(explain, sessionProperties, engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
// Then:
assertThat(query.getQueryDescription().getStatementText(), equalTo(statementText));
assertThat(query.getQueryDescription().getSources(), containsInAnyOrder("Y"));
assertThat("No side effects should happen", engine.getEngine().getPersistentQueries(), is(empty()));
assertThat(query.getQueryDescription().getKsqlHostQueryStatus(), equalTo(Collections.emptyMap()));
}
use of io.confluent.ksql.rest.entity.QueryDescriptionEntity in project ksql by confluentinc.
the class KsqlResourceTest method validateQueryDescription.
private static void validateQueryDescription(final QueryMetadata queryMetadata, final Map<String, Object> overriddenProperties, final KsqlEntity entity) {
assertThat(entity, instanceOf(QueryDescriptionEntity.class));
final QueryDescriptionEntity queryDescriptionEntity = (QueryDescriptionEntity) entity;
final QueryDescription queryDescription = queryDescriptionEntity.getQueryDescription();
assertThat(queryDescription.getFields(), is(EntityUtil.buildSourceSchemaEntity(queryMetadata.getLogicalSchema())));
assertThat(queryDescription.getOverriddenProperties(), is(overriddenProperties));
}
use of io.confluent.ksql.rest.entity.QueryDescriptionEntity in project ksql by confluentinc.
the class KsqlResourceTest method shouldExplainCreateAsSelectStatement.
@Test
public void shouldExplainCreateAsSelectStatement() {
// Given:
final String ksqlQueryString = "CREATE STREAM S3 AS SELECT * FROM test_stream;";
final String ksqlString = "EXPLAIN " + ksqlQueryString;
// When:
final QueryDescriptionEntity query = makeSingleRequest(ksqlString, QueryDescriptionEntity.class);
// Then:
assertThat("Should not have registered the source", metaStore.getSource(SourceName.of("S3")), is(nullValue()));
validateQueryDescription(ksqlQueryString, emptyMap(), query);
}
use of io.confluent.ksql.rest.entity.QueryDescriptionEntity in project ksql by confluentinc.
the class ClientTest method shouldFailToExplainQueryViaExecuteStatement.
@Test
public void shouldFailToExplainQueryViaExecuteStatement() {
// Given
final QueryDescriptionEntity entity = new QueryDescriptionEntity("explain query;", new QueryDescription(new QueryId("id"), "sql", Optional.empty(), Collections.emptyList(), Collections.emptySet(), Collections.emptySet(), "topology", "executionPlan", Collections.emptyMap(), Collections.emptyMap(), KsqlQueryType.PERSISTENT, Collections.emptyList(), Collections.emptySet(), "consumerGroupId"));
testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
// When
final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
ExecutionException.class, () -> javaClient.executeStatement("explain query;").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 'EXPLAIN <QUERY_ID>' statements"));
}
Aggregations