-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix explicit tableOptions hint handling in PinotImplicitTableHintRule #19003
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
Open
yashmayya
wants to merge
1
commit into
apache:master
Choose a base branch
from
yashmayya:fix-implicit-table-hint-explicit-options
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+74
−11
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| package org.apache.pinot.calcite.rel.rules; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import javax.annotation.Nullable; | ||
| import org.apache.calcite.plan.RelOptRuleCall; | ||
|
|
@@ -75,7 +76,7 @@ public void onMatch(RelOptRuleCall call) { | |
| @Nullable | ||
| RelHint explicitHint = getTableOptionHint(tableScan); | ||
| TableOptions tableOptions = calculateTableOptions(explicitHint, implicitTableOptions, tableScan); | ||
| RelNode newRel = withNewTableOptions(tableScan, tableOptions); | ||
| RelNode newRel = withNewTableOptions(tableScan, tableOptions, explicitHint); | ||
| call.transformTo(newRel); | ||
| } | ||
|
|
||
|
|
@@ -102,23 +103,31 @@ private static RelHint getTableOptionHint(TableScan tableScan) { | |
| } | ||
|
|
||
| /** | ||
| * Returns a new node which is a copy of the given table scan with the new table options hint. | ||
| * Returns a new node which is a copy of the given table scan with a rebuilt table options hint: options from the | ||
| * explicit hint that are not modeled by {@link TableOptions} (e.g. is_replicated) are carried over, and the merged | ||
| * (inferred + explicitly overridden) partition options overwrite the explicitly supplied ones. | ||
| */ | ||
| private static RelNode withNewTableOptions(TableScan tableScan, TableOptions tableOptions) { | ||
| private static RelNode withNewTableOptions(TableScan tableScan, TableOptions tableOptions, | ||
| @Nullable RelHint explicitHint) { | ||
| ArrayList<RelHint> newHints = new ArrayList<>(tableScan.getHints()); | ||
|
|
||
| newHints.removeIf(relHint -> relHint.hintName.equals(PinotHintOptions.TABLE_HINT_OPTIONS)); | ||
|
|
||
| RelHint.Builder builder = RelHint.builder(PinotHintOptions.TABLE_HINT_OPTIONS) | ||
| .hintOption(PinotHintOptions.TableHintOptions.PARTITION_KEY, tableOptions.getPartitionKey()) | ||
| .hintOption(PinotHintOptions.TableHintOptions.PARTITION_FUNCTION, tableOptions.getPartitionFunction()) | ||
| .hintOption(PinotHintOptions.TableHintOptions.PARTITION_SIZE, String.valueOf(tableOptions.getPartitionSize())); | ||
|
|
||
| // Seed with the explicitly supplied options so that the ones not rebuilt from the given table options (e.g. | ||
| // is_replicated) are carried over, then overwrite with the merged (inferred + explicitly overridden) partition | ||
| // options. | ||
| Map<String, String> kvOptions = | ||
| explicitHint != null ? new LinkedHashMap<>(explicitHint.kvOptions) : new LinkedHashMap<>(); | ||
| kvOptions.put(PinotHintOptions.TableHintOptions.PARTITION_KEY, tableOptions.getPartitionKey()); | ||
| kvOptions.put(PinotHintOptions.TableHintOptions.PARTITION_FUNCTION, tableOptions.getPartitionFunction()); | ||
| kvOptions.put(PinotHintOptions.TableHintOptions.PARTITION_SIZE, String.valueOf(tableOptions.getPartitionSize())); | ||
| if (tableOptions.getPartitionParallelism() != null) { | ||
| builder.hintOption(PinotHintOptions.TableHintOptions.PARTITION_PARALLELISM, | ||
| kvOptions.put(PinotHintOptions.TableHintOptions.PARTITION_PARALLELISM, | ||
| String.valueOf(tableOptions.getPartitionParallelism())); | ||
| } | ||
|
|
||
| RelHint.Builder builder = RelHint.builder(PinotHintOptions.TABLE_HINT_OPTIONS); | ||
| kvOptions.forEach(builder::hintOption); | ||
| newHints.add(builder.build()); | ||
|
|
||
| return tableScan.withHints(newHints); | ||
|
|
@@ -152,7 +161,7 @@ private static TableOptions calculateTableOptions( | |
| */ | ||
| private static ImmutableTableOptions overridePartitionKey(ImmutableTableOptions base, TableScan tableScan, | ||
| Map<String, String> kvOptions) { | ||
| String partitionKey = kvOptions.get(kvOptions.get(PinotHintOptions.TableHintOptions.PARTITION_KEY)); | ||
| String partitionKey = kvOptions.get(PinotHintOptions.TableHintOptions.PARTITION_KEY); | ||
| if (partitionKey == null || partitionKey.equals(base.getPartitionKey())) { | ||
| return base; | ||
| } | ||
|
|
@@ -165,7 +174,7 @@ private static ImmutableTableOptions overridePartitionKey(ImmutableTableOptions | |
| */ | ||
| private static ImmutableTableOptions overridePartitionFunction(ImmutableTableOptions base, | ||
| TableScan tableScan, Map<String, String> kvOptions) { | ||
| String partitionFunction = kvOptions.get(kvOptions.get(PinotHintOptions.TableHintOptions.PARTITION_FUNCTION)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol + 1 |
||
| String partitionFunction = kvOptions.get(PinotHintOptions.TableHintOptions.PARTITION_FUNCTION); | ||
| if (partitionFunction == null || partitionFunction.equals(base.getPartitionFunction())) { | ||
| return base; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol