You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/05/09 14:04:38 UTC

[GitHub] [incubator-doris] 924060929 opened a new pull request, #9474: [Enhancement](Optimizer) Nereids pattern matching base framework

924060929 opened a new pull request, #9474:
URL: https://github.com/apache/incubator-doris/pull/9474

   # Proposed changes
   
   Issue Number: close #6483
   
   ## Problem Summary:
   This pr provide a new pattern matching framework for Nereids optimizer.
   
   The new pattern matching framework contains this concepts:
   
   1. `Pattern`/`PatternDescriptor`: the tree node's multiple hierarchy shape, e.g. `logicalJoin(logicalJoin(), any()` pattern describe a plan that root is a `LogicalJoin` and the left child is `LogicalJoin` too.
   2. `MatchedAction`: a callback function when the pattern matched, usually you can create new plan to replace the origin matched plan.
   3. `MatchingContext`: the param pass through MatchedAction, contains the matched plan root and the PlannerContext.
   4. `PatternMatcher`: contains PatternDescriptor and MatchedAction
   5. `Rule`: a rewrite rule contains RuleType, PatternPromise, Pattern and transform function(equals to MatchedAction)
   6. `RuleFactory`: the factory can help us build Rules easily. RuleFactory extends Patterns interface, and have some predefined pattern descriptors.
   
   for example, Join commutative:
   ```java
   public class JoinCommutative extends OneExplorationRuleFactory {
       @Override
       public Rule build() {
           return innerLogicalJoin().thenApply(ctx -> {
               return new LogicalJoin(
                   JoinType.INNER_JOIN,
                   ctx.root.getOnClause(),
                   ctx.root.right(),
                   ctx.root.left()
               );
           }).toRule(RuleType.LOGICAL_JOIN_COMMUTATIVE);
       }
   }
   ```
   
   the code above show the three step to create a Rule
   1. 'innerLogicalJoin()' declare pattern  is an inner logical join. 'innerLogicalJoin' is a predefined pattern.
   2. invoke 'then' function to combine a MatchedAction, return a new LogicalJoin with exchange children.
   3. invoke 'toRule' to convert to Rule
   
   You can think the Rule contains three parts: 
   1. Pattern
   2. transform function / MatchedAction
   3. RuleType and RulePromise
   
   So
   1. `innerLogicalJoin()` create a `PatternDescriptor`, which contains a `Pattern`
   2. `PatternDescriptor.then()` convert `PatternDescriptor` to `PatternMatcher,` witch contains Pattern and MatchedAction
   3. `PatternMatcher.toRule()` convert `PatternMatcher` to a Rule
   
   This three step inspired by the currying in function programing.
   
   It should be noted, #9446 provide a generic type for TreeNode's children, so we can infer multiple hierarchy type in this pattern matching framework, so you can get the really tree node type without unsafely cast. like this:
   ```java
   logicalJoin(logicalJoin(), any()).then(j -> {
        // j can be infer type to LogicalJoin<LogicalJoin<Plan, Plan>, Plan>
        // so j.left() can be infer type to LogicalJoin<Plan, Plan>,
        // so you don't need to cast j.left() from 'Plan' to 'LogicalJoin'
        var node = j.left().left();
   })
   ```
   
   
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: No
   5. Has unit tests been added: No Need
   7. Has document been added or modified: No Need
   8. Does it need to update dependencies: No
   9. Are there any changes that cannot be rolled back: Yes
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] github-actions[bot] commented on pull request #9474: [Enhancement](Optimizer) Nereids pattern matching base framework

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #9474:
URL: https://github.com/apache/incubator-doris/pull/9474#issuecomment-1121196511

   PR approved by at least one committer and no changes requested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] github-actions[bot] commented on pull request #9474: [Enhancement](Optimizer) Nereids pattern matching base framework

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #9474:
URL: https://github.com/apache/incubator-doris/pull/9474#issuecomment-1121781020

   PR approved by at least one committer and no changes requested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] github-actions[bot] commented on pull request #9474: [Enhancement](Optimizer) Nereids pattern matching base framework

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #9474:
URL: https://github.com/apache/incubator-doris/pull/9474#issuecomment-1121196576

   PR approved by anyone and no changes requested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] EmmyMiao87 merged pull request #9474: [Enhancement](Optimizer) Nereids pattern matching base framework

Posted by GitBox <gi...@apache.org>.
EmmyMiao87 merged PR #9474:
URL: https://github.com/apache/incubator-doris/pull/9474


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org