use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class SchemaUtilTest method shouldCreateCorrectAvroSchemaWithNullableFields.
@Test
public void shouldCreateCorrectAvroSchemaWithNullableFields() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct();
schemaBuilder.field("ordertime", Schema.INT64_SCHEMA).field("orderid", Schema.STRING_SCHEMA).field("itemid", Schema.STRING_SCHEMA).field("orderunits", Schema.FLOAT64_SCHEMA).field("arraycol", SchemaBuilder.array(Schema.FLOAT64_SCHEMA)).field("mapcol", SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.FLOAT64_SCHEMA));
String avroSchemaString = SchemaUtil.buildAvroSchema(schemaBuilder.build(), "orders");
assertThat(avroSchemaString, equalTo("{\"type\":\"record\",\"name\":\"orders\",\"namespace\":\"ksql\",\"fields\":" + "[{\"name\":\"ordertime\",\"type\":[\"null\",\"long\"],\"default\":null},{\"name\":" + "\"orderid\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"itemid\"," + "\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"orderunits\",\"type\":" + "[\"null\",\"double\"],\"default\":null},{\"name\":\"arraycol\",\"type\":[\"null\"," + "{\"type\":\"array\",\"items\":[\"null\",\"double\"]}],\"default\":null},{\"name\":" + "\"mapcol\",\"type\":[\"null\",{\"type\":\"map\",\"values\":[\"null\",\"double\"]}]" + ",\"default\":null}]}"));
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class QueryEngine method getResultDatasource.
StructuredDataSource getResultDatasource(final Select select, final String name) {
SchemaBuilder dataSource = SchemaBuilder.struct().name(name);
for (SelectItem selectItem : select.getSelectItems()) {
if (selectItem instanceof SingleColumn) {
SingleColumn singleColumn = (SingleColumn) selectItem;
String fieldName = singleColumn.getAlias().get();
dataSource = dataSource.field(fieldName, Schema.BOOLEAN_SCHEMA);
}
}
KsqlTopic ksqlTopic = new KsqlTopic(name, name, null);
return new KsqlStream("QueryEngine-DDLCommand-Not-Needed", name, dataSource.schema(), null, null, ksqlTopic);
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class ConsoleTest method buildTestSchema.
private List<SourceDescription.FieldSchemaInfo> buildTestSchema(int size) {
SchemaBuilder dataSourceBuilder = SchemaBuilder.struct().name("TestSchema");
for (int i = 0; i < size; i++) {
dataSourceBuilder.field("f_" + i, SchemaUtil.getTypeSchema("STRING"));
}
List<SourceDescription.FieldSchemaInfo> res = new ArrayList<>();
List<Field> fields = dataSourceBuilder.build().fields();
for (Field field : fields) {
res.add(new SourceDescription.FieldSchemaInfo(field.name(), SchemaUtil.getSchemaFieldName(field)));
}
return res;
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class SchemaUtil method removeImplicitRowTimeRowKeyFromSchema.
public static Schema removeImplicitRowTimeRowKeyFromSchema(Schema schema) {
SchemaBuilder schemaBuilder = SchemaBuilder.struct();
for (Field field : schema.fields()) {
String fieldName = field.name();
fieldName = fieldName.substring(fieldName.indexOf('.') + 1);
if (!fieldName.equalsIgnoreCase(SchemaUtil.ROWTIME_NAME) && !fieldName.equalsIgnoreCase(SchemaUtil.ROWKEY_NAME)) {
schemaBuilder.field(fieldName, field.schema());
}
}
return schemaBuilder.build();
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class SchemaUtil method getSchemaWithNoAlias.
/**
* Remove the alias when reading/writing from outside
*/
public static Schema getSchemaWithNoAlias(Schema schema) {
SchemaBuilder schemaBuilder = SchemaBuilder.struct();
for (Field field : schema.fields()) {
String name = getFieldNameWithNoAlias(field);
schemaBuilder.field(name, field.schema());
}
return schemaBuilder.build();
}
Aggregations