.writingBase(false)
.minimumTransactionId(10)
.maximumTransactionId(19)
.inspector(inspector)
.reporter(Reporter.NULL);
RecordUpdater updater = new OrcRecordUpdater(root, options);
updater.insert(11, new MyRow("first"));
updater.insert(11, new MyRow("second"));
updater.insert(11, new MyRow("third"));
updater.flush();
updater.insert(12, new MyRow("fourth"));
updater.insert(12, new MyRow("fifth"));
updater.flush();
// Check the stats
assertEquals(5L, updater.getStats().getRowCount());
Path bucketPath = AcidUtils.createFilename(root, options);
Path sidePath = OrcRecordUpdater.getSideFile(bucketPath);
DataInputStream side = fs.open(sidePath);
// read the stopping point for the first flush and make sure we only see
// 3 rows
long len = side.readLong();
Reader reader = OrcFile.createReader(bucketPath,
new OrcFile.ReaderOptions(conf).filesystem(fs).maxLength(len));
assertEquals(3, reader.getNumberOfRows());
// read the second flush and make sure we see all 5 rows
len = side.readLong();
side.close();
reader = OrcFile.createReader(bucketPath,
new OrcFile.ReaderOptions(conf).filesystem(fs).maxLength(len));
assertEquals(5, reader.getNumberOfRows());
RecordReader rows = reader.rows();
// check the contents of the file
assertEquals(true, rows.hasNext());
OrcStruct row = (OrcStruct) rows.next(null);
assertEquals(OrcRecordUpdater.INSERT_OPERATION,
OrcRecordUpdater.getOperation(row));
assertEquals(11, OrcRecordUpdater.getCurrentTransaction(row));
assertEquals(11, OrcRecordUpdater.getOriginalTransaction(row));
assertEquals(10, OrcRecordUpdater.getBucket(row));
assertEquals(0, OrcRecordUpdater.getRowId(row));
assertEquals("first",
OrcRecordUpdater.getRow(row).getFieldValue(0).toString());
assertEquals(true, rows.hasNext());
row = (OrcStruct) rows.next(null);
assertEquals(1, OrcRecordUpdater.getRowId(row));
assertEquals(10, OrcRecordUpdater.getBucket(row));
assertEquals("second",
OrcRecordUpdater.getRow(row).getFieldValue(0).toString());
assertEquals(true, rows.hasNext());
row = (OrcStruct) rows.next(null);
assertEquals(2, OrcRecordUpdater.getRowId(row));
assertEquals(10, OrcRecordUpdater.getBucket(row));
assertEquals("third",
OrcRecordUpdater.getRow(row).getFieldValue(0).toString());
assertEquals(true, rows.hasNext());
row = (OrcStruct) rows.next(null);
assertEquals(12, OrcRecordUpdater.getCurrentTransaction(row));
assertEquals(12, OrcRecordUpdater.getOriginalTransaction(row));
assertEquals(10, OrcRecordUpdater.getBucket(row));
assertEquals(0, OrcRecordUpdater.getRowId(row));
assertEquals("fourth",
OrcRecordUpdater.getRow(row).getFieldValue(0).toString());
assertEquals(true, rows.hasNext());
row = (OrcStruct) rows.next(null);
assertEquals(1, OrcRecordUpdater.getRowId(row));
assertEquals("fifth",
OrcRecordUpdater.getRow(row).getFieldValue(0).toString());
assertEquals(false, rows.hasNext());
// add one more record and close
updater.insert(20, new MyRow("sixth"));
updater.close(false);
reader = OrcFile.createReader(bucketPath,
new OrcFile.ReaderOptions(conf).filesystem(fs));
assertEquals(6, reader.getNumberOfRows());
assertEquals(6L, updater.getStats().getRowCount());
assertEquals(false, fs.exists(sidePath));
}