public ReflectRequestor(Class<?> iface, Transceiver transceiver) throws IOException { this(iface, transceiver, new ReflectData(iface.getClassLoader())); }
/** * 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 ReflectResponder(Protocol protocol, Object impl) { this(protocol, impl, new ReflectData(impl.getClass().getClassLoader())); }
public ReflectResponder(Class iface, Object impl) { this(iface, impl, new ReflectData(impl.getClass().getClassLoader())); }
/** Create a proxy instance whose methods invoke RPCs. */ public static <T> T getClient(Class<T> iface, Transceiver transceiver) throws IOException { return getClient(iface, transceiver, new ReflectData(iface.getClassLoader())); }
/** Construct for reading instances of a class. */ public ReflectDatumReader(Class<T> c) { this(new ReflectData(c.getClassLoader())); setSchema(getSpecificData().getSchema(c)); }
/** Construct for reading instances of a class. */ public ReflectDatumReader(Class<T> c) { this(new ReflectData(c.getClassLoader())); setSchema(getSpecificData().getSchema(c)); }
@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) ); }
private static Schema tryExtractAvroSchema(ClassLoader cl, Class<?> runtimeType) { if (isGenericRecord(runtimeType)) { return null; } if (isSpecificRecord(runtimeType)) { SpecificData d = new SpecificData(cl); return d.getSchema(runtimeType); } ReflectData d = new ReflectData(cl); return d.getSchema(runtimeType); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public void checkStringable(Class c, String value) throws Exception { ReflectData data = new ReflectData(); Schema schema = data.getSchema(c); assertEquals ("{\"type\":\"string\",\"java-class\":\""+c.getName()+"\"}", schema.toString()); checkBinary(schema, c.getConstructor(String.class).newInstance(value)); }
private Schema getReflectedSchemaByName(String className, Conversion<?> conversion) throws ClassNotFoundException { // one argument: a fully qualified class name Class<?> cls = Class.forName(className); // get the reflected schema for the given class ReflectData model = new ReflectData(); model.addLogicalTypeConversion(conversion); return model.getSchema(cls); }
private void testPrimitiveArray(Class<?> c, boolean blocking) throws Exception { ReflectData data = new ReflectData(); Random r = new Random(); int size = 200; Object array = Array.newInstance(c, size); Schema s = data.getSchema(array.getClass()); for(int i = 0; i < size; i++) { Array.set(array, i, randomFor(c, r)); } checkBinary(data, s, array, false, blocking); }
/** Test Map with stringable key classes. */ @Test public void testStringableMapKeys() throws Exception { M1 record = new M1(); record.integerKeyMap = new HashMap<>(1); record.integerKeyMap.put(10, "foo"); record.bigIntegerKeyMap = new HashMap<>(1); record.bigIntegerKeyMap.put(java.math.BigInteger.TEN, "bar"); record.bigDecimalKeyMap = new HashMap<>(1); record.bigDecimalKeyMap.put(java.math.BigDecimal.ONE, "bigDecimal"); record.fileKeyMap = new HashMap<>(1); record.fileKeyMap.put(new java.io.File("foo.bar"), "file"); ReflectData data = new ReflectData().addStringable(Integer.class); checkBinary(data, data.getSchema(M1.class), record, true); }
@Test public void testClassLoader() throws Exception { ClassLoader loader = new ClassLoader() {}; ReflectResponder responder = new ReflectResponder(Simple.class, new TestImpl(), new ReflectData(loader)); assertEquals(responder.getReflectData().getClassLoader(), loader); ReflectRequestor requestor = new ReflectRequestor(Simple.class, client, new ReflectData(loader)); assertEquals(requestor.getReflectData().getClassLoader(), loader); }
@Test public void testWrite() throws IOException { Schema writerSchema = Schema.create(Schema.Type.INT); GenericData dataModel = new ReflectData(); CodecFactory compressionCodec = CodecFactory.nullCodec(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); TaskAttemptContext context = createMock(TaskAttemptContext.class); replay(context); // Write an avro container file with two records: 1 and 2. AvroKeyRecordWriter<Integer> recordWriter = new AvroKeyRecordWriter<>( writerSchema, dataModel, compressionCodec, outputStream); recordWriter.write(new AvroKey<>(1), NullWritable.get()); recordWriter.write(new AvroKey<>(2), NullWritable.get()); recordWriter.close(context); verify(context); // Verify that the file was written as expected. InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); Schema readerSchema = Schema.create(Schema.Type.INT); DatumReader<Integer> datumReader = new SpecificDatumReader<>(readerSchema); DataFileStream<Integer> dataFileReader = new DataFileStream<>(inputStream, datumReader); assertTrue(dataFileReader.hasNext()); // Record 1. assertEquals(1, dataFileReader.next().intValue()); assertTrue(dataFileReader.hasNext()); // Record 2. assertEquals(2, dataFileReader.next().intValue()); assertFalse(dataFileReader.hasNext()); // No more records. dataFileReader.close(); }
keyConverter, valueConverter, new ReflectData(), CodecFactory.nullCodec(), outputStream);
@Test public void testSycnableWrite() throws IOException { Schema writerSchema = Schema.create(Schema.Type.INT); GenericData dataModel = new ReflectData(); CodecFactory compressionCodec = CodecFactory.nullCodec(); FileOutputStream outputStream = new FileOutputStream(new File("target/temp.avro"));
new ReflectData(), compressionCodec, outputStream); TextStats appleStats = new TextStats(); appleStats.name = "apple";
new ReflectData(), compressionCodec, outputStream); TextStats appleStats = new TextStats(); appleStats.name = "apple";
@Test @SuppressWarnings("unchecked") public void testPairRecord() throws IOException { ReflectData model = new ReflectData(); model.addLogicalTypeConversion(new Conversion<Pair>() { @Override