Search in sources :

Example 1 with QueryStatusCount

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

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

the class ClientTest method shouldDescribeSourceWithoutSourceConstraints.

@Test
public void shouldDescribeSourceWithoutSourceConstraints() throws Exception {
    // Given
    final LegacySourceDescription sd = new LegacySourceDescription("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());
    final LegacySourceDescriptionEntity entity = new LegacySourceDescriptionEntity("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().size(), is(0));
}
Also used : RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) QueryId(io.confluent.ksql.query.QueryId) PushQueryId(io.confluent.ksql.rest.entity.PushQueryId) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) 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 3 with QueryStatusCount

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

the class ClientTest method shouldListQueries.

@Test
public void shouldListQueries() throws Exception {
    // Given
    final List<RunningQuery> expectedQueries = new ArrayList<>();
    expectedQueries.add(new RunningQuery("sql1", ImmutableSet.of("sink"), ImmutableSet.of("sink_topic"), new QueryId("a_persistent_query"), new QueryStatusCount(ImmutableMap.of(KsqlQueryStatus.RUNNING, 1)), KsqlQueryType.PERSISTENT));
    expectedQueries.add(new RunningQuery("sql2", Collections.emptySet(), Collections.emptySet(), new QueryId("a_push_query"), new QueryStatusCount(), KsqlQueryType.PUSH));
    final Queries entity = new Queries("list queries;", expectedQueries);
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    // When
    final List<QueryInfo> queries = javaClient.listQueries().get();
    // Then
    assertThat(queries, hasSize(expectedQueries.size()));
    assertThat(queries.get(0).getQueryType(), is(QueryType.PERSISTENT));
    assertThat(queries.get(0).getId(), is("a_persistent_query"));
    assertThat(queries.get(0).getSql(), is("sql1"));
    assertThat(queries.get(0).getSink(), is(Optional.of("sink")));
    assertThat(queries.get(0).getSinkTopic(), is(Optional.of("sink_topic")));
    assertThat(queries.get(1).getQueryType(), is(QueryType.PUSH));
    assertThat(queries.get(1).getId(), is("a_push_query"));
    assertThat(queries.get(1).getSql(), is("sql2"));
    assertThat(queries.get(1).getSink(), is(Optional.empty()));
    assertThat(queries.get(1).getSinkTopic(), is(Optional.empty()));
}
Also used : RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) Queries(io.confluent.ksql.rest.entity.Queries) QueryId(io.confluent.ksql.query.QueryId) PushQueryId(io.confluent.ksql.rest.entity.PushQueryId) ArrayList(java.util.ArrayList) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 4 with QueryStatusCount

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

the class ListQueriesExecutorTest method setup.

@Before
public void setup() throws MalformedURLException {
    // set to true so the tests don't perform the scatter gather by default
    when(sessionProperties.getInternalRequest()).thenReturn(true);
    when(sessionProperties.getKsqlHostInfo()).thenReturn(LOCAL_KSQL_HOST_INFO_ENTITY.toKsqlHost());
    when(sessionProperties.getLocalUrl()).thenReturn(new URL("https://address"));
    queryStatusCount = new QueryStatusCount();
    when(ksqlClient.makeKsqlRequest(any(), any(), any())).thenReturn(response);
    when(response.isErroneous()).thenReturn(false);
    when(serviceContext.getKsqlClient()).thenReturn(ksqlClient);
}
Also used : QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) URL(java.net.URL) Before(org.junit.Before)

Example 5 with QueryStatusCount

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

Aggregations

QueryStatusCount (io.confluent.ksql.rest.entity.QueryStatusCount)5 RunningQuery (io.confluent.ksql.rest.entity.RunningQuery)4 Test (org.junit.Test)4 BaseApiTest (io.confluent.ksql.api.BaseApiTest)3 QueryId (io.confluent.ksql.query.QueryId)3 PushQueryId (io.confluent.ksql.rest.entity.PushQueryId)3 FieldInfo (io.confluent.ksql.rest.entity.FieldInfo)2 SchemaInfo (io.confluent.ksql.rest.entity.SchemaInfo)2 SourceDescriptionEntity (io.confluent.ksql.rest.entity.SourceDescriptionEntity)2 ExecuteResult (io.confluent.ksql.KsqlExecutionContext.ExecuteResult)1 DataSource (io.confluent.ksql.metastore.model.DataSource)1 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)1 ShowColumns (io.confluent.ksql.parser.tree.ShowColumns)1 Queries (io.confluent.ksql.rest.entity.Queries)1 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1