RussellSpitzer commented on a change in pull request #2196:
URL: https://github.com/apache/iceberg/pull/2196#discussion_r569602777
##########
File path:
spark/src/test/java/org/apache/iceberg/actions/TestRewriteDataFilesAction.java
##########
@@ -311,6 +320,76 @@ public void testRewriteLargeTableHasResiduals() {
Assert.assertEquals("Rows must match", records, actualRecords);
}
+ @Test
+ public void testRewriteDataFilesForLargeFile() throws IOException,
AnalysisException {
+ PartitionSpec spec = PartitionSpec.unpartitioned();
+ Map<String, String> options = Maps.newHashMap();
+ Table table = TABLES.create(SCHEMA, spec, options, tableLocation);
+ Assert.assertNull("Table must be empty", table.currentSnapshot());
+
+ List<Record> excepted = Lists.newArrayList();
+ Record baseRecord = GenericRecord.create(SCHEMA);
+
+ GenericAppenderFactory genericAppenderFactory = new
GenericAppenderFactory(SCHEMA);
+ int count = 0;
+ File file = temp.newFile();
+ try (FileAppender<Record> fileAppender =
+ genericAppenderFactory.newAppender(Files.localOutput(file),
FileFormat.PARQUET)) {
+ int fileSize = 10000;
+ for (; fileAppender.length() < fileSize; count++) {
+ Record record = baseRecord.copy();
+ record.setField("c1", count);
+ record.setField("c2", "foo" + count);
+ record.setField("c3", "bar" + count);
+ fileAppender.add(record);
+ excepted.add(record);
+ }
+ }
+
+ DataFile dataFile = DataFiles.builder(table.spec())
+ .withPath(file.getAbsolutePath())
+ .withFileSizeInBytes(file.length())
+ .withFormat(FileFormat.PARQUET)
+ .withRecordCount(count)
+ .build();
+
+ table.newAppend().appendFile(dataFile).commit();
+
+ List<ThreeColumnRecord> records1 = Lists.newArrayList(
+ new ThreeColumnRecord(1, "BBBBBBBBBB", "BBBB"),
+ new ThreeColumnRecord(1, "DDDDDDDDDD", "DDDD")
+ );
+ writeRecords(records1);
+
+ table.refresh();
+
+ CloseableIterable<FileScanTask> tasks = table.newScan().planFiles();
+ List<DataFile> dataFiles =
Lists.newArrayList(CloseableIterable.transform(tasks, FileScanTask::file));
+ Assert.assertEquals("Should have 3 scan tasks before rewrite", 3,
dataFiles.size());
Review comment:
Ah yeah I think I was mistaken here, I think we may be generating
multiple files via the writeRecords method which could potentially parallelize
the write resulting in multiple files. (This is for the 2 record file)
Instead we would need to do a repartition(1) to insure a single file is
written.
In my internal test I just did the repartition to make sure we had a single
file writes
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]