Package org.apache.avro.reflect

Examples of org.apache.avro.reflect.ReflectData


  protected AvroDeserializer(Schema writerSchema, Schema readerSchema,
                             ClassLoader classLoader) {
    mWriterSchema = writerSchema;
    mReaderSchema = null != readerSchema ? readerSchema : writerSchema;
    mAvroDatumReader = new ReflectDatumReader<D>(mWriterSchema, mReaderSchema,
                                                 new ReflectData(classLoader));
  }
View Full Code Here


    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
    Encoder e = factory.directBinaryEncoder(out, null);
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

  }

  @Test
  /** Test nesting of reflect data within generic. */
  public void testReflectWithinGeneric() throws Exception {
    ReflectData data = ReflectData.get();
    // define a record with a field that's a specific Y
    Schema schema = Schema.createRecord("Foo", "", "x.y.z", false);
    List<Schema.Field> fields = new ArrayList<Schema.Field>();
    fields.add(new Schema.Field("f", data.getSchema(Y.class), "", null));
    schema.setFields(fields);

    // create a generic instance of this record
    Y y = new Y();
    y.i = 1;
View Full Code Here

  }

  @Test public void testAlternateModel() throws Exception {
    LOG.debug("Writing some reflect records...");

    ReflectData model = ReflectData.get();

    Configuration conf = new Configuration();
    SortedKeyValueFile.Writer.Options options
      = new SortedKeyValueFile.Writer.Options()
      .withKeySchema(model.getSchema(Stringy.class))
      .withValueSchema(model.getSchema(Stringy.class))
      .withConfiguration(conf)
      .withPath(new Path(mTempDir.getRoot().getPath(), "reflect"))
      .withDataModel(model)
      .withIndexInterval(2);

    SortedKeyValueFile.Writer<Stringy,Stringy> writer
        = new SortedKeyValueFile.Writer<Stringy,Stringy>(options);

    try {
      writer.append(new Stringy("apple"), new Stringy("Apple"));
      writer.append(new Stringy("banana"), new Stringy("Banana"));
      writer.append(new Stringy("carrot"), new Stringy("Carrot"));
      writer.append(new Stringy("durian"), new Stringy("Durian"));
    } finally {
      writer.close();
    }

    LOG.debug("Reading the file back using a reader...");
    SortedKeyValueFile.Reader.Options readerOptions =
      new SortedKeyValueFile.Reader.Options()
      .withKeySchema(model.getSchema(Stringy.class))
      .withValueSchema(model.getSchema(Stringy.class))
      .withConfiguration(conf)
      .withPath(new Path(mTempDir.getRoot().getPath(), "reflect"))
      .withDataModel(model);

    SortedKeyValueFile.Reader<Stringy,Stringy> reader
View Full Code Here

  /**
   * Experiment to see what a schema looks like.
   */
  @Test
  public void testEventSchema() throws IOException {
    ReflectData reflectData = ReflectData.get();
    Schema schm = reflectData.getSchema(EventImpl.class);
    LOG.info(schm);
  }
View Full Code Here

  /**
   * Try BinaryEncoder
   */
  @Test
  public void testSerializeBinary() throws IOException {
    ReflectData reflectData = ReflectData.get();
    Schema schm = reflectData.getSchema(A.class);
    LOG.info(schm);

    ReflectDatumWriter<A> writer = new ReflectDatumWriter<A>(schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Encoder encoder = EncoderFactory.get().binaryEncoder(out, null);
View Full Code Here

  /**
   * Try JsonEncoder
   */
  @Test
  public void testSerializeJson() throws IOException {
    ReflectData reflectData = ReflectData.get();
    Schema schm = reflectData.getSchema(A.class);
    LOG.info(schm);

    ReflectDatumWriter<A> writer = new ReflectDatumWriter<A>(schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JsonEncoder json = EncoderFactory.get().jsonEncoder(schm, out);
View Full Code Here

  /**
   * JsonEncoder and JsonDecoder on a EventImpl
   */
  @Test
  public void testEventSchemaSerializeJson() throws IOException {
    ReflectData reflectData = ReflectData.get();
    Schema schm = reflectData.getSchema(EventImpl.class);
    LOG.info(schm);

    ReflectDatumWriter<EventImpl> writer = new ReflectDatumWriter<EventImpl>(
        schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
View Full Code Here

  /**
   * BinaryEnconder and BinaryDecoder on a EventImpl
   */
  @Test
  public void testEventSchemaSerializeBin() throws IOException {
    ReflectData reflectData = ReflectData.get();
    Schema schm = reflectData.getSchema(EventImpl.class);
    LOG.info(schm);

    ReflectDatumWriter<EventImpl> writer = new ReflectDatumWriter<EventImpl>(
        schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
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.