use of com.hortonworks.registries.schemaregistry.SchemaFieldInfo in project registry by hortonworks.
the class StreamsSchemaProvider method generateFields.
@Override
public List<SchemaFieldInfo> generateFields(String schemaText) {
// schema should be in json form.
List<Schema.Field> fields;
try {
fields = new ObjectMapper().readValue(schemaText, new TypeReference<List<Schema.Field>>() {
});
} catch (IOException e) {
throw new RuntimeException(e);
}
List<SchemaFieldInfo> fieldInfos = new ArrayList<>(fields.size());
for (Schema.Field field : fields) {
// currently internal schema implementation does not have namespace.
fieldInfos.add(new SchemaFieldInfo("__universal", field.getName(), field.getType().toString()));
}
return fieldInfos;
}
use of com.hortonworks.registries.schemaregistry.SchemaFieldInfo in project registry by hortonworks.
the class AvroFieldsGenerator method parseField.
private void parseField(Schema.Field field, List<SchemaFieldInfo> schemaFieldInfos, Set<String> visitedRecords) {
Schema schema = field.schema();
Schema.Type type = schema.getType();
String name = field.name();
LOG.debug("Visiting field: [{}]", field);
String namespace = null;
try {
namespace = schema.getNamespace();
} catch (Exception e) {
// ignore.
}
schemaFieldInfos.add(new SchemaFieldInfo(namespace, name, type.name()));
// todo check whether fields should be mapped to the root schema.
parseSchema(schema, schemaFieldInfos, visitedRecords);
}
use of com.hortonworks.registries.schemaregistry.SchemaFieldInfo in project registry by hortonworks.
the class AvroSchemaFieldsGeneratorTest method testComplexSchemaRead.
@Test
public void testComplexSchemaRead() throws Exception {
AvroFieldsGenerator avroFieldsGenerator = new AvroFieldsGenerator();
try (InputStream schemaStream = this.getClass().getResourceAsStream("/schema-1.avsc")) {
Schema.Parser parser = new Schema.Parser();
Schema schema = parser.parse(schemaStream);
List<SchemaFieldInfo> schemaFieldInfos = avroFieldsGenerator.generateFields(schema);
Assert.assertEquals(schemaFieldInfos.size(), 12);
}
}
use of com.hortonworks.registries.schemaregistry.SchemaFieldInfo in project registry by hortonworks.
the class AvroSchemaProviderTest method testAvroSchemas.
@Test
public void testAvroSchemas() throws Exception {
AvroSchemaProvider avroSchemaProvider = new AvroSchemaProvider();
try (InputStream schemaStream = AvroSchemaProviderTest.class.getResourceAsStream("/avro/trucks.avsc")) {
List<SchemaFieldInfo> schemaFieldInfos = avroSchemaProvider.generateFields(IOUtils.toString(schemaStream));
LOG.info("generated schema fields [{}]", schemaFieldInfos);
Assert.assertEquals(11, schemaFieldInfos.size());
}
}
use of com.hortonworks.registries.schemaregistry.SchemaFieldInfo in project registry by hortonworks.
the class StreamsSchemaProviderTest method testStreamsSchema.
@Test
public void testStreamsSchema() throws Exception {
StreamsSchemaProvider streamsSchemaProvider = new StreamsSchemaProvider();
try (InputStream trucksSchemaStream = StreamsSchemaProviderTest.class.getResourceAsStream("/streams/trucks.stsc")) {
List<SchemaFieldInfo> schemaFieldInfos = streamsSchemaProvider.generateFields(IOUtils.toString(trucksSchemaStream));
LOG.info("schemaFieldInfos = " + schemaFieldInfos);
Assert.assertEquals(11, schemaFieldInfos.size());
}
}
Aggregations