/** * Returns the partitions within which the column values exist. * * @return List of ranges for the column values. */ @Nullable public Set<Integer> getPartitions() { return _partitions; }
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") private static <T> AvroFactory<T> fromReflective(Class<T> type, ClassLoader cl, Optional<Schema> previousSchema) { ReflectData reflectData = new ReflectData(cl); Schema newSchema = reflectData.getSchema(type); return new AvroFactory<>( reflectData, newSchema, new ReflectDatumReader<>(previousSchema.orElse(newSchema), newSchema, reflectData), new ReflectDatumWriter<>(newSchema, reflectData) ); }
@Test public void testR6() throws Exception { R7 r7 = new R7(); r7.value = 1; checkReadWrite(r7, ReflectData.get().getSchema(R6.class)); R8 r8 = new R8(); r8.value = 1; checkReadWrite(r8, ReflectData.get().getSchema(R6.class)); R9 r9 = new R9(); r9.r6s = new R6[] {r7, r8}; checkReadWrite(r9, ReflectData.get().getSchema(R9.class)); }
/** * Constructor. * * @param writerSchema The Avro writer schema for the data to deserialize. * @param readerSchema The Avro reader schema for the data to deserialize (may be null). */ protected AvroDeserializer(Schema writerSchema, Schema readerSchema, ClassLoader classLoader) { mWriterSchema = writerSchema; mReaderSchema = null != readerSchema ? readerSchema : writerSchema; mAvroDatumReader = new ReflectDatumReader<>(mWriterSchema, mReaderSchema, new ReflectData(classLoader)); }
public static void checkBinary(Schema schema, Object datum) throws IOException { checkBinary(ReflectData.get(), schema, datum, false); }
@Override protected final void readInternal(Decoder d) throws IOException { for (int i = 0; i < count; i++) { reader.read(null, d); } }
@Override protected final void writeInternal(Encoder e) throws IOException { for (int i = 0; i < sourceData.length; i++) { writer.write(sourceData[i], e); } }
@Test public void testNullableStringableField() throws Exception { NullableStringable datum = new NullableStringable(); datum.number = java.math.BigDecimal.TEN; Schema schema = ReflectData.AllowNull.get().getSchema(NullableStringable.class); checkBinary(schema, datum); }
@Stringable public static class R10 { private String text; public R10(String text) { this.text = text; } @Override public String toString() { return text; } @Override public boolean equals(Object o) { if (!(o instanceof R10)) return false; return this.text.equals(((R10)o).text); } }
public ReflectRequestor(Class<?> iface, Transceiver transceiver, ReflectData data) throws IOException { this(data.getProtocol(iface), transceiver, data); }
/** * Create a POJO having non-string map-keys */ private Company buildCompany () { Company co = new Company (); HashMap<EmployeeId, EmployeeInfo> employees = new HashMap<>(); co.setEmployees(employees); employees.put(new EmployeeId(1), new EmployeeInfo("Foo")); employees.put(new EmployeeId(2), new EmployeeInfo("Bar")); return co; }
private FieldAccessor getFieldAccessor(Class<?> c, String fieldName) { ClassAccessorData data = getClassAccessorData(c); if (data != null) { return data.getAccessorFor(fieldName); } return null; }
public static class R9_1 { @Union({Void.class, R7.class, R8.class}) public Object value; @Override public boolean equals(Object o) { if (!(o instanceof R9_1)) return false; if (this.value == null) return ((R9_1)o).value == null; return this.value.equals(((R9_1)o).value); } }
public static class R12 { // fields @AvroSchema("\"int\"") Object x; @AvroSchema("{\"type\":\"array\",\"items\":[\"null\",\"string\"]}") List<String> strings; }
public void testAnnotationAvroStringableFields() throws Exception { check(RAvroStringableField.class, "{\"type\":\"record\",\"name\":\"RAvroNameCollide\",\"namespace\":" +"\"org.apache.avro.reflect.TestReflect\",\"fields\":[" +"{\"name\":\"a\",\"type\":\"String\"}]}"); }
@Nullable @Override protected String getLoadMode() { return "MMAP"; }