Search in sources :

Example 16 with FieldInfo

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

the class EntityUtilTest method shouldBuildCorrectArrayField.

@Test
public void shouldBuildCorrectArrayField() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().valueColumn(ColumnName.of("field"), SqlTypes.array(SqlTypes.BIGINT)).build();
    // When:
    final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
    // Then:
    assertThat(fields, hasSize(1));
    assertThat(fields.get(0).getName(), equalTo("field"));
    assertThat(fields.get(0).getSchema().getTypeName(), equalTo("ARRAY"));
    assertThat(fields.get(0).getSchema().getFields(), equalTo(Optional.empty()));
    assertThat(fields.get(0).getSchema().getMemberSchema().get().getTypeName(), equalTo("BIGINT"));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 17 with FieldInfo

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

the class EntityUtilTest method shouldBuildCorrectStructField.

@Test
public void shouldBuildCorrectStructField() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().valueColumn(ColumnName.of("field"), SqlTypes.struct().field("innerField", SqlTypes.STRING).build()).build();
    // When:
    final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
    // Then:
    assertThat(fields, hasSize(1));
    assertThat(fields.get(0).getName(), equalTo("field"));
    assertThat(fields.get(0).getSchema().getTypeName(), equalTo("STRUCT"));
    assertThat(fields.get(0).getSchema().getFields().get().size(), equalTo(1));
    final FieldInfo inner = fields.get(0).getSchema().getFields().get().get(0);
    assertThat(inner.getSchema().getTypeName(), equalTo("STRING"));
    assertThat(inner.getType(), equalTo(Optional.empty()));
    assertThat(fields.get(0).getSchema().getMemberSchema(), equalTo(Optional.empty()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 18 with FieldInfo

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

the class EntityUtilTest method shouldMaintainColumnOrder.

@Test
public void shouldMaintainColumnOrder() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().valueColumn(ColumnName.of("field0"), SqlTypes.DOUBLE).keyColumn(ColumnName.of("field1"), SqlTypes.INTEGER).build();
    // When:
    final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
    // Then:
    assertThat(fields, hasSize(2));
    assertThat(fields.get(0).getName(), equalTo("field0"));
    assertThat(fields.get(0).getSchema().getTypeName(), equalTo("DOUBLE"));
    assertThat(fields.get(1).getName(), equalTo("field1"));
    assertThat(fields.get(1).getSchema().getTypeName(), equalTo("INTEGER"));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 19 with FieldInfo

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

the class EntityUtilTest method shouldBuildCorrectDecimalField.

@Test
public void shouldBuildCorrectDecimalField() {
    // Given:
    final SqlDecimal decimal = SqlTypes.decimal(10, 9);
    final LogicalSchema schema = LogicalSchema.builder().valueColumn(ColumnName.of("field"), decimal).build();
    // When:
    final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
    // Then:
    assertThat(fields, hasSize(1));
    assertThat(fields.get(0).getName(), equalTo("field"));
    assertThat(fields.get(0).getSchema().getTypeName(), equalTo("DECIMAL"));
    assertThat(fields.get(0).getSchema().getFields(), equalTo(Optional.empty()));
    assertThat(fields.get(0).getSchema().getParameters().get(SqlDecimal.SCALE), equalTo(decimal.getScale()));
    assertThat(fields.get(0).getSchema().getParameters().get(SqlDecimal.PRECISION), equalTo(decimal.getPrecision()));
}
Also used : SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 20 with FieldInfo

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

the class EntityUtilTest method shouldBuildCorrectMapField.

@Test
public void shouldBuildCorrectMapField() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().valueColumn(ColumnName.of("field"), SqlTypes.map(SqlTypes.BIGINT, SqlTypes.INTEGER)).build();
    // When:
    final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
    // Then:
    assertThat(fields, hasSize(1));
    assertThat(fields.get(0).getName(), equalTo("field"));
    assertThat(fields.get(0).getSchema().getTypeName(), equalTo("MAP"));
    assertThat(fields.get(0).getSchema().getFields(), equalTo(Optional.empty()));
    assertThat(fields.get(0).getSchema().getMemberSchema().get().getTypeName(), equalTo("INTEGER"));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) 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