rdblue commented on code in PR #4614:
URL: https://github.com/apache/iceberg/pull/4614#discussion_r857183740
##########
spark/v2.4/spark/src/test/java/org/apache/iceberg/spark/source/TestIcebergSourceTablesBase.java:
##########
@@ -1415,6 +1415,89 @@ public void testRemoveOrphanFilesActionSupport() throws
InterruptedException {
Assert.assertEquals("Rows must match", records, actualRecords);
}
+ @Test
+ public void testOverwritePartition() {
+ TableIdentifier tableIdentifier = TableIdentifier.of("db", "entries_test");
+ Table table = createTable(tableIdentifier, SCHEMA,
PartitionSpec.builderFor(SCHEMA).identity("id").build());
+
+ Dataset<Row> df1 = spark.createDataFrame(Lists.newArrayList(new
SimpleRecord(1, "a")), SimpleRecord.class);
+ df1.select("id", "data").write()
+ .format("iceberg")
+ .mode("append")
+ .save(loadLocation(tableIdentifier));
+
+ List<SimpleRecord> result = spark.read()
+ .format("iceberg")
+ .load(loadLocation(tableIdentifier))
+ .as(Encoders.bean(SimpleRecord.class))
+ .collectAsList();
+ Assert.assertEquals(result, Lists.newArrayList(new SimpleRecord(1, "a")));
+
+ // Now, we try to overwrite the partition id=1
+ Dataset<Row> df2 = spark.createDataFrame(Lists.newArrayList(new
SimpleRecord(1, "b")), SimpleRecord.class);
+ df2.select("id", "data").write()
+ .format("iceberg")
+ .mode("overwrite")
+ .option("overwrite-partitions", "id=1")
+ .save(loadLocation(tableIdentifier));
+
+ result = spark.read()
+ .format("iceberg")
+ .load(loadLocation(tableIdentifier))
+ .as(Encoders.bean(SimpleRecord.class))
+ .collectAsList();
Review Comment:
Can you fix the formatting of this file? Continuation indents should be 4
spaces, not 8.
##########
spark/v2.4/spark/src/main/java/org/apache/iceberg/spark/source/Writer.java:
##########
@@ -173,6 +185,38 @@ private void replacePartitions(WriterCommitMessage[]
messages) {
commitOperation(dynamicOverwrite, numFiles, "dynamic partition overwrite");
}
+ private void replaceOverwritePartitions(WriterCommitMessage[] messages) {
+ final Expression overwriteExpression =
parseOverwritePartitionFilter(overwriteFilter);
+ Iterable<DataFile> files = files(messages);
+
+ if (!files.iterator().hasNext()) {
+ LOG.info("Static overwrite is empty, skipping commit");
+ return;
+ }
+
+ OverwriteFiles overwriteFiles = table.newOverwrite()
+ .overwriteByRowFilter(overwriteExpression);
Review Comment:
Indentation is off here as well.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]