Deterministically desugar instance methods into equivalent scalar functions
Author: findepiCreated Sep 23, 2026Updated Sep 23, 2026
Labelsperformance
Today an instance method like x.reverse() gets desugared into ordinary scalar function reverse(x) only if it's a conjunct of a predicate where some other conjunct is pushed down into the connector.
More precisely, in connector expressions, reverse(x) and x.reverse() are both represented as the same thing Call("reverse", [x]) (which is good, the connectors shouldn't need to handle different forms of equivalent function). Later, when translating back Call("reverse", [x])→ becomesreverse(x). Thus, ConnectorExpressionTranslator` desugers the instance method form into ordinary scalar function (which is also good for runtime: bytecode generation caches and JIT both benefit from this deduplication).
- the existing desugaring mechanism looks like incidental side effect of
ConnectorExpressionTranslator. it could be made more explicit - the desugating should take place independently from connector pushdowns, it should be applied together with other expression simplification optimizer rules
- it should be the early stage so that optimizer rules that match specific scalar functions do not need to learn about their equivalent instance method forms
Source: trinodb/trino