The way ReferenceRel is implemented in substrait makes building up queries with CTEs difficult, namely they are referred to by their ordinal positions which obviously can change when one needs to join two tables each having a set of associated CTEs.
I've added support for a simple case of having a single CTE, but I'm gonna defer more work pending on whether substrait changes the way it handles reference relations.
The way ReferenceRel is implemented in substrait makes building up queries with CTEs difficult, namely they are referred to by their ordinal positions which obviously can change when one needs to join two tables each having a set of associated CTEs.
I've added support for a simple case of having a single CTE, but I'm gonna defer more work pending on whether substrait changes the way it handles reference relations.