Confusing behavior of `select()`.

The following traversal acts as a counter:

g.withSideEffect("map", [3: "foo", 4: "bar"]).
  inject("a", "b", "c", "d").
  aggregate(local, "x").
  map(select("x").count(local))


It produces:

==>1
==>2
==>3
==>4


I want to modify the traversal to use this count to produce ["foo", "bar"]. So, I tried adding .as("cnt").select("map").select(select("cnt")) like this:

g.withSideEffect("map", [3: "foo", 4: "bar"]).
  inject("a", "b", "c", "d").
  aggregate(local, "x").
  map(select("x").count(local)).
  as("cnt").
  select("map").select(select('cnt'))


But the code above does not work as expected, it produces no output.

Interestingly, if I change select("cnt") to constant(3), then it starts producing foo:

==>foo
==>foo
==>foo
==>foo


Could someone help me understand why select("cnt") is not working here and why using constant(3) works?

Thanks in advance!
Solution
This is caused (if you are using TinkerGraph for example) by Java's HashMap implementation and the fact that a Long will not match an Integer type.
g.withSideEffect("map", [3L: "foo", 4L: "bar"]).
  inject("a", "b", "c", "d").
  aggregate(local, "x").
  map(select("x").count(local)).
  as("cnt").
  select("map").select(select('cnt')) 

==>foo
==>bar   
Was this page helpful?