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

Migrate ProjectionPushDown to iterative optimizer #7256

Merged

Conversation

losipiuk
Copy link
Contributor

No description provided.

@losipiuk
Copy link
Contributor Author

There is yet some test failure. I will investigate it tomorrow.

Copy link
Contributor

@kokosing kokosing left a 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);
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

as separate commit?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

AliasMatcher?

Copy link
Contributor Author

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()));
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done already

Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope

@martint martint added the planner label Feb 2, 2017
@losipiuk losipiuk force-pushed the lo/projection-pushdown-new-optimizer branch 2 times, most recently from 6a609fc to bafc65c Compare February 2, 2017 15:32
@losipiuk
Copy link
Contributor Author

losipiuk commented Feb 2, 2017

Updated.
@kokosing, @martint please take a look.

It seems like followup of this work would be to introduce explicit-output symbols to ExchangeNode so we always can get rid of Projection on top of exchange and not send unnecessary symbols over the network.

@losipiuk losipiuk force-pushed the lo/projection-pushdown-new-optimizer branch from bafc65c to 76872e2 Compare February 2, 2017 16:38
Copy link
Contributor

@kokosing kokosing left a 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()));
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

use your method here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what method?

Copy link
Contributor

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));
Copy link
Contributor

Choose a reason for hiding this comment

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

use ImmutableList

Copy link
Contributor Author

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)
Copy link
Contributor

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. :)

Copy link
Contributor Author

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)) {
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

use project.isIdentity() here

Copy link
Contributor

Choose a reason for hiding this comment

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

what about shuffle projection?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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());
Copy link
Contributor

Choose a reason for hiding this comment

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

use Assignemnts.ideintity()

@losipiuk losipiuk force-pushed the lo/projection-pushdown-new-optimizer branch from 76872e2 to de1ac09 Compare February 3, 2017 16:14
@losipiuk
Copy link
Contributor Author

losipiuk commented Feb 3, 2017

I addressed the comments. Some questions.

@losipiuk losipiuk force-pushed the lo/projection-pushdown-new-optimizer branch 2 times, most recently from 1f823e2 to 70baada Compare February 3, 2017 16:18
Copy link
Contributor

@kokosing kokosing left a 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;
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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

@losipiuk losipiuk force-pushed the lo/projection-pushdown-new-optimizer branch from 70baada to 81458c6 Compare February 6, 2017 12:29
Copy link
Contributor Author

@losipiuk losipiuk left a 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)
Copy link
Contributor Author

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.
Copy link
Contributor Author

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);
Copy link
Contributor

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.

@findepi findepi dismissed their stale review February 11, 2017 15:30

(minor)

@losipiuk losipiuk force-pushed the lo/projection-pushdown-new-optimizer branch from 81458c6 to 8f99fdc Compare February 23, 2017 09:32
@erichwang
Copy link
Contributor

Just a heads up: I already reviewed and pushed the commit "Extend support for exchange in PlanMatchingVisitor".

@losipiuk losipiuk force-pushed the lo/projection-pushdown-new-optimizer branch from 8f99fdc to 31523c3 Compare March 20, 2017 14:00
@losipiuk losipiuk force-pushed the lo/projection-pushdown-new-optimizer branch from 31523c3 to 1f6588a Compare April 10, 2017 16:39
Copy link
Contributor

@martint martint left a 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 @@
/*
Copy link
Contributor

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.

Copy link
Contributor Author

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 @@
/*
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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

@martint martint assigned losipiuk and unassigned martint May 15, 2017
@losipiuk losipiuk force-pushed the lo/projection-pushdown-new-optimizer branch 2 times, most recently from 982dac3 to 84959ec Compare May 16, 2017 15:52
Copy link
Contributor Author

@losipiuk losipiuk left a 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 @@
/*
Copy link
Contributor Author

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;
Copy link
Contributor Author

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

@losipiuk losipiuk assigned martint and unassigned losipiuk May 16, 2017
@losipiuk losipiuk force-pushed the lo/projection-pushdown-new-optimizer branch from 84959ec to cdd5b68 Compare May 17, 2017 08:41
@martint martint merged commit 648528b into prestodb:master May 17, 2017
@losipiuk losipiuk deleted the lo/projection-pushdown-new-optimizer branch May 18, 2017 12:52
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.

6 participants