Julian, I want to add hint support for Calcite, the initial idea was to tag a RelNode(transformed from a SqlNode with hint) with a hit attribute(or trait), then I hope that the children (inputs) of it can see this hint, so to make some decisions if it should consume or propagate the hint.
The problem I got here is the trait propagate from inputs from, which is the opposite as what I need, can you give some suggestions ? If I use MetadataHandler to cache and propagate the hints, how to propagate from parents to children ? Best, Danny Chan 在 2019年4月23日 +0800 AM3:14,Julian Hyde <[email protected]>,写道: > TL;DR: RelNodes don’t really have parents. Be careful if you are relying on > the parent concept too much. Rely on rules instead. > > In the Volcano model, a RelNode doesn’t really have a parent. It might be > used in several places. (RelSet has a field ‘List<RelNode> parents’ that is > kept up to date as planing progresses. But it’s really for Volcano’s internal > use.) > > Even if you are not using Volcano, there are reasons to want the RelNode > graph to be a dag, so again, a RelNode doesn’t have a unique parent. > > RelShuttleImpl has a stack. You can use that to find the parent. But the > “parent” is just “where we came from as we traversed the RelNode graph”. > There may be other “parents” that you do not know about. > > If you have a Project and want to find all parents that are Filters, don’t > even think about “iterating over the parents” of the Project. Just write a > rule that matches a Filter on a Project, and trust Volcano to do its job. > > Julian > > > > > > On Apr 22, 2019, at 6:15 AM, Yuzhao Chen <[email protected]> wrote: > > > > Thx, Stamatis, that somehow make sense, if i pass around the parent node > > every time I visit a RelNode and keep the parents in the cache, but it is > > still not that intuitive. Actually I what a to add a new RelTrait which > > bind to a specific scope, for example: > > > > join-rel(trait1) > > / \ > > join2 join3 > > > > Join-rel has a trait trait1, and I want all the children of join-rel can > > see this trait, with Calcite’s default metadata handler, I can only see the > > trait from children nodes(traits propagate from the inputs), and I have no > > idea how to propagate a trait reversely? > > > > > > Best, > > Danny Chan > > 在 2019年4月22日 +0800 PM8:44,Stamatis Zampetakis <[email protected]>,写道: > > > Hi Danny, > > > > > > Apart from RelShuttle there is also RelVisitor which has a visit method > > > that provides the parent [1]. Not sure, if it suits your needs. > > > > > > Best, > > > Stamatis > > > > > > [1] > > > https://github.com/apache/calcite/blob/ee83efd360793ef4201f4cdfc2af8d837b76ca69/core/src/main/java/org/apache/calcite/rel/RelVisitor.java#L43 > > > > > > > > > On Mon, Apr 22, 2019 at 2:14 PM Yuzhao Chen <[email protected]> wrote: > > > > > > > Now for RelNode, we have method getInput()[1] to fetch the input > > > > RelNodes, but how we fetch the parent ? > > > > > > > > For example, we have plan: > > > > > > > > join-rel > > > > / \ > > > > scan1 scan2 > > > > > > > > > > > > We can get scan1 and scan2 in join-rel directly with method getInput, > > > > but > > > > how can we get the join rel in scan1 and scan 2 ? > > > > > > > > I know that there is a RelShuttle that can visit every RelNode and if I > > > > make a cache for the inputs mapping, finally I can get the ‘parents’ > > > > from > > > > the cache, but this is boring code and not that intuitive. > > > > > > > > Do you guys have any good ideas ? > > > > > > > > [1] > > > > https://github.com/apache/calcite/blob/ee83efd360793ef4201f4cdfc2af8d837b76ca69/core/src/main/java/org/apache/calcite/rel/RelNode.java#L132 > > > > > > > > > > > > Best, > > > > Danny Chan > > > > >
