/** * Returns an iterator starting at the current position in the file. * * <p>Use the get() method to move the current position.</p> * * <p>Note that this iterator is shared with other clients of the file; it does not * contain a separate pointer into the file.</p> * * @return An iterator. */ public Iterator<AvroKeyValue<K, V>> iterator() { return new AvroKeyValue.Iterator<>(mDataFileReader.iterator()); }
public static void assertGenericRecords(File outputAvroFile, Schema schema) throws IOException { try (DataFileReader<GenericRecord> reader = new DataFileReader<>(outputAvroFile, new GenericDatumReader<GenericRecord>(schema))) { Iterator<GenericRecord> iterator = reader.iterator(); GenericRecord record = iterator.next(); Assert.assertEquals(record.get("name").toString(), "Alyssa"); record = iterator.next(); Assert.assertEquals(record.get("name").toString(), "Ben"); record = iterator.next(); Assert.assertEquals(record.get("name").toString(), "Charlie"); Assert.assertFalse(iterator.hasNext()); } }
private void check(String... extraArgs) throws Exception { ArrayList<String> args = new ArrayList<>(); args.addAll(Arrays.asList(new String[] { OUT_FILE.toString(), "--count", COUNT, "--schema-file", SCHEMA_FILE.toString(), "--seed", Long.toString(SEED) })); args.addAll(Arrays.asList(extraArgs)); run(args); DataFileReader<Object> reader = new DataFileReader<Object>(OUT_FILE, new GenericDatumReader<>()); Iterator<Object> found = reader.iterator(); for (Object expected : new RandomData(schemaParser.parse(SCHEMA_FILE), Integer.parseInt(COUNT), SEED)) assertEquals(expected, found.next()); reader.close(); }
new GenericDatumReader<>(writeSchema, readSchema)); GenericData.Record rec1read = reader.iterator().next(); Assert.assertEquals(1, rec1read.get("requiredInt")); Assert.assertNull(rec1read.get("optionalInt")); Assert.assertEquals(5, rec1read.get("newNullableIntWithDefault")); GenericData.Record rec2read = reader.iterator().next(); Assert.assertEquals(1, rec2read.get("requiredInt")); Assert.assertEquals(2, rec2read.get("optionalInt"));
/** * Returns an iterator starting at the current position in the file. * * <p>Use the get() method to move the current position.</p> * * <p>Note that this iterator is shared with other clients of the file; it does not * contain a separate pointer into the file.</p> * * @return An iterator. */ public Iterator<AvroKeyValue<K, V>> iterator() { return new AvroKeyValue.Iterator<K, V>(mDataFileReader.iterator()); }
/** * Given a path to a data file of Spans, extract all spans and add them * to the provided list. */ private static void readFileSpans(File f, List<Span> list) throws IOException { DataFileReader<Span> reader = new DataFileReader<Span>(f, SPAN_READER); Iterator<Span> it = reader.iterator(); ArrayList<Span> spans = new ArrayList<Span>(); while (it.hasNext()) { spans.add(it.next()); } list.addAll(spans); }
/** * Given a path to a data file of Spans, extract spans within a time period * bounded by start and end. */ private static void readFileSpans(File f, List<Span> list, long start, long end) throws IOException { DataFileReader<Span> reader = new DataFileReader<Span>(f, SPAN_READER); Iterator<Span> it = reader.iterator(); ArrayList<Span> spans = new ArrayList<Span>(); while (it.hasNext()) { Span s = it.next(); if (Util.spanInRange(s, start, end)) { spans.add(s); } } list.addAll(spans); }