Search in sources :

Example 6 with QueryDescriptionEntity

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"));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) Explain(io.confluent.ksql.parser.tree.Explain) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 7 with QueryDescriptionEntity

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()));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) Explain(io.confluent.ksql.parser.tree.Explain) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 8 with QueryDescriptionEntity

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));
}
Also used : QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription)

Example 9 with QueryDescriptionEntity

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);
}
Also used : QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 10 with QueryDescriptionEntity

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"));
}
Also used : QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) QueryId(io.confluent.ksql.query.QueryId) PushQueryId(io.confluent.ksql.rest.entity.PushQueryId) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) 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)

Aggregations

QueryDescriptionEntity (io.confluent.ksql.rest.entity.QueryDescriptionEntity)10 Test (org.junit.Test)9 Explain (io.confluent.ksql.parser.tree.Explain)4 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 QueryDescription (io.confluent.ksql.rest.entity.QueryDescription)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 QueryId (io.confluent.ksql.query.QueryId)2 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)2 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)2 BaseApiTest (io.confluent.ksql.api.BaseApiTest)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 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)1 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)1 QueryError (io.confluent.ksql.query.QueryError)1 FieldInfo (io.confluent.ksql.rest.entity.FieldInfo)1