@Test public void testRead_ReflectReader() throws IOException { Schema reflectSchema = ReflectData.get().getSchema(PojoPerson.class); GenericRecord savedRecord = new GenericData.Record(reflectSchema); savedRecord.put("name", "John Doe"); populateGenericFile(Lists.newArrayList(savedRecord), reflectSchema); AvroFileReaderFactory<PojoPerson> genericReader = new AvroFileReaderFactory<PojoPerson>( Avros.reflects(PojoPerson.class), new Configuration()); Iterator<PojoPerson> recordIterator = genericReader.read(FileSystem .getLocal(new Configuration()), new Path(this.avroFile.getAbsolutePath())); PojoPerson person = recordIterator.next(); assertEquals("John Doe", person.getName()); assertFalse(recordIterator.hasNext()); }
@Override public Iterator<T> read(FileSystem fs, final Path path) { this.mapFn.setConfigurationForTest(conf); this.mapFn.initialize(); try { FsInput fsi = new FsInput(path, fs.getConf()); final DataFileReader<T> reader = new DataFileReader<T>(fsi, recordReader); return new UnmodifiableIterator<T>() { @Override public boolean hasNext() { return reader.hasNext(); } @Override public T next() { return mapFn.map(reader.next()); } }; } catch (IOException e) { LOG.info("Could not read avro file at path: " + path, e); return Iterators.emptyIterator(); } }
AvroFileReaderFactory implements FileReaderFactory<T> { @Override public Iterator<T> read(FileSystem fs, final Path path) { this.mapFn.setConfigurationForTest(conf); this.mapFn.initialize(); try { FsInput fsi = new FsInput(path, fs.getConf()); final DataFileReader<T> reader = new DataFileReader<T>(fsi, recordReader); return new UnmodifiableIterator<T>() { @Override public boolean hasNext() { return reader.hasNext(); } @Override public T next() { return mapFn.map(reader.next()); } }; } catch (IOException e) { LOG.info("Could not read avro file at path: " + path, e); return Iterators.emptyIterator(); } } }
AvroFileReaderFactory implements FileReaderFactory<T> { @Override public Iterator<T> read(FileSystem fs, final Path path) { this.mapFn.setConfigurationForTest(conf); this.mapFn.initialize(); try { FsInput fsi = new FsInput(path, fs.getConf()); final DataFileReader<T> reader = new DataFileReader<T>(fsi, recordReader); return new UnmodifiableIterator<T>() { @Override public boolean hasNext() { return reader.hasNext(); } @Override public T next() { return mapFn.map(reader.next()); } }; } catch (IOException e) { LOG.info("Could not read avro file at path: " + path, e); return Iterators.emptyIterator(); } } AvroFileReaderFactory(AvroType<T> atype, Configuration conf); }
AvroFileReaderFactory implements FileReaderFactory<T> { @Override public Iterator<T> read(FileSystem fs, final Path path) { this.mapFn.setConfigurationForTest(conf); this.mapFn.initialize(); try { FsInput fsi = new FsInput(path, fs.getConf()); final DataFileReader<T> reader = new DataFileReader<T>(fsi, recordReader); return new UnmodifiableIterator<T>() { @Override public boolean hasNext() { return reader.hasNext(); } @Override public T next() { return mapFn.map(reader.next()); } }; } catch (IOException e) { LOG.info("Could not read avro file at path: " + path, e); return Iterators.emptyIterator(); } } AvroFileReaderFactory(AvroType<T> atype, Configuration conf); @Override Iterator<T> read(FileSystem fs, final Path path); }
AvroFileReaderFactory implements FileReaderFactory<T> { @Override public Iterator<T> read(FileSystem fs, final Path path) { this.mapFn.setConfigurationForTest(conf); this.mapFn.initialize(); try { FsInput fsi = new FsInput(path, fs.getConf()); final DataFileReader<T> reader = new DataFileReader<T>(fsi, recordReader); return new UnmodifiableIterator<T>() { @Override public boolean hasNext() { return reader.hasNext(); } @Override public T next() { return mapFn.map(reader.next()); } }; } catch (IOException e) { LOG.info("Could not read avro file at path: " + path, e); return Iterators.emptyIterator(); } } AvroFileReaderFactory(AvroType<T> atype, Configuration conf); @Override Iterator<T> read(FileSystem fs, final Path path);  }