While convert RelNode to SqlNode, the "group by" statement in subquery was dropped unexpectedly. For example,
original sql is:
RelNode converted by SqlNode is
And then convert this RelNode to SqlNode, the sql of SqlNode is like this:
We can find that "group by" in subquery was dropped which may cause SqlNode converted by RelNode being not equivalent to RelNode.
After debugging, I've found code
calls org.apache.calcite.rel.rel2sql.SqlImplementor.Builder#setGroupBy without judge whether "group by" already exists.
Finally, I think in this case, the main select and sub-select shouldn't be merged.