calcite
calcite copied to clipboard
[CALCITE-3085] Add RelBaseShuttle, implementation of RelShuttle without stack
org.apache.calcite.rel.RelShuttleImpl class has a protected stack field used to capture parent node when visiting children, but all subclasses in Calcite codebase never read the content of the stack.
The change add a new implementation of RelShuttle named RelBasicShuttle. The implementation do not use/populate a stack.
Also make the class the base class of RelShuttleImpl, along with all the sub-classes of RelShuttleImpl (since none of them requires a stack).
Has this issue shown up empirically?
The stack is implemented as an ArrayDeque
, so push and pop should be very few machine instructions.
RelShuttleImpl
is not the only possible implementation of RelShuttle
. It is just a good general-purpose implementation. If it doesn't meet your needs, you can create your own.
No sub-classes in Calcite use the stack
field, but it's there, and it is potentially useful, if I am looking for say a Filter
within a Project
within a Filter
.
Consider AbstractList
class in the JDK. It contains a modCount
field is useful for most implementations (prevents concurrent modifications) but is unnecessary overhead for sub-classes that are immutable. To avoid that overhead, I created AbstractImmutableList
, but I wouldn't suggest removing modCount
from AbstractList
.
Sorry @julianhyde I just saw the email notification from JIRA, and replied within the ticket. Following the conversation here, I will push a new commit against master (there's no point of keeping the current commit)