rdblue commented on a change in pull request #2196:
URL: https://github.com/apache/iceberg/pull/2196#discussion_r569588414
##########
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());
+
+ spark.read().format("iceberg").load(tableLocation).createTempView("rows");
+ long originalNumRecords =
spark.read().format("iceberg").load(tableLocation).count();
+ List<Object[]> originalRecords = sql("SELECT * from rows sort by c2");
+
+ Actions actions = Actions.forTable(table);
+
+ long targetSizeInBytes = file.length() - 10;
+ RewriteDataFilesActionResult result = actions
+ .rewriteDataFiles()
+ .targetSizeInBytes(targetSizeInBytes)
+ .splitOpenFileCost(1)
+ .execute();
+
+ Assert.assertEquals("Action should delete 4 data files", 4,
result.deletedDataFiles().size());
+ Assert.assertEquals("Action should add 2 data files", 2,
result.addedDataFiles().size());
+
+ long postRewriteNumRecords =
spark.read().format("iceberg").load(tableLocation).count();
+ List<Object[]> rewrittenRecords = sql("SELECT * from rows sort by c2");
Review comment:
I'm not very comfortable with using the same view to load original and
rewritten records. Can you create a separate view for the rewritten data? That
way we avoid any weird caching behavior.
----------------------------------------------------------------
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]