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

Conversation

ajantha-bhat
Copy link
Member

@ajantha-bhat ajantha-bhat commented Jan 30, 2023

Incase of no-op (when the manifests are already optimized), rewrite manifest can still create one new file from the old file with the same contents. Which is a waste of resources. Hence, handling the no-op scenario.

Examples of no-op scenarios:
a) have one manifest and user calls rewrite manifests.
b) output of previous rewrite has created one smaller manifest (residual manifest after rewriting all the manifest to the target size) and user calls rewrite-manifests again.

  • Have five manifests of 5MB each and target size is 8MB.
    The first time calling rewrite will create three 8MB file and one 1MB file.
    If the rewrite is called again, no need to write just 1MB file into a new 1MB file.

@github-actions github-actions bot added the spark label Jan 30, 2023

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.

@ajantha-bhat ajantha-bhat marked this pull request as draft January 30, 2023 05:59
@@ -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.

@@ -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.

.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


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

@ajantha-bhat ajantha-bhat marked this pull request as ready for review January 30, 2023 07:04
@ajantha-bhat
Copy link
Member Author

@aokolnychyi
Copy link
Contributor

I should be able to take a look.

@@ -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

@aokolnychyi
Copy link
Contributor

The change makes sense but we must be able to rewrite large manifests.

@ajantha-bhat
Copy link
Member Author

ajantha-bhat commented Feb 1, 2023

The change makes sense but we must be able to rewrite large manifests.

@aokolnychyi: 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.

@aokolnychyi
Copy link
Contributor

My bad, I overlooked the condition, @ajantha-bhat!

@aokolnychyi aokolnychyi merged commit 6165a7d into apache:master Feb 3, 2023
@aokolnychyi
Copy link
Contributor

Thanks, @ajantha-bhat! I merged this. Would you mind following up with cherry-picks to other versions?

@ajantha-bhat
Copy link
Member Author

Thanks, @ajantha-bhat! I merged this. Would you mind following up with cherry-picks to other versions?

Thanks for merging. Today I will work on backporting this PR to other spark versions.

@ajantha-bhat
Copy link
Member Author

@aokolnychyi: back ported PR details.
3.2: #6730
3.1: #6731
2.4: #6733

@aokolnychyi
Copy link
Contributor

Thanks, @ajantha-bhat. Merged them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants