@Test
public void testAliasesWithinUnion() {
Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "A");
Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "B");
a.addEdge("edge", b);
// First, confirm that a simple traversal using an alias works properly. This works as
// expected (the failure is below with the union where the exact traversal is used inside the union).
List<Vertex> noUnionItems = this.sqlgGraph.traversal()
.V()
.hasLabel("A")
.as("alias1")
.out()
.<Vertex>select("alias1")
.toList();
Assert.assertEquals(1, noUnionItems.size());
Assert.assertEquals(a, noUnionItems.get(0));
// This one doesn't work even though the exact same traversal is used inside the union. Debugging
// the code shows that it cannot find the "alias1" label in the SelectOneStep (in the map method).
List<Vertex> unionItems = this.sqlgGraph.traversal()
.V()
.limit(1) // Normally an inject would be used here, but see #415
.<Vertex>union(
__.V().hasLabel("A").as("alias1").out().select("alias1")
)
.toList();
// This fails because unionItems contains 0 results.
Assert.assertEquals(1, unionItems.size());
}
This test illustrates the problem: