Search in sources :

Example 1 with QueryDescription

use of io.confluent.ksql.rest.entity.QueryDescription 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 2 with QueryDescription

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

the class ListQueriesExecutorTest method shouldNotMergeDifferentQueryDescriptions.

@Test
public void shouldNotMergeDifferentQueryDescriptions() {
    // Given
    when(sessionProperties.getInternalRequest()).thenReturn(false);
    final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES EXTENDED;");
    final PersistentQueryMetadata localMetadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
    final PersistentQueryMetadata remoteMetadata = givenPersistentQuery("different id", ERROR_QUERY_STATE);
    final KsqlEngine engine = mock(KsqlEngine.class);
    when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(localMetadata));
    when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(localMetadata));
    final Map<KsqlHostInfoEntity, KsqlQueryStatus> remoteMap = Collections.singletonMap(REMOTE_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.RUNNING);
    final List<QueryDescription> remoteQueryDescriptions = Collections.singletonList(QueryDescriptionFactory.forQueryMetadata(remoteMetadata, remoteMap));
    when(remoteQueryDescriptionList.getQueryDescriptions()).thenReturn(remoteQueryDescriptions);
    when(ksqlEntityList.get(anyInt())).thenReturn(remoteQueryDescriptionList);
    when(response.getResponse()).thenReturn(ksqlEntityList);
    // When
    final QueryDescriptionList queries = (QueryDescriptionList) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then
    assertThat(queries.getQueryDescriptions(), containsInAnyOrder(QueryDescriptionFactory.forQueryMetadata(localMetadata, LOCAL_KSQL_HOST_INFO_MAP), QueryDescriptionFactory.forQueryMetadata(remoteMetadata, remoteMap)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) ListQueries(io.confluent.ksql.parser.tree.ListQueries) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Test(org.junit.Test)

Example 3 with QueryDescription

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

the class ListQueriesExecutorTest method shouldScatterGatherAndMergeShowQueriesExtended.

@Test
public void shouldScatterGatherAndMergeShowQueriesExtended() {
    // Given
    when(sessionProperties.getInternalRequest()).thenReturn(false);
    final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES EXTENDED;");
    final StreamsTaskMetadata localTaskMetadata = mock(StreamsTaskMetadata.class);
    final StreamsTaskMetadata remoteTaskMetadata = mock(StreamsTaskMetadata.class);
    final PersistentQueryMetadata localMetadata = givenPersistentQuery("id", RUNNING_QUERY_STATE, Collections.singleton(localTaskMetadata));
    final PersistentQueryMetadata remoteMetadata = givenPersistentQuery("id", ERROR_QUERY_STATE, Collections.singleton(remoteTaskMetadata));
    final KsqlEngine engine = mock(KsqlEngine.class);
    when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(localMetadata));
    when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(localMetadata));
    final List<QueryDescription> remoteQueryDescriptions = Collections.singletonList(QueryDescriptionFactory.forQueryMetadata(remoteMetadata, Collections.singletonMap(REMOTE_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.ERROR)));
    when(remoteQueryDescriptionList.getQueryDescriptions()).thenReturn(remoteQueryDescriptions);
    when(ksqlEntityList.get(anyInt())).thenReturn(remoteQueryDescriptionList);
    when(response.getResponse()).thenReturn(ksqlEntityList);
    final Map<KsqlHostInfoEntity, KsqlQueryStatus> mergedMap = new HashMap<>();
    mergedMap.put(REMOTE_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.ERROR);
    mergedMap.put(LOCAL_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.RUNNING);
    // When
    final QueryDescriptionList queries = (QueryDescriptionList) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then
    final QueryDescription mergedQueryDescription = QueryDescriptionFactory.forQueryMetadata(localMetadata, mergedMap);
    mergedQueryDescription.updateTaskMetadata(Collections.singleton(remoteTaskMetadata));
    assertThat(queries.getQueryDescriptions(), containsInAnyOrder(mergedQueryDescription));
}
Also used : KsqlEngine(io.confluent.ksql.engine.KsqlEngine) HashMap(java.util.HashMap) ListQueries(io.confluent.ksql.parser.tree.ListQueries) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) StreamsTaskMetadata(io.confluent.ksql.rest.entity.StreamsTaskMetadata) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Test(org.junit.Test)

Example 4 with QueryDescription

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

the class ShowQueriesMultiNodeFunctionalTest method getShowQueriesExtendedResult.

private static QueryExtendedResults getShowQueriesExtendedResult(final TestKsqlRestApp restApp) {
    final List<KsqlEntity> results = RestIntegrationTestUtil.makeKsqlRequest(restApp, "Show Queries Extended;");
    if (results.size() != 1) {
        return new QueryExtendedResults();
    }
    final KsqlEntity result = results.get(0);
    if (!(result instanceof QueryDescriptionList)) {
        return new QueryExtendedResults();
    }
    final List<QueryDescription> queryDescriptions = ((QueryDescriptionList) result).getQueryDescriptions();
    if (queryDescriptions.size() != 1) {
        return new QueryExtendedResults();
    }
    return new QueryExtendedResults(queryDescriptions.get(0).getKsqlHostQueryStatus().keySet(), queryDescriptions.get(0).getTasksMetadata());
}
Also used : QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity)

Example 5 with QueryDescription

use of io.confluent.ksql.rest.entity.QueryDescription 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)

Aggregations

QueryDescription (io.confluent.ksql.rest.entity.QueryDescription)8 QueryDescriptionList (io.confluent.ksql.rest.entity.QueryDescriptionList)5 QueryDescriptionEntity (io.confluent.ksql.rest.entity.QueryDescriptionEntity)4 QueryId (io.confluent.ksql.query.QueryId)3 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)3 Test (org.junit.Test)3 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)2 ListQueries (io.confluent.ksql.parser.tree.ListQueries)2 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)2 StreamsTaskMetadata (io.confluent.ksql.rest.entity.StreamsTaskMetadata)2 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)2 KsqlQueryStatus (io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)2 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)2 Map (java.util.Map)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 Streams (com.google.common.collect.Streams)1 BaseApiTest (io.confluent.ksql.api.BaseApiTest)1