private SimpleRecordSchema(final List<RecordField> fields, final String text, final String schemaFormat, final boolean textAvailable, final SchemaIdentifier id) { this(text, schemaFormat, textAvailable, id); setFields(fields); }
/** * Converts an Avro Schema to a RecordSchema * * @param avroSchema the Avro Schema to convert * @param schemaText the textual representation of the schema * @param schemaId the identifier of the schema * @return the Corresponding Record Schema */ public static RecordSchema createSchema(final Schema avroSchema, final String schemaText, final SchemaIdentifier schemaId) { if (avroSchema == null) { throw new IllegalArgumentException("Avro Schema cannot be null"); } final String schemaFullName = avroSchema.getNamespace() + "." + avroSchema.getName(); final SimpleRecordSchema recordSchema = schemaText == null ? new SimpleRecordSchema(schemaId) : new SimpleRecordSchema(schemaText, AVRO_SCHEMA_FORMAT, schemaId); recordSchema.setSchemaName(avroSchema.getName()); recordSchema.setSchemaNamespace(avroSchema.getNamespace()); final DataType recordSchemaType = RecordFieldType.RECORD.getRecordDataType(recordSchema); final Map<String, DataType> knownRecords = new HashMap<>(); knownRecords.put(schemaFullName, recordSchemaType); final List<RecordField> recordFields = new ArrayList<>(avroSchema.getFields().size()); for (final Field field : avroSchema.getFields()) { final String fieldName = field.name(); final Schema fieldSchema = field.schema(); final DataType dataType = AvroTypeUtil.determineDataType(fieldSchema, knownRecords); final boolean nullable = isNullable(fieldSchema); addFieldToList(recordFields, field, fieldName, fieldSchema, dataType, nullable); } recordSchema.setFields(recordFields); return recordSchema; }
recordSchema.setFields(recordFields); return recordSchemaType;
private SimpleRecordSchema(final List<RecordField> fields, final String text, final String schemaFormat, final boolean textAvailable, final SchemaIdentifier id) { this(text, schemaFormat, textAvailable, id); setFields(fields); }
/** * Converts an Avro Schema to a RecordSchema * * @param avroSchema the Avro Schema to convert * @param schemaText the textual representation of the schema * @param schemaId the identifier of the schema * @return the Corresponding Record Schema */ public static RecordSchema createSchema(final Schema avroSchema, final String schemaText, final SchemaIdentifier schemaId) { if (avroSchema == null) { throw new IllegalArgumentException("Avro Schema cannot be null"); } final String schemaFullName = avroSchema.getNamespace() + "." + avroSchema.getName(); final SimpleRecordSchema recordSchema = schemaText == null ? new SimpleRecordSchema(schemaId) : new SimpleRecordSchema(schemaText, AVRO_SCHEMA_FORMAT, schemaId); final DataType recordSchemaType = RecordFieldType.RECORD.getRecordDataType(recordSchema); final Map<String, DataType> knownRecords = new HashMap<>(); knownRecords.put(schemaFullName, recordSchemaType); final List<RecordField> recordFields = new ArrayList<>(avroSchema.getFields().size()); for (final Field field : avroSchema.getFields()) { final String fieldName = field.name(); final Schema fieldSchema = field.schema(); final DataType dataType = AvroTypeUtil.determineDataType(fieldSchema, knownRecords); final boolean nullable = isNullable(fieldSchema); addFieldToList(recordFields, field, fieldName, fieldSchema, dataType, nullable); } recordSchema.setFields(recordFields); return recordSchema; }
recordSchema.setFields(recordFields); return recordSchemaType;