Soumyadeep, To me, your approach is the simplest one.
If you want to try a planner rule, then you must consider several things, which will be more complicated: - The rule only matches a pattern, e.g., a Filter on top of Aggregate. This means that if your RelNode tree has multiple matches, you cannot easily distinguish them (I assume you only want to match the outer most one). - After you have done the work in RelNode level, then you need to transform it to SqlNode again to get SQL, that means you need to use `RelToSqlConverter`. Soumyadeep Mukhopadhyay <[email protected]> 于2023年5月27日周六 18:48写道: > Hello all, > > *I was trying to implement a filter rule which can add an extra predicate*, > for example: > *look for GROUP BY clause in a query, check if HAVING is present, if not > add HAVING COUNT(*)>120.* > > *I was trying to do the following: * > https://gist.github.com/Soumyadeep-github/47c1131bf02149af995d8e3bccb3ee67 > > *My approach in this gist *: > get a SqlNode (parsed query) ==> visit each SqlCall node recursively ==> > find SqlSelect (since there's getHaving and setHaving) ==> create a new > dummy query and extract having from the query ==> > set Having for the current query at hand via the dummy query. > > *I was wondering if* the same could be achieved in a planner rule. It may > not be a good idea but, for the sake of trying it out, do you think it is > possible? If yes, could you please give me a rough road map. > > Thank you for your time and patience! > > With regards, > Soumyadeep Mukhopadhyay. > -- Best, Benchao Li
