Motivation
-
Not only Rel's but Expression can be shared a "real" common subexpression. However, in Substrait model, sharing expression is not easy due to the field references, which relies on "offset" of binding schema rather than the "identity".
-
Another case is a real function defined in terms of substrait scalar expressions (i.e., UDF).
Proposal
Both scenario can be modeled a function and all the field references can be replaced as a function argument. On referenced site, we can substitute the common expression as a function invocation.
Depending on implementation, one can choose either make it true function call or inline the expression with the specific parameter bindings.
We can reuse the existing lambda infrastructure for definition and call site but the definition must reside in plan scope and in a separate namespace (i.e., separate anchor).
Motivation
Not only Rel's but Expression can be shared a "real" common subexpression. However, in Substrait model, sharing expression is not easy due to the field references, which relies on "offset" of binding schema rather than the "identity".
Another case is a real function defined in terms of substrait scalar expressions (i.e., UDF).
Proposal
Both scenario can be modeled a function and all the field references can be replaced as a function argument. On referenced site, we can substitute the common expression as a function invocation.
Depending on implementation, one can choose either make it true function call or inline the expression with the specific parameter bindings.
We can reuse the existing lambda infrastructure for definition and call site but the definition must reside in plan scope and in a separate namespace (i.e., separate anchor).