Search in sources :

Example 1 with SchemaInfo

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

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

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

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

the class ListTypesExecutor method execute.

public static StatementExecutorResponse execute(final ConfiguredStatement<ListTypes> configuredStatement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
    final ImmutableMap.Builder<String, SchemaInfo> types = ImmutableMap.builder();
    final Iterator<CustomType> customTypes = executionContext.getMetaStore().types();
    while (customTypes.hasNext()) {
        final CustomType customType = customTypes.next();
        types.put(customType.getName(), EntityUtil.schemaInfo(customType.getType()));
    }
    return StatementExecutorResponse.handled(Optional.of(new TypeList(configuredStatement.getStatementText(), types.build())));
}
Also used : CustomType(io.confluent.ksql.metastore.TypeRegistry.CustomType) ImmutableMap(com.google.common.collect.ImmutableMap) TypeList(io.confluent.ksql.rest.entity.TypeList) SchemaInfo(io.confluent.ksql.rest.entity.SchemaInfo)

Example 5 with SchemaInfo

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

the class ConsoleTest method shouldPrintTypesList.

@Test
public void shouldPrintTypesList() {
    // Given:
    final KsqlEntityList entities = new KsqlEntityList(ImmutableList.of(new TypeList("statement", ImmutableMap.of("typeB", new SchemaInfo(SqlBaseType.ARRAY, null, new SchemaInfo(SqlBaseType.STRING, null, null)), "typeA", new SchemaInfo(SqlBaseType.STRUCT, ImmutableList.of(new FieldInfo("f1", new SchemaInfo(SqlBaseType.STRING, null, null), Optional.empty())), null), "typeC", new SchemaInfo(SqlBaseType.DECIMAL, null, null, ImmutableMap.of("precision", 10, "scale", 9))))));
    // When:
    console.printKsqlEntityList(entities);
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeList(io.confluent.ksql.rest.entity.TypeList) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) SchemaInfo(io.confluent.ksql.rest.entity.SchemaInfo) Test(org.junit.Test)

Aggregations

SchemaInfo (io.confluent.ksql.rest.entity.SchemaInfo)5 FieldInfo (io.confluent.ksql.rest.entity.FieldInfo)4 Test (org.junit.Test)4 QueryId (io.confluent.ksql.query.QueryId)3 BaseApiTest (io.confluent.ksql.api.BaseApiTest)2 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)2 PushQueryId (io.confluent.ksql.rest.entity.PushQueryId)2 QueryStatusCount (io.confluent.ksql.rest.entity.QueryStatusCount)2 RunningQuery (io.confluent.ksql.rest.entity.RunningQuery)2 TypeList (io.confluent.ksql.rest.entity.TypeList)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 CustomType (io.confluent.ksql.metastore.TypeRegistry.CustomType)1 QueryError (io.confluent.ksql.query.QueryError)1 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)1 QueryDescription (io.confluent.ksql.rest.entity.QueryDescription)1 QueryDescriptionEntity (io.confluent.ksql.rest.entity.QueryDescriptionEntity)1 SourceDescriptionEntity (io.confluent.ksql.rest.entity.SourceDescriptionEntity)1 StreamsTaskMetadata (io.confluent.ksql.rest.entity.StreamsTaskMetadata)1