@Override public Schema union(Schema union, Iterable<Schema> options) { Preconditions.checkState(isOptionSchema(union), "Invalid schema: non-option unions are not supported: {}", union); Schema nonNullOriginal = fromOption(union); Schema nonNullResult = fromOptions(Lists.newArrayList(options)); if (nonNullOriginal != nonNullResult) { return toOption(nonNullResult); } return union; }
@Override public Schema union(Schema union, List<Schema> options) { Preconditions.checkState(AvroSchemaUtil.isOptionSchema(union), "Invalid schema: non-option unions are not supported: {}", union); // only unions with null are allowed, and a null schema results in null Schema pruned = null; if (options.get(0) != null) { pruned = options.get(0); } else if (options.get(1) != null) { pruned = options.get(1); } if (pruned != null) { if (pruned != AvroSchemaUtil.fromOption(union)) { return AvroSchemaUtil.toOption(pruned); } return union; } return null; }
private static int getId(Schema schema, String propertyName) { if (schema.getType() == UNION) { return getId(fromOption(schema), propertyName); } Object id = schema.getObjectProp(propertyName); Preconditions.checkNotNull(id, "Missing expected '%s' property", propertyName); return toInt(id); }
Record p1 = new Record(AvroSchemaUtil.fromOption( AvroSchemaUtil.fromOption(record.getSchema().getField("points").schema()) .getElementType())); p1.put("x", 1);
Record l1 = new Record(AvroSchemaUtil.fromOption( AvroSchemaUtil.fromOption(record.getSchema().getField("locations").schema()) .getValueType())); l1.put("lat", 53.992811f);
Record l1 = new Record(AvroSchemaUtil.fromOption( AvroSchemaUtil.fromOption(record.getSchema().getField("locations").schema()) .getValueType())); l1.put("lat", 53.992811f);
Record p1 = new Record(AvroSchemaUtil.fromOption( AvroSchemaUtil.fromOption(record.getSchema().getField("points").schema()) .getElementType())); p1.put("x", 1);
record.put("id", 34L); Record location = new Record( AvroSchemaUtil.fromOption(record.getSchema().getField("location").schema())); location.put("lat", 52.995143f); location.put("long", -1.539054f);
record.put("id", 34L); Record location = new Record( AvroSchemaUtil.fromOption(record.getSchema().getField("location").schema())); location.put("lat", 52.995143f); location.put("long", -1.539054f);