use of io.confluent.ksql.rest.entity.FieldInfo in project ksql by confluentinc.
the class Console method formatFieldType.
private static String formatFieldType(final FieldInfo field, final Optional<WindowType> windowType, final boolean isTable) {
final FieldType possibleFieldType = field.getType().orElse(null);
if (possibleFieldType == FieldType.HEADER) {
final String headerType = field.getHeaderKey().map(k -> "(header('" + k + "'))").orElse("(headers)");
return String.format("%-16s %s", field.getSchema().toTypeString(), headerType);
}
if (possibleFieldType == FieldType.KEY) {
final String wt = windowType.map(v -> " (Window type: " + v + ")").orElse("");
final String keyType = isTable ? "(primary key)" : "(key)";
return String.format("%-16s %s%s", field.getSchema().toTypeString(), keyType, wt);
}
return field.getSchema().toTypeString();
}
use of io.confluent.ksql.rest.entity.FieldInfo 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)));
}
use of io.confluent.ksql.rest.entity.FieldInfo in project ksql by confluentinc.
the class EntityUtilTest method shouldBuildCorrectPrimitiveField.
private static void shouldBuildCorrectPrimitiveField(final SqlType primitiveSchema, final String schemaName) {
// Given:
final LogicalSchema schema = LogicalSchema.builder().valueColumn(ColumnName.of("field"), primitiveSchema).build();
// When:
final List<FieldInfo> fields = EntityUtil.buildSourceSchemaEntity(schema);
// Then:
assertThat(fields.get(0).getName(), equalTo("field"));
assertThat(fields.get(0).getSchema().getTypeName(), equalTo(schemaName));
assertThat(fields.get(0).getSchema().getFields(), equalTo(Optional.empty()));
assertThat(fields.get(0).getSchema().getMemberSchema(), equalTo(Optional.empty()));
assertThat(fields.get(0).getType(), equalTo(Optional.empty()));
}
use of io.confluent.ksql.rest.entity.FieldInfo in project ksql by confluentinc.
the class EntityUtilTest method shouldSupportSchemasWithAllHeadersColumn.
@Test
public void shouldSupportSchemasWithAllHeadersColumn() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().headerColumn(ColumnName.of("field1"), Optional.empty()).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("ARRAY"));
assertThat(fields.get(0).getType(), equalTo(Optional.of(FieldType.HEADER)));
assertThat(fields.get(0).getHeaderKey(), equalTo(Optional.empty()));
}
use of io.confluent.ksql.rest.entity.FieldInfo in project ksql by confluentinc.
the class EntityUtilTest method shouldSupportSchemasWithExtractedHeaderColumns.
@Test
public void shouldSupportSchemasWithExtractedHeaderColumns() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().headerColumn(ColumnName.of("field1"), Optional.of("abc")).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("BYTES"));
assertThat(fields.get(0).getType(), equalTo(Optional.of(FieldType.HEADER)));
assertThat(fields.get(0).getHeaderKey(), equalTo(Optional.of("abc")));
}
Aggregations