-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Migrate ProjectionPushDown to iterative optimizer #7256
Migrate ProjectionPushDown to iterative optimizer #7256
Conversation
There is yet some test failure. I will investigate it tomorrow. |
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.
minor comments unless you modified rules
@@ -78,7 +78,7 @@ public Symbol symbol(String name, Type type) | |||
{ | |||
Symbol symbol = new Symbol(name); | |||
|
|||
Type old = symbols.get(symbol); | |||
Type old = symbols.put(symbol, type); |
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.
put if symbols
not contains
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.
But we allow the symbol to already be in the map provided the type match.
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.
Either retain get
here or remove put
5 lines down the road.
@@ -236,7 +237,8 @@ public static PlanMatchPattern join(JoinNode.Type joinType, List<ExpectedValuePr | |||
expectedFilter.map(predicate -> rewriteQualifiedNamesToSymbolReferences(new SqlParser().createExpression(predicate))))); | |||
} | |||
|
|||
public static PlanMatchPattern exchange(PlanMatchPattern... sources) { | |||
public static PlanMatchPattern exchange(PlanMatchPattern... sources) | |||
{ |
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.
as separate commit?
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.
done already
// verify that data originally on symbols aliased as x1 and x2 is part of exchange output | ||
.withAlias("x1") | ||
.withAlias("x2")); | ||
// todo check contents of values |
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.
maybe you could please add support for values
. I see this TODO in so many rule tests that I am surprised that nobody fixed that so far.
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.
I think it is done already if I understand the todo intention correctly
@@ -24,13 +24,13 @@ | |||
import static java.lang.String.format; | |||
import static java.util.Objects.requireNonNull; | |||
|
|||
public class Alias | |||
public class AliasMatches |
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.
AliasMatcher
?
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.
done
{ | ||
// just check alias is present | ||
// return self mapping from symbolAliasesMap. | ||
return symbolAliases.getOptional(alias).map(sr -> new Symbol(sr.getName())); |
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.
put .map(...)
in separate line
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.
done
@@ -124,7 +126,7 @@ public ExchangeBuilder addSource(PlanNode source) | |||
return this; | |||
} | |||
|
|||
public ExchangeBuilder addInputsSet(Symbol ... inputs) | |||
public ExchangeBuilder addInputsSet(Symbol... inputs) |
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.
include this change in the commit which introduced this code
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.
done already
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.
so why do I still see this?
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.
Weird. Annotate in IntelliJ showed last modification from older commit. Fixed.
implements Rule | ||
{ | ||
@Override | ||
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) |
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.
did you have to logically modify the rule somehow?
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.
modifications are in separate commit.
return this; | ||
} | ||
|
||
public ExchangeBuilder singleDistributionPartitioningScheme(Symbol... outputSymbols) |
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.
put it one method above
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.
done
return Optional.of(new UnionNode(node.getId(), outputSources.build(), mappings.build(), ImmutableList.copyOf(mappings.build().keySet()))); | ||
} | ||
|
||
private static Expression translateExpression(Expression inputExpression, Map<Symbol, SymbolReference> symbolMapping) |
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.
maybe put it as static method of ExpressionSymbolInliner
?
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.
Let's leave it for now.
implements Rule | ||
{ | ||
@Override | ||
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) |
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.
did you modify this rule?
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.
Nope
6a609fc
to
bafc65c
Compare
bafc65c
to
76872e2
Compare
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.
Please also address my comments from previous review
public Optional<Symbol> getAssignedSymbol(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) | ||
{ | ||
return symbolAliases.getOptional(alias) | ||
.map(sr -> new Symbol(sr.getName())); |
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.
use Symbol::from
@@ -81,6 +82,13 @@ public SymbolReference get(String alias) | |||
return result; |
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.
use your method here
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.
what method?
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.
use getOptional
in implementation of get
@@ -368,6 +369,11 @@ public PlanMatchPattern withNumberOfOutputColumns(int numberOfSymbols) | |||
* in the outputs. This is the case for symbols that are produced by a direct or indirect | |||
* source of the node you're applying this to. | |||
*/ | |||
public PlanMatchPattern withExactOutputs(String... expectedAliases) | |||
{ | |||
return withExactOutputs(asList(expectedAliases)); |
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.
use ImmutableList
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.
done
* Transforms: | ||
* | ||
* <pre> | ||
* PROJ(x = e1, y = e2) |
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.
use Project instead of PROJ.
Please do not use capitalized names. You do not need to shout. :)
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.
Changed the casing. Not sure if that is actually more readable. Whatever.
@@ -52,6 +81,10 @@ | |||
return Optional.empty(); | |||
} | |||
|
|||
if (isIdentityOrNarrowingProjection(project)) { |
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.
please create an issue about this on github
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.
please modify assert framework for rules to check if rule is unable to be applied two times in a row
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.
Did you mean the issue for check? Teradata#499
Or the issue for old ProjectionPushDown
optimizer? Do we really want to fix that?
return Optional.of(result); | ||
} | ||
|
||
private boolean isIdentityOrNarrowingProjection(ProjectNode project) |
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.
use project.isIdentity()
here
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.
what about shuffle projection?
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.
Yeah - I think we should not do anything about shuffling projection. What is the point?
And actually this method returns true for shulffling projection.
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.
I renamed method to isSymbolToSymbolProjection
|
||
Assignments.Builder newAssignments = Assignments.builder(); | ||
for (Symbol symbol : project.getOutputSymbols()) { | ||
newAssignments.put(symbol, symbol.toSymbolReference()); |
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.
use Assignemnts.ideintity()
76872e2
to
de1ac09
Compare
I addressed the comments. Some questions. |
1f823e2
to
70baada
Compare
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.
some minor comments
@@ -81,6 +82,13 @@ public SymbolReference get(String alias) | |||
return result; |
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.
use getOptional
in implementation of get
return result; | ||
} | ||
|
||
public static PlanMatchPattern values(List<String> aliases) |
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.
maybe add also a method which accepts var-args
@@ -124,7 +126,7 @@ public ExchangeBuilder addSource(PlanNode source) | |||
return this; | |||
} | |||
|
|||
public ExchangeBuilder addInputsSet(Symbol ... inputs) | |||
public ExchangeBuilder addInputsSet(Symbol... inputs) |
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.
so why do I still see this?
* </pre> | ||
* | ||
* | ||
* To avoid looping this optimizer will not be fired if upper Project contains just symbol references. |
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.
have you posted an issue on github about this problem in legacy rule? If so can you please attach the link to it?
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.
Discussed that it is about need for projection above Exchange node sometimes.
This is the issue: #7307
70baada
to
81458c6
Compare
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.
Updated
@@ -124,7 +126,7 @@ public ExchangeBuilder addSource(PlanNode source) | |||
return this; | |||
} | |||
|
|||
public ExchangeBuilder addInputsSet(Symbol ... inputs) | |||
public ExchangeBuilder addInputsSet(Symbol... inputs) |
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.
Weird. Annotate in IntelliJ showed last modification from older commit. Fixed.
* </pre> | ||
* | ||
* | ||
* To avoid looping this optimizer will not be fired if upper Project contains just symbol references. |
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.
Discussed that it is about need for projection above Exchange node sometimes.
This is the issue: #7307
@@ -78,7 +78,7 @@ public Symbol symbol(String name, Type type) | |||
{ | |||
Symbol symbol = new Symbol(name); | |||
|
|||
Type old = symbols.get(symbol); | |||
Type old = symbols.put(symbol, type); |
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.
Either retain get
here or remove put
5 lines down the road.
81458c6
to
8f99fdc
Compare
Just a heads up: I already reviewed and pushed the commit "Extend support for exchange in PlanMatchingVisitor". |
8f99fdc
to
31523c3
Compare
31523c3
to
1f6588a
Compare
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.
Minor comments, but otherwise looks good. Please reassign to me once you've addressed them and I'll merge it.
@@ -0,0 +1,156 @@ | |||
/* |
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.
Squash this commit with the one that ports the rule.
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.
Sure.
But note that test fails without the "changes" commit, as just-ported code does not ensure that Node after rewrite exposes same number of outputs.
Maybe we should squash all the three commits together. I left them separate mostly to make review easier.
@@ -0,0 +1,131 @@ | |||
/* |
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.
Rename this commit to "Migrate projection pushdown through exchange to iterative rule"
@@ -35,6 +35,37 @@ | |||
import java.util.Map; |
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.
Instead of repeating the commit title of the other commit with the "(changes)" qualifier, describe what the changes are.
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.
Changed commit message to:
Ensure output symbols do not change after pushing projection through exchange
982dac3
to
84959ec
Compare
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.
Addressed and rebased to origin/master.
As I mentioned in one of the replies I would consider merging the Ensure output symbols do not change after pushing projection through exchange
into Migrate projection pushdown through exchange to iterative rule
@@ -0,0 +1,156 @@ | |||
/* |
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.
Sure.
But note that test fails without the "changes" commit, as just-ported code does not ensure that Node after rewrite exposes same number of outputs.
Maybe we should squash all the three commits together. I left them separate mostly to make review easier.
@@ -35,6 +35,37 @@ | |||
import java.util.Map; |
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.
Changed commit message to:
Ensure output symbols do not change after pushing projection through exchange
Beside porting the code changes to rule where needto to ensure output symbols do not change after pushing projection through exchange.
84959ec
to
cdd5b68
Compare
No description provided.