Hi Ian, There are some workarounds to find the root node inside a RelRule match but these rules become planner specific. For instance, Hive applies some workarounds (e.g., in HiveFieldTrimmerRule[1]) for running inside rules, transformations that apply and modify the whole plan.
Best, Stamatis [1] https://github.com/apache/hive/blob/58b05f72f74dd35214c3d33c2008b16124fdb25f/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveFieldTrimmerRule.java#L30 On Tue, May 4, 2021 at 2:50 AM Haisheng Yuan <hy...@apache.org> wrote: > Hi Ian, > > Is there any specific reason or use case that you have to match the root > node and find the parent node in your customized rule? > > Thanks, > Haisheng Yuan > > On 2021/05/03 20:20:22, Julian Hyde <jh...@apache.org> wrote: > > > Is there a way to identify a node as being a root node during > RelRule.match? > > > > Not currently. One workaround would be to create 'class MyRoot extends > > SingleRel', add it as the root of the tree, and write your rules to > > match on it. > > > > > Or more generally, is there a way to collect the parents of an > arbitrary RelNode? > > > > By design, the only way to find the parents of a RelNode are to write > > a rule that matches those parents. This ensures that rules will work > > in the Volcano planner, where a RelNode can have many parents. > > > > Julian > > > > On Mon, May 3, 2021 at 12:52 PM Ian Bertolacci > > <ian.bertola...@workday.com.invalid> wrote: > > > > > > Hello, > > > I am trying to write a rule that matches (among other things) the root > of a RelNode tree. > > > > > > Unfortunately, it seems that HepRuleCall.parents is only initialized > and populated if the rule extends CommonRelSubExpr, which doesn’t really > apply in my case. > > > (see: > https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java#L526 > ) > > > > > > Is there a way to identify a node as being a root node during > RelRule.match? Or more generally, is there a way to collect the parents of > an arbitrary RelNode? > > > > > > Thanks. > > >