Package org.apache.avro.generic

Examples of org.apache.avro.generic.GenericData


  }

  @Test public void testUnionWithCollection() {
    Schema s = Schema.parse
      ("[\"null\", {\"type\":\"array\",\"items\":\"float\"}]");
    GenericData data = ReflectData.get();
    assertEquals(1, data.resolveUnion(s, new ArrayList<Float>()));
  }
View Full Code Here


  }

  @Test public void testUnionWithMap() {
    Schema s = Schema.parse
      ("[\"null\", {\"type\":\"map\",\"values\":\"float\"}]");
    GenericData data = ReflectData.get();
    assertEquals(1, data.resolveUnion(s, new HashMap<String,Float>()));
  }
View Full Code Here

    assertEquals(1, data.resolveUnion(s, new HashMap<String,Float>()));
  }

  @Test public void testUnionWithBytes() {
    Schema s = Schema.parse ("[\"null\", \"bytes\"]");
    GenericData data = ReflectData.get();
    assertEquals(1, data.resolveUnion(s, ByteBuffer.wrap(new byte[]{1})));
  }
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

   * @return The DatumReader for the given type
   */
  @SuppressWarnings("unchecked")
  public static <E> DatumReader<E> getDatumReaderForType(Class<E> type, Schema writerSchema) {
    Schema readerSchema = getReaderSchema(type, writerSchema);
    GenericData dataModel = getDataModelForType(type);
    if (dataModel instanceof ReflectData) {
      return new ReflectDatumReader<E>(writerSchema, readerSchema, (ReflectData)dataModel);
    } else if (dataModel instanceof SpecificData) {
      return new SpecificDatumReader<E>(writerSchema, readerSchema, (SpecificData)dataModel);
    } else {
View Full Code Here

   * @param writerSchema The writer {@link Schema} for the entity
   * @return The reader schema based on the given type and writer schema
   */
  public static <E> Schema getReaderSchema(Class<E> type, Schema writerSchema) {
    Schema readerSchema = writerSchema;
    GenericData dataModel = getDataModelForType(type);

    if (dataModel instanceof SpecificData) {
      readerSchema = ((SpecificData)dataModel).getSchema(type);
    }

View Full Code Here

public class TestDataModelUtil {
 
  @Test
  public void testDataModelForGenericType() {
    Class<GenericData.Record> type = GenericData.Record.class;
    GenericData result = DataModelUtil.getDataModelForType(type);
    assertEquals(GenericData.class, result.getClass());
  }
View Full Code Here

  }

  @Test
  public void testDataModelForSpecificType() {
    Class<StandardEvent> type = StandardEvent.class;
    GenericData result = DataModelUtil.getDataModelForType(type);
    assertEquals(SpecificData.class, result.getClass());
  }
View Full Code Here

  }

  @Test
  public void testDataModelForReflectType() {
    Class<String> type = String.class;
    GenericData result = DataModelUtil.getDataModelForType(type);
    assertEquals(DataModelUtil.AllowNulls.class, result.getClass());
  }
View Full Code Here

  }

  @Test public void testUnionWithCollection() {
    Schema s = new Schema.Parser().parse
      ("[\"null\", {\"type\":\"array\",\"items\":\"float\"}]");
    GenericData data = ReflectData.get();
    assertEquals(1, data.resolveUnion(s, new ArrayList<Float>()));
  }
View Full Code Here

TOP

Related Classes of org.apache.avro.generic.GenericData

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.