Search in sources :

Example 86 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class TableElementsTest method shouldBuildLogicalSchemaWithWithExtractedHeader.

@Test
public void shouldBuildLogicalSchemaWithWithExtractedHeader() {
    // Given:
    final TableElements tableElements = TableElements.of(tableElement("v0", INT_TYPE), tableElement("h0", BYTES_TYPE, new Builder().header("key").build()));
    // When:
    final LogicalSchema schema = tableElements.toLogicalSchema();
    // Then:
    assertThat(schema, is(LogicalSchema.builder().valueColumn(ColumnName.of("v0"), SqlTypes.INTEGER).headerColumn(ColumnName.of("h0"), Optional.of("key")).build()));
}
Also used : Builder(io.confluent.ksql.parser.tree.ColumnConstraints.Builder) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 87 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class TableElementsTest method shouldBuildLogicalSchemaWithWithHeaders.

@Test
public void shouldBuildLogicalSchemaWithWithHeaders() {
    // Given:
    final TableElements tableElements = TableElements.of(tableElement("v0", INT_TYPE), tableElement("h0", new Type(SqlArray.of(SqlStruct.builder().field("KEY", SqlTypes.STRING).field("VALUE", SqlTypes.BYTES).build())), HEADERS_CONSTRAINT));
    // When:
    final LogicalSchema schema = tableElements.toLogicalSchema();
    // Then:
    assertThat(schema, is(LogicalSchema.builder().valueColumn(ColumnName.of("v0"), SqlTypes.INTEGER).headerColumn(ColumnName.of("h0"), Optional.empty()).build()));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 88 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class LogicalSchemaDeserializerTest method shouldDeserializeSchemaWithKeyAfterValue.

@Test
public void shouldDeserializeSchemaWithKeyAfterValue() throws Exception {
    // Given:
    final String json = "\"`v0` INTEGER, `key0` STRING KEY\"";
    // When:
    final LogicalSchema schema = MAPPER.readValue(json, LogicalSchema.class);
    // Then:
    assertThat(schema, is(LogicalSchema.builder().valueColumn(ColumnName.of("v0"), SqlTypes.INTEGER).keyColumn(ColumnName.of("key0"), SqlTypes.STRING).build()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 89 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class QueryStreamWriter method buildHeader.

private StreamedRow buildHeader() {
    final QueryId queryId = queryMetadata.getQueryId();
    // Push queries only return value columns, but query metadata schema includes key and meta:
    final LogicalSchema storedSchema = queryMetadata.getLogicalSchema();
    final Builder projectionSchema = LogicalSchema.builder();
    storedSchema.value().forEach(projectionSchema::valueColumn);
    // No session consistency offered for push or stream pull queries
    return StreamedRow.header(queryId, projectionSchema.build());
}
Also used : QueryId(io.confluent.ksql.query.QueryId) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Example 90 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class EntityUtilTest method shouldSupportSchemasWithKeyColumns.

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

Aggregations

LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)223 Test (org.junit.Test)152 Expression (io.confluent.ksql.execution.expression.tree.Expression)44 ColumnName (io.confluent.ksql.name.ColumnName)31 GenericRow (io.confluent.ksql.GenericRow)30 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)29 KsqlException (io.confluent.ksql.util.KsqlException)27 GenericKey (io.confluent.ksql.GenericKey)20 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)19 List (java.util.List)16 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)14 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)14 Optional (java.util.Optional)14 Collectors (java.util.stream.Collectors)14 QueryContext (io.confluent.ksql.execution.context.QueryContext)13 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)12 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)12 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)12 Column (io.confluent.ksql.schema.ksql.Column)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)11