private Schema getAnnotatedUnion(Union union, Map<String,Schema> names) { List<Schema> branches = new ArrayList<>(); for (Class branch : union.value()) branches.add(createSchema(branch, names)); return Schema.createUnion(branches); }
private Schema getAnnotatedUnion(Union union, Map<String,Schema> names) { List<Schema> branches = new ArrayList<Schema>(); for (Class branch : union.value()) branches.add(createSchema(branch, names)); return Schema.createUnion(branches); }
private Schema getSchema(Type type, Map<String,Schema> names) { try { return createSchema(type, names); } catch (AvroTypeException e) { // friendly exception throw new AvroTypeException("Error getting schema for "+type+": " +e.getMessage(), e); } }
private Schema getSchema(Type type, Map<String,Schema> names) { try { return createSchema(type, names); } catch (AvroTypeException e) { // friendly exception throw new AvroTypeException("Error getting schema for "+type+": " +e.getMessage(), e); } }
/** Create a schema for a field. */ protected Schema createFieldSchema(Field field, Map<String, Schema> names) { AvroEncode enc = field.getAnnotation(AvroEncode.class); if (enc != null) try { return enc.using().newInstance().getSchema(); } catch (Exception e) { throw new AvroRuntimeException("Could not create schema from custom serializer for " + field.getName()); } AvroSchema explicit = field.getAnnotation(AvroSchema.class); if (explicit != null) // explicit schema return Schema.parse(explicit.value()); Schema schema = createSchema(field.getGenericType(), names); if (field.isAnnotationPresent(Stringable.class)) { // Stringable schema = Schema.create(Schema.Type.STRING); } if (field.isAnnotationPresent(Nullable.class)) // nullable schema = makeNullable(schema); return schema; }
Schema createNonStringMapSchema(Type keyType, Type valueType, Map<String, Schema> names) { Schema keySchema = createSchema(keyType, names); Schema valueSchema = createSchema(valueType, names); Schema.Field keyField = new Schema.Field(NS_MAP_KEY, keySchema, null, null); Schema.Field valueField = new Schema.Field(NS_MAP_VALUE, valueSchema, null, null); String name = getNameForNonStringMapRecord(keyType, valueType, keySchema, valueSchema); Schema elementSchema = Schema.createRecord(name, null, null, false); elementSchema.setFields(Arrays.asList(keyField, valueField)); Schema arraySchema = Schema.createArray(elementSchema); return arraySchema; }
Schema createNonStringMapSchema(Type keyType, Type valueType, Map<String, Schema> names) { Schema keySchema = createSchema(keyType, names); Schema valueSchema = createSchema(valueType, names); Schema.Field keyField = new Schema.Field(NS_MAP_KEY, keySchema, null, null); Schema.Field valueField = new Schema.Field(NS_MAP_VALUE, valueSchema, null, null); String name = getNameForNonStringMapRecord(keyType, valueType, keySchema, valueSchema); Schema elementSchema = Schema.createRecord(name, null, null, false); elementSchema.setFields(Arrays.asList(keyField, valueField)); Schema arraySchema = Schema.createArray(elementSchema); return arraySchema; }
/** Create a schema for a field. */ protected Schema createFieldSchema(Field field, Map<String, Schema> names) { AvroEncode enc = field.getAnnotation(AvroEncode.class); if (enc != null) try { return enc.using().newInstance().getSchema(); } catch (Exception e) { throw new AvroRuntimeException("Could not create schema from custom serializer for " + field.getName()); } AvroSchema explicit = field.getAnnotation(AvroSchema.class); if (explicit != null) // explicit schema return Schema.parse(explicit.value()); Union union = field.getAnnotation(Union.class); if (union != null) return getAnnotatedUnion(union, names); Schema schema = createSchema(field.getGenericType(), names); if (field.isAnnotationPresent(Stringable.class)) { // Stringable schema = Schema.create(Schema.Type.STRING); } if (field.isAnnotationPresent(Nullable.class)) // nullable schema = makeNullable(schema); return schema; }
if (component == Byte.TYPE) // byte array return Schema.create(Schema.Type.BYTES); Schema result = Schema.createArray(createSchema(component, names)); setElement(result, component); return result; Class key = (Class)params[0]; if (isStringable(key)) { // Stringable key Schema schema = Schema.createMap(createSchema(params[1], names)); schema.addProp(KEY_CLASS_PROP, key.getName()); return schema; if (params.length != 1) throw new AvroTypeException("No array type specified."); Schema schema = Schema.createArray(createSchema(params[0], names)); schema.addProp(CLASS_PROP, raw.getName()); return schema; return result; Schema result = Schema.createArray(createSchema(component, names)); result.addProp(CLASS_PROP, c.getName()); setElement(result, component);
if (component == Byte.TYPE) // byte array return Schema.create(Schema.Type.BYTES); Schema result = Schema.createArray(createSchema(component, names)); setElement(result, component); return result; Class key = (Class)params[0]; if (isStringable(key)) { // Stringable key Schema schema = Schema.createMap(createSchema(params[1], names)); schema.addProp(KEY_CLASS_PROP, key.getName()); return schema; if (params.length != 1) throw new AvroTypeException("No array type specified."); Schema schema = Schema.createArray(createSchema(params[0], names)); schema.addProp(CLASS_PROP, raw.getName()); return schema; return result; Schema result = Schema.createArray(createSchema(component, names)); result.addProp(CLASS_PROP, c.getName()); setElement(result, component);
/** Create a schema for a field. */ protected Schema createFieldSchema(Field field, Map<String, Schema> names) { Schema schema = createSchema(field.getGenericType(), names); if (field.isAnnotationPresent(Nullable.class)) // nullable schema = makeNullable(schema); return schema; }
/** Create a schema for a field. */ protected Schema createFieldSchema(Field field, Map<String, Schema> names) { Schema schema = createSchema(field.getGenericType(), names); if (field.isAnnotationPresent(Nullable.class)) // nullable schema = makeNullable(schema); return schema; }
private Schema getAnnotatedUnion(Union union, Map<String,Schema> names) { List<Schema> branches = new ArrayList<Schema>(); for (Class branch : union.value()) branches.add(createSchema(branch, names)); return Schema.createUnion(branches); }
private Schema getAnnotatedUnion(Union union, Map<String,Schema> names) { List<Schema> branches = new ArrayList<Schema>(); for (Class branch : union.value()) branches.add(createSchema(branch, names)); return Schema.createUnion(branches); }
private Schema getAnnotatedUnion(Union union, Map<String,Schema> names) { List<Schema> branches = new ArrayList<Schema>(); for (Class branch : union.value()) branches.add(createSchema(branch, names)); return Schema.createUnion(branches); }
private Schema getAnnotatedUnion(Union union, Map<String,Schema> names) { List<Schema> branches = new ArrayList<Schema>(); for (Class branch : union.value()) branches.add(createSchema(branch, names)); return Schema.createUnion(branches); }
private Schema getSchema(Type type, Map<String,Schema> names) { try { return createSchema(type, names); } catch (AvroTypeException e) { // friendly exception throw new AvroTypeException("Error getting schema for "+type+": " +e.getMessage(), e); } }
private Schema getSchema(Type type, Map<String,Schema> names) { try { return createSchema(type, names); } catch (AvroTypeException e) { // friendly exception throw new AvroTypeException("Error getting schema for "+type+": " +e.getMessage(), e); } }
private Schema getSchema(Type type, Map<String,Schema> names) { try { return createSchema(type, names); } catch (AvroTypeException e) { // friendly exception throw new AvroTypeException("Error getting schema for "+type+": " +e.getMessage(), e); } }
private Schema getSchema(Type type, Map<String,Schema> names) { try { return createSchema(type, names); } catch (AvroTypeException e) { // friendly exception throw new AvroTypeException("Error getting schema for "+type+": " +e.getMessage(), e); } }