Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spark-3.3: Handle no-op for rewrite manifests procedure/action #6695

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ public void testRewriteLargeManifests() {
"Must have 4 manifests", 4, table.currentSnapshot().allManifests(table.io()).size());
}

@Test
public void testRewriteManifestsNoOp() {
sql(
"CREATE TABLE %s (id bigint NOT NULL, data string) USING iceberg PARTITIONED BY (data)",
tableName);
sql("INSERT INTO TABLE %s VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')", tableName);

Table table = validationCatalog.loadTable(tableIdent);

Assert.assertEquals(
"Must have 1 manifest", 1, table.currentSnapshot().allManifests(table.io()).size());

List<Object[]> output = sql("CALL %s.system.rewrite_manifests('%s')", catalogName, tableIdent);
// should not rewrite any manifests for no-op (output of rewrite is same as before and after)
assertEquals("Procedure output must match", ImmutableList.of(row(0, 0)), output);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the result will be (1,1) without this PR.


table.refresh();

Assert.assertEquals(
"Must have 1 manifests", 1, table.currentSnapshot().allManifests(table.io()).size());
}

@Test
public void testRewriteLargeManifestsOnDatePartitionedTableWithJava8APIEnabled() {
withSQLConf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ private RewriteManifests.Result doExecute() {
int targetNumManifests = targetNumManifests(totalSizeBytes);
int targetNumManifestEntries = targetNumManifestEntries(numEntries, targetNumManifests);

if (targetNumManifests == 1 && matchingManifests.size() == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is safe as the only manifest that may match may be huge, which would be a bottleneck for planning. It is a valid scenario to be able to split one giant manifest into a number of smaller ones.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip this iff the size of the manifest is under the target manifest size.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need tests for both scenarios.

Copy link
Member Author

@ajantha-bhat ajantha-bhat Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewriting one big manifest into smaller manifests still works with this change and we have testcases for it.
It works because targetNumManifests will be more than one in that case. So, it won't enter the new code.

We already have tests for both scenario's in this file it is called testRewriteLargeManifests

return BaseRewriteManifestsActionResult.empty();
}

Dataset<Row> manifestEntryDF = buildManifestEntryDF(matchingManifests);

List<ManifestFile> newManifests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ public void testRewriteImportedManifests() throws IOException {
SparkTableUtil.importSparkTable(
spark, new TableIdentifier("parquet_table"), table, stagingDir.toString());

// add some more data to create more than one manifest for the rewrite
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a 1-to-1 no-op. So, added one more manifest to avoid no-op.

inputDF.select("c1", "c2", "c3").write().format("iceberg").mode("append").save(tableLocation);
table.refresh();

Snapshot snapshot = table.currentSnapshot();

SparkActions actions = SparkActions.get();
Expand Down Expand Up @@ -431,6 +435,8 @@ public void testRewriteManifestsWithPredicate() throws IOException {
new ThreeColumnRecord(1, null, "AAAA"), new ThreeColumnRecord(1, "BBBBBBBBBB", "BBBB"));
writeRecords(records1);

writeRecords(records1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a 1-to-1 no-op. So, added one more manifest to avoid no-op.


List<ThreeColumnRecord> records2 =
Lists.newArrayList(
new ThreeColumnRecord(2, "CCCCCCCCCC", "CCCC"),
Expand All @@ -440,21 +446,24 @@ public void testRewriteManifestsWithPredicate() throws IOException {
table.refresh();

List<ManifestFile> manifests = table.currentSnapshot().allManifests(table.io());
Assert.assertEquals("Should have 2 manifests before rewrite", 2, manifests.size());
Assert.assertEquals("Should have 3 manifests before rewrite", 3, manifests.size());

SparkActions actions = SparkActions.get();

// rewrite only the first manifest without caching
RewriteManifests.Result result =
actions
.rewriteManifests(table)
.rewriteIf(manifest -> manifest.path().equals(manifests.get(0).path()))
.rewriteIf(
manifest ->
(manifest.path().equals(manifests.get(0).path())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selecting more than one manifests for rewrite

|| (manifest.path().equals(manifests.get(1).path()))))
.stagingLocation(temp.newFolder().toString())
.option("use-caching", "false")
.execute();

Assert.assertEquals(
"Action should rewrite 1 manifest", 1, Iterables.size(result.rewrittenManifests()));
"Action should rewrite 2 manifest", 2, Iterables.size(result.rewrittenManifests()));
Assert.assertEquals(
"Action should add 1 manifests", 1, Iterables.size(result.addedManifests()));

Expand All @@ -464,11 +473,16 @@ public void testRewriteManifestsWithPredicate() throws IOException {
Assert.assertEquals("Should have 2 manifests after rewrite", 2, newManifests.size());

Assert.assertFalse("First manifest must be rewritten", newManifests.contains(manifests.get(0)));
Assert.assertFalse(
"Second manifest must be rewritten", newManifests.contains(manifests.get(1)));
Assert.assertTrue(
"Second manifest must not be rewritten", newManifests.contains(manifests.get(1)));
"Third manifest must not be rewritten", newManifests.contains(manifests.get(2)));

List<ThreeColumnRecord> expectedRecords = Lists.newArrayList();
expectedRecords.addAll(records1);
expectedRecords.add(records1.get(0));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorted order insert

expectedRecords.add(records1.get(0));
expectedRecords.add(records1.get(1));
expectedRecords.add(records1.get(1));
expectedRecords.addAll(records2);

Dataset<Row> resultDF = spark.read().format("iceberg").load(tableLocation);
Expand Down