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()));
}
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()));
}
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()));
}
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());
}
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)));
}
Aggregations