Package org.apache.avro.io

Examples of org.apache.avro.io.DatumReader


    String recordJson =
      "{\"type\":\"record\", \"name\":\"Foo\", \"fields\":[{\"name\":\"f\", "
    +"\"type\":"+schemaJson+", "
    +"\"default\":"+defaultJson+"}]}";
    Schema expected = Schema.parse(recordJson);
    DatumReader in = new GenericDatumReader(ACTUAL, expected);
    GenericData.Record record = (GenericData.Record)
      in.read(null, DecoderFactory.defaultFactory().createBinaryDecoder(
          new byte[0], null));
    assertEquals("Wrong default.", defaultValue, record.get("f"));
    assertEquals("Wrong toString", expected, Schema.parse(expected.toString()));
  }
View Full Code Here


  private List<Object> fromJson(Schema schema, File file) throws Exception {
    InputStream in = new FileInputStream(file);
    List<Object> data = new ArrayList<Object>();
    try {
      DatumReader reader = new GenericDatumReader(schema);
      Decoder decoder = DecoderFactory.get().jsonDecoder(schema, in);
      while (true)
        data.add(reader.read(null, decoder));
    } catch (EOFException e) {
    } finally {
      in.close();
    }
    return data;
View Full Code Here

    String recordJson =
      "{\"type\":\"record\", \"name\":\"Foo\", \"fields\":[{\"name\":\"f\", "
    +"\"type\":"+schemaJson+", "
    +"\"default\":"+defaultJson+"}]}";
    Schema expected = Schema.parse(recordJson);
    DatumReader in = new GenericDatumReader(ACTUAL, expected);
    GenericData.Record record = (GenericData.Record)
      in.read(null, new BinaryDecoder(new ByteArrayInputStream(new byte[0])));
    assertEquals("Wrong default.", defaultValue, record.get("f"));
    assertEquals("Wrong toString", expected, Schema.parse(expected.toString()));
  }
View Full Code Here

  }

  @Override
  public Iterator<T> read(FileSystem fs, final Path path) {
    AvroMode mode = AvroMode.fromType(atype).withFactoryFromConfiguration(fs.getConf());
    final DatumReader recordReader = reader == null ? mode.getReader(atype.getSchema()) : reader;
    this.mapFn.initialize();
    try {
      FsInput fsi = new FsInput(path, fs.getConf());
      final DataFileReader<T> reader = new DataFileReader<T>(fsi, recordReader);
      return new AutoClosingIterator<T>(reader, new UnmodifiableIterator<T>() {
View Full Code Here

    String recordJson =
      "{\"type\":\"record\", \"name\":\"Foo\", \"fields\":[{\"name\":\"f\", "
    +"\"type\":"+schemaJson+", "
    +"\"default\":"+defaultJson+"}]}";
    Schema expected = Schema.parse(recordJson);
    DatumReader in = new GenericDatumReader(ACTUAL, expected);
    GenericData.Record record = (GenericData.Record)
      in.read(null, new BinaryDecoder(new ByteArrayInputStream(new byte[0])));
    assertEquals("Wrong default.", defaultValue, record.get("f"));
    assertEquals("Wrong toString", expected, Schema.parse(expected.toString()));
  }
View Full Code Here

    String recordJson =
      "{\"type\":\"record\", \"name\":\"Foo\", \"fields\":[{\"name\":\"f\", "
    +"\"type\":"+schemaJson+", "
    +"\"default\":"+defaultJson+"}]}";
    Schema expected = Schema.parse(recordJson);
    DatumReader in = new GenericDatumReader(ACTUAL, expected);
    GenericData.Record record = (GenericData.Record)
      in.read(null, DecoderFactory.defaultFactory().createBinaryDecoder(
          new byte[0], null));
    assertEquals("Wrong default.", defaultValue, record.get("f"));
    assertEquals("Wrong toString", expected, Schema.parse(expected.toString()));
  }
View Full Code Here

  @Test
  public void testGetDatumReaderForGenericType() {
    Class<GenericData.Record> type = GenericData.Record.class;
    Schema writerSchema = StandardEvent.getClassSchema();
    DatumReader result = DataModelUtil.getDatumReaderForType(type, writerSchema);
    assertEquals(GenericDatumReader.class, result.getClass());
  }
View Full Code Here

  @Test
  public void testGetDatumReaderForSpecificType() {
    Class<StandardEvent> type = StandardEvent.class;
    Schema writerSchema = StandardEvent.getClassSchema();
    DatumReader result = DataModelUtil.getDatumReaderForType(type, writerSchema);
    assertEquals(SpecificDatumReader.class, result.getClass());
  }
View Full Code Here

  @Test
  public void testGetDatumReaderForReflectType() {
    Class<String> type = String.class;
    Schema writerSchema = Schema.create(Schema.Type.STRING);
    DatumReader result = DataModelUtil.getDatumReaderForType(type, writerSchema);
    assertEquals(ReflectDatumReader.class, result.getClass());
  }
View Full Code Here

  }
 
  public static void assertOutput(String output, Configuration conf)
      throws NumberFormatException, IOException, InterruptedException {

    DatumReader datumReader = new SpecificDatumReader(AvroTweetsJoin.getAvroOutputSchema());
    FileReader reader = DataFileReader.openReader(new File(output),datumReader);
   
    Record record=null;
    record = (Record)reader.next(record);
   
View Full Code Here

TOP

Related Classes of org.apache.avro.io.DatumReader

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.