Project: datamanagement
Issue DM-737: Rendering an IR node tree should produce properly parenthesized output
It appears that rendering a tree of IR nodes doesn't always result in correct generation of parentheses. Consider the following tree: {panel} * OrTerm ** BoolFactor *** NullPredicate **** ValueExpr ***** ValueFactor: ColumnRef("refObjectId") ** BoolFactor *** CompPredicate **** ValueExpr ***** ValueFactor: ColumnRef("flags") **** Token("<>") **** ValueExpr ***** ValueFactor: Const("2") {panel} which corresponds to the SQL for: "refObjectId IS NULL OR flags<>2". If one prepends this (via {{WhereClause.prependAndTerm()}}) to the {{WhereClause}} obtained by parsing "... WHERE foo!=bar AND baz<3.14159;" and renders the result using {{QueryTemplate}}, one obtains: {{... WHERE refObjectId IS NULL OR flags<>2 AND foo!=bar AND baz<3.14159}} This is equivalent to {{... WHERE refObjectId IS NULL OR (flags<>2 AND foo!=bar AND baz<3.14159)}} which doesn't match the parse tree - one should obtain: {{... WHERE (refObjectId IS NULL OR flags<>2) AND foo!=bar AND baz<3.14159}} This issue involves surveying all IR node classes and making sure that they render parentheses properly. {color:gray}(One way we might test for this is to parse queries containing parenthesized expressions where removal of the parentheses changes the meaning of the query. This would give us some IR that we can render to a string and reparse back into IR. If the rendering logic is correct, one should obtain identical IR trees).{color} Other possibilities that might explain the behavior above is that the input tree is somehow invalid or that {{WhereClause.prependAndTerm}} creates invalid IR.
Story points: 8