neo4j/community — Issue #114: Gremlin Table Projections - Column Order Incorrect when using chained .As('x').As('y') 
Author: Romiko
Created: 2011-11-30 00:29:52+00:00
State: open

EXPECTED Order: Createdy, ReferralGroup, ReferralId, ReferralData

When AS statements appear next to each other.
Consider A (WORKS – But not logical – have to reverse order when more than 1 AS statement is chained together right after each other for column array to match):
{"script":"g.v(0).outE[[label:'HOSTS']].inV.filter{ it.Key == 'romikoagency' }.inE[[label:'USER_BELONGS_TO']].outV.filter{ it.Username == 'romiko.derbynew' }.as('CreatedBy').outE[[label:'USER_LINKED_TO_PROGRAM']].inV.as('ReferralGroup').inE[[label:'HAS_SUGGESTED_PROGRAM']].outV.inE[[label:'REFERRAL_HAS_DECISIONS_SECTION']].outV.as('ReferralDate').as('ReferralId').table(new Table()){it.Username}{it.Name}{it.UniqueId}{it.DateInitiatedUtc}.cap"
}

notice: as('ReferralDate').as('ReferralId') and then notice the column order below is opposite this: "columns" .... "ReferralId", "ReferralDate" ]

Results
[ [ {
"data" : [ [ "romiko.derbynew", "Testa", 331, "/Date(1322007153048+1100)/" ], [ "romiko.derbynew", "Testa", 321, "/Date(1322003375637+1100)/" ]],
"columns" : [ "CreatedBy", "ReferralGroup", "ReferralId", "ReferralDate" ]
} ] ]

Consider B (Does not work – this is more LOGICAL from gremlin perspective but is bugged, the Chained AS right after each other gets reversed in the column array.)
{"script":"g.v(0).outE[[label:'HOSTS']].inV.filter{ it.Key == 'romikoagency' }.inE[[label:'USER_BELONGS_TO']].outV.filter{ it.Username == 'romiko.derbynew' }.as('CreatedBy').outE[[label:'USER_LINKED_TO_PROGRAM']].inV.as('ReferralGroup').inE[[label:'HAS_SUGGESTED_PROGRAM']].outV.inE[[label:'REFERRAL_HAS_DECISIONS_SECTION']].outV.as('ReferralId').as('ReferralDate').table(new Table()){it.Username}{it.Name}{it.UniqueId}{it.DateInitiatedUtc}.cap"
}

Notice: .as('ReferralId').as('ReferralDate') and then the columns "columns" .... "ReferralDate", "ReferralId" ]

Results
[ [ {
"data" : [ [ "romiko.derbynew", "Testa", 331, "/Date(1322007153048+1100)/" ]],
"columns" : [ "CreatedBy", "ReferralGroup", "ReferralDate", "ReferralId" ]
} ] ]