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

Refactoring join method in PlanMatchPattern in builder pattern #12423

Closed

Conversation

barunhalderkolkata
Copy link

@barunhalderkolkata barunhalderkolkata commented May 16, 2022

Description

Refactoring join method in PlanMatchPattern in builder pattern

Related issues, pull requests, and links

Fixes #5976

@cla-bot
Copy link

cla-bot bot commented May 16, 2022

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Barun Halder.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@barunhalderkolkata
Copy link
Author

I am raising the PR which is partially complete. I would like to review my approach before making it a too big as there are several places changes need to be done.

@findepi findepi added the no-release-notes This pull request does not require release notes entry label May 17, 2022
@findepi
Copy link
Member

findepi commented May 17, 2022

@sopel39 this is for #5976. please chime in.

also cc @kasiafi @martint @hashhar @raunaqmorarka @findepi who work with plan tests

@cla-bot
Copy link

cla-bot bot commented May 17, 2022

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Barun Halder.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@barunhalderkolkata
Copy link
Author

@raunaqmorarka, @lukasz-stec can you please review the changes? And also help me out about cla-signed, I have already mailed signed documents as per the process.

Copy link
Member

@lukasz-stec lukasz-stec left a comment

Choose a reason for hiding this comment

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

It would be good to find a way to avoid adding new JoinParamUtil.JoinParamBuilder everywhere.

@@ -66,14 +67,15 @@ public void testNonStraddlingJoinExpression()
assertPlan(
"SELECT * FROM orders JOIN lineitem ON orders.orderkey = lineitem.orderkey AND cast(lineitem.linenumber AS varchar) = '2'",
anyTree(
join(INNER, ImmutableList.of(equiJoinClause("ORDERS_OK", "LINEITEM_OK")),
join(new JoinParamUtil.JoinParamBuilder(INNER,
Copy link
Member

Choose a reason for hiding this comment

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

adding new JoinParamUtil.JoinParamBuilder( and .build() everywhere seems verbose.
Could you come up with some solution that avoids that?

Copy link
Author

Choose a reason for hiding this comment

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

Hi @lukasz-stec The only way I am thinking of having a JoinMatcherBuilder which will have static method with params joinType & equiCriteria to create object of JoinMatcher, and setter for other attributes.
Like below,

join(JoinMatcherBuilder.buildMatcher(joinType, equiCriteria).filter(filter), leftPlanMatchPattern, rightPlanMatchPattern)

But that will require to change JoinMatcher from immutable to mutable.
Otherwise, avoiding method overloading to use builder pattern will bring code verbosity. Please guide what can be done?

Copy link
Member

Choose a reason for hiding this comment

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

to remove new JoinParamUtil.JoinParamBuilder you could have a single class, JoinMatcherBuilder

class JoinMatcherBuilder
{
    public static JoinMatcherBuilder join(
      JoinNode.Type joinType,
      List<ExpectedValueProvider<JoinNode.EquiJoinClause>> expectedEquiCriteria,
      PlanMatchPattern left,
      PlanMatchPattern right) {..}

  ...

    PlanMatchPattern build() {...}
}

That still requires build for every current PlanMatchPattern.join method call.
One way to keep it out of tests is to add duplicated method to every method in PlanMatchPattern that takes PlanMatchPattern as param to instead take PlanMatchPatternBuilder (new interface) but that seems too much just for joins.
@sopel39 you're the original issue author. Did you have some ideas on what this should look like when you created the ticket?

import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.trino.sql.tree.ComparisonExpression.Operator.EQUAL;

public class JoinParamUtil
Copy link
Member

Choose a reason for hiding this comment

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

instead of having JoinParamUtil and JoinParamBuilder you could have a single JoinMatcherBuilder that either builds JoinMatcher or PlanMatchPattern

@kasiafi
Copy link
Member

kasiafi commented May 23, 2022

@barunhalderkolkata we already have a few examples in PlanMatchPattern where builders are used. See window() method which uses WindowMatcher.Builder for example. It would be good to follow the same approach when adding new builders.

@sopel39
Copy link
Member

sopel39 commented Oct 21, 2022

Fixed in #14542

@sopel39 sopel39 closed this Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-release-notes This pull request does not require release notes entry
Development

Successfully merging this pull request may close these issues.

Use builders in PlanMatchPattern
5 participants