You can't find the parent when firing a rule, because in a Volcano planner a RelNode may have multiple parents. So you need to take a different approach. I suggest that you write multiple rules, each of which matches a parent and child (or children), and apply those rules in succession.
This approach handles most cases. Occasionally you need to match the whole tree, or large parts of the tree. LoptMultiJoin and RelFieldTrimmer are cases where we needed to use this approach. But if you can, stay within the Volcano approach. Your rules are more resilient, composable and re-usable if they just match small regions of the tree. You achieve big effects by composing multiple rules. Julian On Sun, Jul 9, 2017 at 7:40 AM, Muhammad Gelbana <[email protected]> wrote: > I need to traverse the parents of *JdbcTableScan*(s). But the > *RelOptRuleCall.getParents()* never returned anything but *NULL* to me. So > how can I get the parents of a matched node while a rule is being executed > ? Also the *RelNode* interface doesn't seem to provide a similar method to > get the node's parents. And after getting the parents, how can I convert > one of the parents instead the matched node ? > > If you find my question weird, please consider the following plan > > JdbcSort > *JdbcAggregate* > JdbcProject > JdbcJoin > JdbcJoin > JdbcTableScan > JdbcTableScan > *JdbcProject* > JdbcFilter > *JdbcAggregate* > JdbcProject > JdbcJoin > JdbcTableScan > JdbcTableScan > > There are 2 *JdbcAggregate* nodes (in bold) in this plan. I need to write a > rule that can *convert* nodes with the following conditions: > > 1. It's children cover as much nodes as possible of the plan. > 2. It's children includes only one *JdbcAggregate*. > 3. It's children does not include a BiRel. > > This means that I need to *convert* the underlined *JdbcProject* node only. > To do that, I believe I need to traverse the parents of *JdbcTableScan*(s) > (i.e. the lowest possible node in a plan).
