Examples of SeekableFileInput


Examples of org.apache.avro.file.SeekableFileInput

  @Test
  public void testReadRecords() throws IOException, InterruptedException {
    // Create the test avro file input with two records:
    //   1. "first"
    //   2. "second"
    final SeekableInput avroFileInput = new SeekableFileInput(
        AvroFiles.createFile(new File(mTempDir.getRoot(), "myStringfile.avro"),
            Schema.create(Schema.Type.STRING), "first", "second"));

    // Create the record reader.
    Schema readerSchema = Schema.create(Schema.Type.STRING);
    RecordReader<AvroKey<CharSequence>, NullWritable> recordReader
        = new AvroKeyRecordReader<CharSequence>(readerSchema) {
      @Override
      protected SeekableInput createSeekableInput(Configuration conf, Path path)
          throws IOException {
        return avroFileInput;
      }
    };

    // Set up the job configuration.
    Configuration conf = new Configuration();

    // Create a mock input split for this record reader.
    FileSplit inputSplit = createMock(FileSplit.class);
    expect(inputSplit.getPath()).andReturn(new Path("/path/to/an/avro/file")).anyTimes();
    expect(inputSplit.getStart()).andReturn(0L).anyTimes();
    expect(inputSplit.getLength()).andReturn(avroFileInput.length()).anyTimes();

    // Create a mock task attempt context for this record reader.
    TaskAttemptContext context = createMock(TaskAttemptContext.class);
    expect(context.getConfiguration()).andReturn(conf).anyTimes();
View Full Code Here

Examples of org.apache.avro.file.SeekableFileInput

    AvroKeyValue<CharSequence, Integer> secondInputRecord
        = new AvroKeyValue<CharSequence, Integer>(new GenericData.Record(keyValueSchema));
    secondInputRecord.setKey("second");
    secondInputRecord.setValue(2);

    final SeekableInput avroFileInput = new SeekableFileInput(
        AvroFiles.createFile(new File(mTempDir.getRoot(), "myInputFile.avro"), keyValueSchema,
            firstInputRecord.get(), secondInputRecord.get()));

    // Create the record reader over the avro input file.
    RecordReader<AvroKey<CharSequence>, AvroValue<Integer>> recordReader
        = new AvroKeyValueRecordReader<CharSequence, Integer>(
            Schema.create(Schema.Type.STRING), Schema.create(Schema.Type.INT)) {
      @Override
      protected SeekableInput createSeekableInput(Configuration conf, Path path)
          throws IOException {
        return avroFileInput;
      }
    };

    // Set up the job configuration.
    Configuration conf = new Configuration();

    // Create a mock input split for this record reader.
    FileSplit inputSplit = createMock(FileSplit.class);
    expect(inputSplit.getPath()).andReturn(new Path("/path/to/an/avro/file")).anyTimes();
    expect(inputSplit.getStart()).andReturn(0L).anyTimes();
    expect(inputSplit.getLength()).andReturn(avroFileInput.length()).anyTimes();

    // Create a mock task attempt context for this record reader.
    TaskAttemptContext context = createMock(TaskAttemptContext.class);
    expect(context.getConfiguration()).andReturn(conf).anyTimes();
View Full Code Here

Examples of org.apache.avro.file.SeekableFileInput

    DataFileReader<Object> reader =
      new DataFileReader<Object>(file, new GenericDatumReader<Object>());
    // get a header for this file
    DataFileStream.Header header = reader.getHeader();
    // re-open to an arbitrary position near the middle, with sync == true
    SeekableFileInput sin = new SeekableFileInput(file);
    sin.seek(sin.length() / 2);
    reader = DataFileReader.<Object>openReader(sin, new GenericDatumReader<Object>(),
        header, true);
    assertNotNull("Should be able to reopen from arbitrary point", reader.next());
    long validPos = reader.previousSync();
    // post sync, we know of a valid sync point: re-open with seek (sync == false)
    sin.seek(validPos);
    reader = DataFileReader.<Object>openReader(sin, new GenericDatumReader<Object>(),
        header, false);
    assertEquals("Should not move from sync point on reopen", validPos, sin.tell());
    assertNotNull("Should be able to reopen at sync point", reader.next());
  }
View Full Code Here

Examples of org.apache.avro.file.SeekableFileInput

      new DataFileWriter<Object>(new GenericDatumWriter<Object>());
    writer.setFlushOnEveryBlock(false);
    TestingByteArrayOutputStream out = new TestingByteArrayOutputStream();
    if (useFile) {
      File f = makeFile();
      SeekableFileInput in = new SeekableFileInput(f);
      writer.appendTo(in, out);
    } else {
      writer.create(SCHEMA, out);
    }
    int currentCount = 0;
View Full Code Here

Examples of org.apache.avro.file.SeekableFileInput

    DataFileReader<Object> reader =
      new DataFileReader<Object>(file, new GenericDatumReader<Object>());
    // get a header for this file
    DataFileStream.Header header = reader.getHeader();
    // re-open to an arbitrary position near the middle, with sync == true
    SeekableFileInput sin = new SeekableFileInput(file);
    sin.seek(sin.length() / 2);
    reader = DataFileReader.<Object>openReader(sin, new GenericDatumReader<Object>(),
        header, true);
    assertNotNull("Should be able to reopen from arbitrary point", reader.next());
    long validPos = reader.previousSync();
    // post sync, we know of a valid sync point: re-open with seek (sync == false)
    sin.seek(validPos);
    reader = DataFileReader.<Object>openReader(sin, new GenericDatumReader<Object>(),
        header, false);
    assertEquals("Should not move from sync point on reopen", validPos, sin.tell());
    assertNotNull("Should be able to reopen at sync point", reader.next());
  }
View Full Code Here

Examples of org.apache.avro.file.SeekableFileInput

  }

  @Test
  public void testGenericRead() throws IOException {
    DataFileReader<Object> reader =
      new DataFileReader<Object>(new SeekableFileInput(FILE),
                                 new GenericDatumReader<Object>());
    try {
      Object datum = null;
      if (VALIDATE) {
        for (Object expected : new RandomData(SCHEMA, COUNT, SEED)) {
View Full Code Here

Examples of org.apache.avro.file.SeekableFileInput

  protected void readFile(File f,
      DatumReader<Object> datumReader, boolean reuse)
    throws IOException {
    System.out.println("Reading "+ f.getName());
    DataFileReader<Object> reader =
      new DataFileReader<Object>(new SeekableFileInput(f), datumReader);
    Object datum = null;
    long count = reader.getMetaLong("count");
    for (int i = 0; i < count; i++) {
      datum = reader.next(reuse ? datum : null);
      assertNotNull(datum);
View Full Code Here

Examples of org.apache.avro.file.SeekableFileInput

    write(writer, new BarRecord("Two beers please"), check);
    write(writer, new FooRecord(20), check);
    writer.close();

    ReflectDatumReader din = new ReflectDatumReader("org.apache.avro.");
    SeekableFileInput sin = new SeekableFileInput(FILE);
    DataFileReader<Object> reader = new DataFileReader<Object>(sin, din);
    Object datum = null;
    long count = reader.getMetaLong("count");
    for (int i = 0; i < count; i++) {
      datum = reader.next(datum);
View Full Code Here

Examples of org.apache.avro.file.SeekableFileInput

    write(writer, new BarRecord("Many beers please"), check);

    writer.close();

    ReflectDatumReader din = new ReflectDatumReader("org.apache.avro.");
    SeekableFileInput sin = new SeekableFileInput(FILE);
    DataFileReader<Object> reader = new DataFileReader<Object>(sin, din);
    Object datum = null;
    long count = reader.getMetaLong("count");
    for (int i = 0; i < count; i++) {
      datum = reader.next(datum);
View Full Code Here

Examples of org.apache.avro.file.SeekableFileInput

    write(writer, new BarRecord(), check);
    write(writer, new BarRecord("Two beers please"), check);
    writer.close();

    ReflectDatumReader din = new ReflectDatumReader("org.apache.avro.");
    SeekableFileInput sin = new SeekableFileInput(FILE);
    DataFileReader<Object> reader = new DataFileReader<Object>(sin, din);
    Object datum = null;
    long count = reader.getMetaLong("count");
    for (int i = 0; i < count; i++) {
      datum = reader.next(datum);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.