Describe the bug
There seems to be an issue with the compiler where aliases in union subqueries cannot be referenced correctly. Below is an example that illustrates the problem:
gremlin> g.V().limit(1).union(out(), out().out()).as('a').select('a').count()
ErrorCode: TAG_NOT_FOUND
Message: {alias=a} not found; expected aliases are: [_]
Workaround Solution:
By rewriting the query, we can achieve the expected results:
gremlin> g.V().limit(1).union(out().as('a'), out().out().as('a')).select('a').count()
==>30033
To reproduce, compiler configuration is as follows:
graph.planner.is.on=true
graph.planner.opt=RBO
graph.planner.rules=FilterIntoJoinRule, FilterMatchRule, ExtendIntersectRule, ExpandGetVFusionRule
graph.physical.opt=proto
gremlin.script.language.name=antlr_gremlin_calcite