private static TypeInfo generateTypeInfoWorker(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { // Avro requires NULLable types to be defined as unions of some type T // and NULL. This is annoying and we're going to hide it from the user. if(AvroSerdeUtils.isNullableType(schema)) { return generateTypeInfo( AvroSerdeUtils.getOtherTypeFromNullableType(schema), seenSchemas); } Schema.Type type = schema.getType(); if(primitiveTypeToTypeInfo.containsKey(type)) { return primitiveTypeToTypeInfo.get(type); } switch(type) { case RECORD: return generateRecordTypeInfo(schema, seenSchemas); case MAP: return generateMapTypeInfo(schema, seenSchemas); case ARRAY: return generateArrayTypeInfo(schema, seenSchemas); case UNION: return generateUnionTypeInfo(schema, seenSchemas); case ENUM: return generateEnumTypeInfo(schema); default: throw new AvroSerdeException("Do not yet support: " + schema); } }
/** * Generate a list of of TypeInfos from an Avro schema. This method is * currently public due to some weirdness in deserializing unions, but * will be made private once that is resolved. * @param schema Schema to generate field types for * @return List of TypeInfos, each element of which is a TypeInfo derived * from the schema. * @throws AvroSerdeException for problems during conversion. */ public static List<TypeInfo> generateColumnTypes(Schema schema) throws AvroSerdeException { return generateColumnTypes (schema, null); }
private static TypeInfo generateTypeInfoWorker(Schema schema) throws AvroSerdeException { // Avro requires NULLable types to be defined as unions of some type T // and NULL. This is annoying and we're going to hide it from the user. if(AvroSerdeUtils.isNullableType(schema)) return generateTypeInfo(AvroSerdeUtils.getOtherTypeFromNullableType(schema)); Schema.Type type = schema.getType(); if(primitiveTypeToTypeInfo.containsKey(type)) return primitiveTypeToTypeInfo.get(type); switch(type) { case BYTES: return generateBytesTypeInfo(schema); case RECORD: return generateRecordTypeInfo(schema); case MAP: return generateMapTypeInfo(schema); case ARRAY: return generateArrayTypeInfo(schema); case UNION: return generateUnionTypeInfo(schema); case ENUM: return generateEnumTypeInfo(schema); case FIXED: return generateFixedTypeInfo(schema); default: throw new AvroSerdeException("Do not yet support: " + schema); } }
/** * Generate a list of of TypeInfos from an Avro schema. This method is * currently public due to some weirdness in deserializing unions, but * will be made private once that is resolved. * @param schema Schema to generate field types for * @param seenSchemas stores schemas processed in the parsing done so far, * helping to resolve circular references in the schema * @return List of TypeInfos, each element of which is a TypeInfo derived * from the schema. * @throws AvroSerdeException for problems during conversion. */ public static List<TypeInfo> generateColumnTypes(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { List<Schema.Field> fields = schema.getFields(); List<TypeInfo> types = new ArrayList<TypeInfo>(fields.size()); for (Schema.Field field : fields) { types.add(generateTypeInfo(field.schema(), seenSchemas)); } return types; }
private static TypeInfo generateUnionTypeInfo(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { assert schema.getType().equals(Schema.Type.UNION); List<Schema> types = schema.getTypes(); List<TypeInfo> typeInfos = new ArrayList<TypeInfo>(types.size()); for(Schema type : types) { typeInfos.add(generateTypeInfo(type, seenSchemas)); } return TypeInfoFactory.getUnionTypeInfo(typeInfos); }
private static TypeInfo generateTypeInfoWorker(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { // Avro requires NULLable types to be defined as unions of some type T // and NULL. This is annoying and we're going to hide it from the user. if(AvroSerdeUtils.isNullableType(schema)) { return generateTypeInfo( AvroSerdeUtils.getOtherTypeFromNullableType(schema), seenSchemas); } Schema.Type type = schema.getType(); if(primitiveTypeToTypeInfo.containsKey(type)) { return primitiveTypeToTypeInfo.get(type); } switch(type) { case RECORD: return generateRecordTypeInfo(schema, seenSchemas); case MAP: return generateMapTypeInfo(schema, seenSchemas); case ARRAY: return generateArrayTypeInfo(schema, seenSchemas); case UNION: return generateUnionTypeInfo(schema, seenSchemas); case ENUM: return generateEnumTypeInfo(schema); default: throw new AvroSerdeException("Do not yet support: " + schema); } }
private static TypeInfo generateRecordTypeInfo(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { assert schema.getType().equals(Schema.Type.RECORD); if (seenSchemas == null) { seenSchemas = Collections.newSetFromMap(new IdentityHashMap<Schema, Boolean>()); } else if (seenSchemas.contains(schema)) { throw new AvroSerdeException( "Recursive schemas are not supported. Recursive schema was " + schema .getFullName()); } seenSchemas.add(schema); List<Schema.Field> fields = schema.getFields(); List<String> fieldNames = new ArrayList<String>(fields.size()); List<TypeInfo> typeInfos = new ArrayList<TypeInfo>(fields.size()); for(int i = 0; i < fields.size(); i++) { fieldNames.add(i, fields.get(i).name()); typeInfos.add(i, generateTypeInfo(fields.get(i).schema(), seenSchemas)); } return TypeInfoFactory.getStructTypeInfo(fieldNames, typeInfos); }
public AvroObjectInspectorGenerator(Schema schema) throws SerDeException { verifySchemaIsARecord(schema); this.columnNames = AvroObjectInspectorGenerator.generateColumnNames(schema); this.columnTypes = SchemaToTypeInfo.generateColumnTypes(schema); this.columnComments = AvroObjectInspectorGenerator.generateColumnComments(schema); assert columnNames.size() == columnTypes.size(); this.oi = createObjectInspector(); }
private static TypeInfo generateTypeInfoWorker(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { // Avro requires NULLable types to be defined as unions of some type T // and NULL. This is annoying and we're going to hide it from the user. if(AvroSerdeUtils.isNullableType(schema)) { return generateTypeInfo( AvroSerdeUtils.getOtherTypeFromNullableType(schema), seenSchemas); } Schema.Type type = schema.getType(); if(primitiveTypeToTypeInfo.containsKey(type)) { return primitiveTypeToTypeInfo.get(type); } switch(type) { case RECORD: return generateRecordTypeInfo(schema, seenSchemas); case MAP: return generateMapTypeInfo(schema, seenSchemas); case ARRAY: return generateArrayTypeInfo(schema, seenSchemas); case UNION: return generateUnionTypeInfo(schema, seenSchemas); case ENUM: return generateEnumTypeInfo(schema); default: throw new AvroSerdeException("Do not yet support: " + schema); } }
private static TypeInfo generateArrayTypeInfo(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { assert schema.getType().equals(Schema.Type.ARRAY); Schema itemsType = schema.getElementType(); TypeInfo itemsTypeInfo = generateTypeInfo(itemsType, seenSchemas); return TypeInfoFactory.getListTypeInfo(itemsTypeInfo); }
/** * Generate a list of of TypeInfos from an Avro schema. This method is * currently public due to some weirdness in deserializing unions, but * will be made private once that is resolved. * @param schema Schema to generate field types for * @return List of TypeInfos, each element of which is a TypeInfo derived * from the schema. * @throws AvroSerdeException for problems during conversion. */ public static List<TypeInfo> generateColumnTypes(Schema schema) throws AvroSerdeException { return generateColumnTypes (schema, null); }
private static TypeInfo generateTypeInfoWorker(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { // Avro requires NULLable types to be defined as unions of some type T // and NULL. This is annoying and we're going to hide it from the user. if(AvroSerdeUtils.isNullableType(schema)) { return generateTypeInfo( AvroSerdeUtils.getOtherTypeFromNullableType(schema), seenSchemas); } Schema.Type type = schema.getType(); if(primitiveTypeToTypeInfo.containsKey(type)) { return primitiveTypeToTypeInfo.get(type); } switch(type) { case RECORD: return generateRecordTypeInfo(schema, seenSchemas); case MAP: return generateMapTypeInfo(schema, seenSchemas); case ARRAY: return generateArrayTypeInfo(schema, seenSchemas); case UNION: return generateUnionTypeInfo(schema, seenSchemas); case ENUM: return generateEnumTypeInfo(schema); default: throw new AvroSerdeException("Do not yet support: " + schema); } }
/** * Generate a TypeInfo for an Avro Map. This is made slightly simpler in that * Avro only allows maps with strings for keys. */ private static TypeInfo generateMapTypeInfo(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { assert schema.getType().equals(Schema.Type.MAP); Schema valueType = schema.getValueType(); TypeInfo ti = generateTypeInfo(valueType, seenSchemas); return TypeInfoFactory.getMapTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("string"), ti); }
/** * Generate a list of of TypeInfos from an Avro schema. This method is * currently public due to some weirdness in deserializing unions, but * will be made private once that is resolved. * @param schema Schema to generate field types for * @return List of TypeInfos, each element of which is a TypeInfo derived * from the schema. * @throws AvroSerdeException for problems during conversion. */ public static List<TypeInfo> generateColumnTypes(Schema schema) throws AvroSerdeException { return generateColumnTypes (schema, null); }
private static TypeInfo generateTypeInfoWorker(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { // Avro requires NULLable types to be defined as unions of some type T // and NULL. This is annoying and we're going to hide it from the user. if(AvroSerdeUtils.isNullableType(schema)) { return generateTypeInfo( AvroSerdeUtils.getOtherTypeFromNullableType(schema), seenSchemas); } Schema.Type type = schema.getType(); if(primitiveTypeToTypeInfo.containsKey(type)) { return primitiveTypeToTypeInfo.get(type); } switch(type) { case RECORD: return generateRecordTypeInfo(schema, seenSchemas); case MAP: return generateMapTypeInfo(schema, seenSchemas); case ARRAY: return generateArrayTypeInfo(schema, seenSchemas); case UNION: return generateUnionTypeInfo(schema, seenSchemas); case ENUM: return generateEnumTypeInfo(schema); default: throw new AvroSerdeException("Do not yet support: " + schema); } }
/** * Generate a list of of TypeInfos from an Avro schema. This method is * currently public due to some weirdness in deserializing unions, but * will be made private once that is resolved. * @param schema Schema to generate field types for * @param seenSchemas stores schemas processed in the parsing done so far, * helping to resolve circular references in the schema * @return List of TypeInfos, each element of which is a TypeInfo derived * from the schema. * @throws AvroSerdeException for problems during conversion. */ public static List<TypeInfo> generateColumnTypes(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { List<Schema.Field> fields = schema.getFields(); List<TypeInfo> types = new ArrayList<TypeInfo>(fields.size()); for (Schema.Field field : fields) { types.add(generateTypeInfo(field.schema(), seenSchemas)); } return types; }
/** * Generate a list of of TypeInfos from an Avro schema. This method is * currently public due to some weirdness in deserializing unions, but * will be made private once that is resolved. * @param schema Schema to generate field types for * @return List of TypeInfos, each element of which is a TypeInfo derived * from the schema. * @throws AvroSerdeException for problems during conversion. */ public static List<TypeInfo> generateColumnTypes(Schema schema) throws AvroSerdeException { return generateColumnTypes (schema, null); }
/** * Generate a list of of TypeInfos from an Avro schema. This method is * currently public due to some weirdness in deserializing unions, but * will be made private once that is resolved. * @param schema Schema to generate field types for * @param seenSchemas stores schemas processed in the parsing done so far, * helping to resolve circular references in the schema * @return List of TypeInfos, each element of which is a TypeInfo derived * from the schema. * @throws AvroSerdeException for problems during conversion. */ public static List<TypeInfo> generateColumnTypes(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { List<Schema.Field> fields = schema.getFields(); List<TypeInfo> types = new ArrayList<TypeInfo>(fields.size()); for (Schema.Field field : fields) { types.add(generateTypeInfo(field.schema(), seenSchemas)); } return types; }
/** * Generate a list of of TypeInfos from an Avro schema. This method is * currently public due to some weirdness in deserializing unions, but * will be made private once that is resolved. * @param schema Schema to generate field types for * @return List of TypeInfos, each element of which is a TypeInfo derived * from the schema. * @throws AvroSerdeException for problems during conversion. */ public static List<TypeInfo> generateColumnTypes(Schema schema) throws AvroSerdeException { return generateColumnTypes (schema, null); }
/** * Generate a list of of TypeInfos from an Avro schema. This method is * currently public due to some weirdness in deserializing unions, but * will be made private once that is resolved. * @param schema Schema to generate field types for * @return List of TypeInfos, each element of which is a TypeInfo derived * from the schema. * @throws AvroSerdeException for problems during conversion. */ public static List<TypeInfo> generateColumnTypes(Schema schema) throws AvroSerdeException { List<Schema.Field> fields = schema.getFields(); List<TypeInfo> types = new ArrayList<TypeInfo>(fields.size()); for (Schema.Field field : fields) { types.add(generateTypeInfo(field.schema())); } return types; }