Package org.apache.avro.reflect

Examples of org.apache.avro.reflect.ReflectData


  }
 
  @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"));
    TaskAttemptContext context = createMock(TaskAttemptContext.class);

    replay(context);
View Full Code Here


  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

  }

  @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

    ClassLoader loader = conf.getClass().getClassLoader();
    AvroSerialization serialization = new AvroSerialization();
    serialization.setConf(conf);
    AvroDeserializer des =
      (AvroDeserializer)serialization.getDeserializer(AvroKey.class);
    ReflectData data =
      (ReflectData)((ReflectDatumReader)des.mAvroDatumReader).getData();
    Assert.assertEquals(loader, data.getClassLoader());
  }
View Full Code Here

    conf.setClassLoader(loader);
    AvroSerialization serialization = new AvroSerialization();
    serialization.setConf(conf);
    AvroDeserializer des =
      (AvroDeserializer)serialization.getDeserializer(AvroKey.class);
    ReflectData data =
      (ReflectData)((ReflectDatumReader)des.mAvroDatumReader).getData();
    Assert.assertEquals(loader, data.getClassLoader());
  }
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
    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

    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

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.