Package org.apache.avro.reflect

Examples of org.apache.avro.reflect.ReflectData


    assertEquals(record, decoded);
  }

  @Test
  public void testRecordWithNullIO() throws IOException {
    ReflectData reflectData = ReflectData.AllowNull.get();
    Schema schm = reflectData.getSchema(AnotherSampleRecord.class);
    ReflectDatumWriter<AnotherSampleRecord> writer =
      new ReflectDatumWriter<AnotherSampleRecord>(schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    // keep record.a null and see if that works
    BinaryEncoder e = new BinaryEncoder(out);
View Full Code Here


  public static class A { B1 b1; B2 b2; }
  public static interface C { void foo(A a); }

  @Test
  public void testForwardReference() {
    ReflectData data = ReflectData.get();
    Protocol reflected = data.getProtocol(C.class);
    Protocol reparsed = Protocol.parse(reflected.toString());
    assertEquals(reflected, reparsed);
    assert(reparsed.getTypes().contains(data.getSchema(A.class)));
    assert(reparsed.getTypes().contains(data.getSchema(B1.class)));
    assert(reparsed.getTypes().contains(data.getSchema(B2.class)));
    assert(reparsed.getTypes().contains(data.getSchema(X.class)));
  }
View Full Code Here

public class TestAvroKeyRecordWriter {
  @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);
View Full Code Here

    // Use a writer to generate a Avro container file in memory.
    // Write two records: <'apple', TextStats('apple')> and <'banana', TextStats('banana')>.
    AvroKeyValueRecordWriter<Text, AvroValue<TextStats>> writer
        = new AvroKeyValueRecordWriter<Text, AvroValue<TextStats>>(keyConverter, valueConverter,
            new ReflectData(), compressionCodec, outputStream);
    TextStats appleStats = new TextStats();
    appleStats.name = "apple";
    writer.write(new Text("apple"), new AvroValue<TextStats>(appleStats));
    TextStats bananaStats = new TextStats();
    bananaStats.name = "banana";
View Full Code Here

    AvroDatumConverter<AvroValue<R1>, R1> valueConverter =
      factory.create((Class<AvroValue<R1>>) avroValue.getClass());

    AvroKeyValueRecordWriter<Text, AvroValue<R1>> writer =
      new AvroKeyValueRecordWriter<Text, AvroValue<R1>>(
        keyConverter, valueConverter, new ReflectData(),
        CodecFactory.nullCodec(), outputStream);

    writer.write(new Text("reflectionData"), avroValue);
    writer.close(context);
View Full Code Here

import org.apache.avro.reflect.ReflectDatumWriter;

/** {@link org.apache.avro.ipc.Responder} for existing interfaces.*/
public class ReflectResponder extends SpecificResponder {
  public ReflectResponder(Class iface, Object impl) {
    this(iface, impl, new ReflectData(impl.getClass().getClassLoader()));
  }
View Full Code Here

  public ReflectResponder(Class iface, Object impl) {
    this(iface, impl, new ReflectData(impl.getClass().getClassLoader()));
  }
 
  public ReflectResponder(Protocol protocol, Object impl) {
    this(protocol, impl, new ReflectData(impl.getClass().getClassLoader()));
  }
View Full Code Here

/** A {@link org.apache.avro.ipc.Requestor} for existing interfaces. */
public class ReflectRequestor extends SpecificRequestor {
 
  public ReflectRequestor(Class<?> iface, Transceiver transceiver)
    throws IOException {
    this(iface, transceiver, new ReflectData(iface.getClassLoader()));
  }
View Full Code Here

  /** Create a proxy instance whose methods invoke RPCs. */
  public static <T> T getClient(Class<T> iface, Transceiver transciever)
    throws IOException {
    return getClient(iface, transciever,
                     new ReflectData(iface.getClassLoader()));
  }
View Full Code Here

    }
    return values;
  }

  private static <E> String[] shredReflect(E entity, Schema schema) {
    ReflectData reflect = ReflectData.get();
    List<Schema.Field> fields = schema.getFields();
    String[] values = new String[fields.size()];
    for (int i = 0; i < values.length; i += 1) {
      Schema.Field field = fields.get(i);
      values[i] = valueString(
          reflect.getField(entity, field.name(), i), field.schema());
    }
    return values;
  }
View Full Code Here

TOP

Related Classes of org.apache.avro.reflect.ReflectData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.