Search in sources :

Example 1 with QueryDescriptionEntity

use of io.confluent.ksql.rest.entity.QueryDescriptionEntity in project ksql by confluentinc.

the class KsqlResourceTest method shouldExplainQueryStatement.

@Test
public void shouldExplainQueryStatement() {
    // Given:
    final String ksqlQueryString = "SELECT * FROM test_stream EMIT CHANGES;";
    final String ksqlString = "EXPLAIN " + ksqlQueryString;
    // When:
    final QueryDescriptionEntity query = makeSingleRequest(ksqlString, QueryDescriptionEntity.class);
    // Then:
    validateTransientQueryDescription(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 2 with QueryDescriptionEntity

use of io.confluent.ksql.rest.entity.QueryDescriptionEntity in project ksql by confluentinc.

the class KsqlResourceTest method shouldExplainQueryId.

@Test
public void shouldExplainQueryId() {
    // Given:
    final Map<String, Object> overriddenProperties = Collections.singletonMap("ksql.streams.auto.offset.reset", "earliest");
    final PersistentQueryMetadata queryMetadata = createQuery("CREATE STREAM test_explain AS SELECT * FROM test_stream;", overriddenProperties);
    // When:
    final QueryDescriptionEntity query = makeSingleRequest("EXPLAIN " + queryMetadata.getQueryId() + ";", QueryDescriptionEntity.class);
    // Then:
    validateQueryDescription(queryMetadata, overriddenProperties, query);
}
Also used : QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Test(org.junit.Test)

Example 3 with QueryDescriptionEntity

use of io.confluent.ksql.rest.entity.QueryDescriptionEntity in project ksql by confluentinc.

the class ConsoleTest method shouldPrintExplainQueryWithError.

@Test
public void shouldPrintExplainQueryWithError() {
    final long timestamp = 1596644936314L;
    // Given:
    final QueryDescriptionEntity queryEntity = new QueryDescriptionEntity("statement", new QueryDescription(new QueryId("id"), "statement", Optional.empty(), ImmutableList.of(new FieldInfo("name", new SchemaInfo(SqlBaseType.STRING, ImmutableList.of(), null), Optional.empty())), ImmutableSet.of("source"), ImmutableSet.of("sink"), "topology", "executionPlan", ImmutableMap.of("overridden.prop", 42), ImmutableMap.of(new KsqlHostInfoEntity("foo", 123), KsqlQueryStatus.ERROR), KsqlQueryType.PERSISTENT, ImmutableList.of(new QueryError(timestamp, "error", Type.SYSTEM)), ImmutableSet.of(new StreamsTaskMetadata("test", Collections.emptySet(), Optional.empty())), "consumerGroupId"));
    final KsqlEntityList entityList = new KsqlEntityList(ImmutableList.of(queryEntity));
    // When:
    console.printKsqlEntityList(entityList);
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) QueryId(io.confluent.ksql.query.QueryId) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) QueryError(io.confluent.ksql.query.QueryError) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) StreamsTaskMetadata(io.confluent.ksql.rest.entity.StreamsTaskMetadata) SchemaInfo(io.confluent.ksql.rest.entity.SchemaInfo) Test(org.junit.Test)

Example 4 with QueryDescriptionEntity

use of io.confluent.ksql.rest.entity.QueryDescriptionEntity in project ksql by confluentinc.

the class ExplainExecutorTest method shouldExplainStatement.

@Test
public void shouldExplainStatement() {
    // Given:
    engine.givenSource(DataSourceType.KSTREAM, "Y");
    final String statementText = "SELECT * 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"));
    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 5 with QueryDescriptionEntity

use of io.confluent.ksql.rest.entity.QueryDescriptionEntity in project ksql by confluentinc.

the class ExplainExecutorTest method shouldExplainQueryId.

@Test
public void shouldExplainQueryId() {
    // Given:
    final ConfiguredStatement<Explain> explain = (ConfiguredStatement<Explain>) engine.configure("EXPLAIN id;");
    final PersistentQueryMetadata metadata = givenPersistentQuery("id");
    final KsqlEngine engine = mock(KsqlEngine.class);
    when(engine.getPersistentQuery(metadata.getQueryId())).thenReturn(Optional.of(metadata));
    // When:
    final QueryDescriptionEntity query = (QueryDescriptionEntity) customExecutors.explain().execute(explain, sessionProperties, engine, this.engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(query.getQueryDescription(), equalTo(QueryDescriptionFactory.forQueryMetadata(metadata, Collections.singletonMap(new KsqlHostInfoEntity(LOCAL_HOST), STATE))));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) Explain(io.confluent.ksql.parser.tree.Explain) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) 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