Search in sources :

Example 6 with FieldInfo

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

the class EntityUtilTest method shouldSupportRowTimeAndKeyInValueSchema.

@Test
public void shouldSupportRowTimeAndKeyInValueSchema() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().valueColumn(ColumnName.of("ROWKEY"), SqlTypes.STRING).valueColumn(ColumnName.of("ROWTIME"), SqlTypes.INTEGER).valueColumn(ColumnName.of("field1"), SqlTypes.INTEGER).build();
    // When:
    final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
    // Then:
    assertThat(fields, hasSize(3));
    assertThat(fields.get(0).getName(), equalTo("ROWKEY"));
    assertThat(fields.get(0).getType(), equalTo(Optional.empty()));
    assertThat(fields.get(1).getName(), equalTo("ROWTIME"));
    assertThat(fields.get(1).getType(), equalTo(Optional.empty()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 7 with FieldInfo

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

the class ConsoleTest method buildSourceDescription.

private SourceDescription buildSourceDescription(final List<RunningQuery> readQueries, final List<RunningQuery> writeQueries, final List<FieldInfo> fields, final boolean withClusterStats) {
    final Stat STAT = new Stat("TEST", 0, 1596644936314L);
    final Stat ERROR_STAT = new Stat("ERROR", 0, 1596644936314L);
    List<QueryHostStat> statistics = IntStream.range(1, 5).boxed().map((i) -> new KsqlHostInfoEntity("host" + i, 8000 + i)).map((host) -> QueryHostStat.fromStat(STAT, host)).collect(Collectors.toList());
    List<QueryHostStat> errors = IntStream.range(1, 5).boxed().map((i) -> new KsqlHostInfoEntity("host" + i, 8000 + i)).map((host) -> QueryHostStat.fromStat(ERROR_STAT, host)).collect(Collectors.toList());
    return new SourceDescription("TestSource", Optional.empty(), readQueries, writeQueries, fields, DataSourceType.KTABLE.getKsqlType(), "2000-01-01", "stats", "errors", true, "kafka", "avro", "kafka-topic", 1, 1, "sql statement", Collections.emptyList(), Collections.emptyList(), withClusterStats ? statistics : ImmutableList.of(), withClusterStats ? errors : ImmutableList.of());
}
Also used : StreamsList(io.confluent.ksql.rest.entity.StreamsList) ColumnName(io.confluent.ksql.name.ColumnName) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) SimpleConnectorPluginInfo(io.confluent.ksql.rest.entity.SimpleConnectorPluginInfo) KsqlQueryType(io.confluent.ksql.util.KsqlConstants.KsqlQueryType) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) StringUtils(org.apache.commons.lang3.StringUtils) Type(io.confluent.ksql.query.QueryError.Type) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) MockitoAnnotations(org.mockito.MockitoAnnotations) SchemaInfo(io.confluent.ksql.rest.entity.SchemaInfo) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) QueryId(io.confluent.ksql.query.QueryId) ConnectorType(org.apache.kafka.connect.runtime.rest.entities.ConnectorType) ClassRule(org.junit.ClassRule) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) TypeList(io.confluent.ksql.rest.entity.TypeList) EnumMap(java.util.EnumMap) ConnectorState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.ConnectorState) ArgumentInfo(io.confluent.ksql.rest.entity.ArgumentInfo) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) TopicDescription(io.confluent.ksql.rest.entity.TopicDescription) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) TimezoneRule(io.confluent.ksql.test.util.TimezoneRule) DropConnectorEntity(io.confluent.ksql.rest.entity.DropConnectorEntity) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) FunctionDescriptionList(io.confluent.ksql.rest.entity.FunctionDescriptionList) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Stat(io.confluent.ksql.metrics.TopicSensors.Stat) Supplier(java.util.function.Supplier) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) StreamsTaskMetadata(io.confluent.ksql.rest.entity.StreamsTaskMetadata) NoOpRowCaptor(io.confluent.ksql.cli.console.Console.NoOpRowCaptor) FakeException(io.confluent.ksql.FakeException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CliSpecificCommand(io.confluent.ksql.cli.console.cmd.CliSpecificCommand) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Before(org.junit.Before) IOException(java.io.IOException) Test(org.junit.Test) Mockito.never(org.mockito.Mockito.never) ConsumerPartitionOffsets(io.confluent.ksql.rest.entity.ConsumerPartitionOffsets) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) ConnectorPluginsList(io.confluent.ksql.rest.entity.ConnectorPluginsList) QueryOffsetSummary(io.confluent.ksql.rest.entity.QueryOffsetSummary) TestTerminal(io.confluent.ksql.TestTerminal) TaskState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.TaskState) QueryTopicOffsetSummary(io.confluent.ksql.rest.entity.QueryTopicOffsetSummary) CommandId(io.confluent.ksql.rest.entity.CommandId) GenericRow.genericRow(io.confluent.ksql.GenericRow.genericRow) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) Approvals(org.approvaltests.Approvals) After(org.junit.After) ExecutionPlan(io.confluent.ksql.rest.entity.ExecutionPlan) EntityUtil(io.confluent.ksql.rest.util.EntityUtil) Parameterized(org.junit.runners.Parameterized) ImmutableSet(com.google.common.collect.ImmutableSet) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) ImmutableMap(com.google.common.collect.ImmutableMap) Errors(io.confluent.ksql.rest.Errors) TimeZone(java.util.TimeZone) Collection(java.util.Collection) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Collectors(java.util.stream.Collectors) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) List(java.util.List) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo) ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) Options(org.approvaltests.core.Options) Optional(java.util.Optional) KsqlConstants(io.confluent.ksql.util.KsqlConstants) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) TerminateQueryEntity(io.confluent.ksql.rest.entity.TerminateQueryEntity) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) QueryError(io.confluent.ksql.query.QueryError) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) FunctionType(io.confluent.ksql.rest.entity.FunctionType) ImmutableList(com.google.common.collect.ImmutableList) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) Queries(io.confluent.ksql.rest.entity.Queries) TablesList(io.confluent.ksql.rest.entity.TablesList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Mockito.when(org.mockito.Mockito.when) Property(io.confluent.ksql.rest.entity.PropertiesList.Property) Mockito.verify(org.mockito.Mockito.verify) SourceInfo(io.confluent.ksql.rest.entity.SourceInfo) Collections(java.util.Collections) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) Stat(io.confluent.ksql.metrics.TopicSensors.Stat) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription)

Example 8 with FieldInfo

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

the class ConsoleTest method testPrintSourceDescriptionWithExtractedHeader.

@Test
public void testPrintSourceDescriptionWithExtractedHeader() {
    // Given:
    final List<FieldInfo> fields = buildTestSchema(Optional.of("abc"), SqlTypes.BOOLEAN, SqlTypes.INTEGER, SqlTypes.BIGINT, SqlTypes.DOUBLE, SqlTypes.STRING, SqlTypes.array(SqlTypes.STRING), SqlTypes.map(SqlTypes.STRING, SqlTypes.BIGINT), SqlTypes.struct().field("a", SqlTypes.DOUBLE).build());
    final List<RunningQuery> readQueries = ImmutableList.of(new RunningQuery("read query", ImmutableSet.of("sink1"), ImmutableSet.of("sink1 topic"), new QueryId("readId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final List<RunningQuery> writeQueries = ImmutableList.of(new RunningQuery("write query", ImmutableSet.of("sink2"), ImmutableSet.of("sink2 topic"), new QueryId("writeId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final KsqlEntityList entityList = new KsqlEntityList(ImmutableList.of(new SourceDescriptionEntity("some sql", buildSourceDescription(readQueries, writeQueries, fields, false), Collections.emptyList())));
    // When:
    console.printKsqlEntityList(entityList);
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) QueryId(io.confluent.ksql.query.QueryId) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 9 with FieldInfo

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

the class ConsoleTest method testPrintSourceDescriptionWithClusterStats.

@Test
public void testPrintSourceDescriptionWithClusterStats() {
    // Given:
    final List<FieldInfo> fields = buildTestSchema(SqlTypes.BOOLEAN, SqlTypes.INTEGER, SqlTypes.BIGINT, SqlTypes.DOUBLE, SqlTypes.STRING, SqlTypes.array(SqlTypes.STRING), SqlTypes.map(SqlTypes.STRING, SqlTypes.BIGINT), SqlTypes.struct().field("a", SqlTypes.DOUBLE).build());
    final List<RunningQuery> readQueries = ImmutableList.of(new RunningQuery("read query", ImmutableSet.of("sink1"), ImmutableSet.of("sink1 topic"), new QueryId("readId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final List<RunningQuery> writeQueries = ImmutableList.of(new RunningQuery("write query", ImmutableSet.of("sink2"), ImmutableSet.of("sink2 topic"), new QueryId("writeId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final KsqlEntityList entityList = new KsqlEntityList(ImmutableList.of(new SourceDescriptionEntity("some sql", buildSourceDescription(readQueries, writeQueries, fields, true), Collections.emptyList())));
    // When:
    console.printKsqlEntityList(entityList);
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) QueryId(io.confluent.ksql.query.QueryId) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 10 with FieldInfo

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

the class ConsoleTest method testPrintSourceDescriptionWithHeaders.

@Test
public void testPrintSourceDescriptionWithHeaders() {
    // Given:
    final List<FieldInfo> fields = buildTestSchema(Optional.empty(), SqlTypes.BOOLEAN, SqlTypes.INTEGER, SqlTypes.BIGINT, SqlTypes.DOUBLE, SqlTypes.STRING, SqlTypes.array(SqlTypes.STRING), SqlTypes.map(SqlTypes.STRING, SqlTypes.BIGINT), SqlTypes.struct().field("a", SqlTypes.DOUBLE).build());
    final List<RunningQuery> readQueries = ImmutableList.of(new RunningQuery("read query", ImmutableSet.of("sink1"), ImmutableSet.of("sink1 topic"), new QueryId("readId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final List<RunningQuery> writeQueries = ImmutableList.of(new RunningQuery("write query", ImmutableSet.of("sink2"), ImmutableSet.of("sink2 topic"), new QueryId("writeId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final KsqlEntityList entityList = new KsqlEntityList(ImmutableList.of(new SourceDescriptionEntity("some sql", buildSourceDescription(readQueries, writeQueries, fields, false), Collections.emptyList())));
    // When:
    console.printKsqlEntityList(entityList);
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) QueryId(io.confluent.ksql.query.QueryId) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Aggregations

FieldInfo (io.confluent.ksql.rest.entity.FieldInfo)22 Test (org.junit.Test)20 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)13 QueryId (io.confluent.ksql.query.QueryId)8 RunningQuery (io.confluent.ksql.rest.entity.RunningQuery)8 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)7 SourceDescriptionEntity (io.confluent.ksql.rest.entity.SourceDescriptionEntity)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 SchemaInfo (io.confluent.ksql.rest.entity.SchemaInfo)5 QueryError (io.confluent.ksql.query.QueryError)3 QueryDescription (io.confluent.ksql.rest.entity.QueryDescription)3 QueryDescriptionEntity (io.confluent.ksql.rest.entity.QueryDescriptionEntity)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BaseApiTest (io.confluent.ksql.api.BaseApiTest)2 CliSpecificCommand (io.confluent.ksql.cli.console.cmd.CliSpecificCommand)2 Stat (io.confluent.ksql.metrics.TopicSensors.Stat)2 ArgumentInfo (io.confluent.ksql.rest.entity.ArgumentInfo)2 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)2