23
23
import com .alibaba .graphscope .gremlin .transform .alias .AliasManager ;
24
24
25
25
import org .apache .tinkerpop .gremlin .process .traversal .Step ;
26
+ import org .apache .tinkerpop .gremlin .process .traversal .step .map .PropertyMapStep ;
27
+ import org .apache .tinkerpop .gremlin .structure .T ;
26
28
27
29
import java .util .*;
28
- import java .util .stream .*;
29
30
30
31
// values("name") -> key: head, value: "marko"
31
32
// valueMap("name") -> key: head, value: {name, "marko"}
@@ -47,7 +48,7 @@ public static ProjectResultParser create(Step step) {
47
48
@ Override
48
49
public Object parseFrom (IrResult .Results results ) {
49
50
IrResult .Record record = results .getRecord ();
50
- Map <String , Object > projectResult = new LinkedHashMap <>();
51
+ Map <Object , Object > projectResult = new LinkedHashMap <>();
51
52
record .getColumnsList ()
52
53
.forEach (
53
54
column -> {
@@ -59,7 +60,7 @@ public Object parseFrom(IrResult.Results results) {
59
60
Map tagEntry =
60
61
(Map )
61
62
projectResult .computeIfAbsent (
62
- tag , k1 -> new HashMap <>());
63
+ tag , k1 -> new LinkedHashMap <>());
63
64
tagEntry .putAll (flatMap (projectTags ));
64
65
} else {
65
66
if (!(parseEntry instanceof EmptyValue )) {
@@ -78,8 +79,8 @@ public Object parseFrom(IrResult.Results results) {
78
79
}
79
80
80
81
// {~label: "person", ~all: {name: "marko"}} -> {~label: "person", name: "marko"}
81
- private Map <String , Object > flatMap (Map <String , Object > map ) {
82
- Map <String , Object > result = new HashMap <>();
82
+ private Map <Object , Object > flatMap (Map <String , Object > map ) {
83
+ Map <Object , Object > result = new LinkedHashMap <>();
83
84
for (Map .Entry <String , Object > entry : map .entrySet ()) {
84
85
Object k = entry .getKey ();
85
86
Object v = entry .getValue ();
@@ -90,23 +91,26 @@ private Map<String, Object> flatMap(Map<String, Object> map) {
90
91
String nameOrId = null ;
91
92
if (k instanceof List ) { // valueMap("name") -> Map<["", "name"], value>
92
93
nameOrId = (String ) ((List ) k ).get (1 );
93
- } else if (k
94
- instanceof
95
- String ) { // valueMap() -> Map<"name",
94
+ } else if (k instanceof String ) { // valueMap() -> Map<"name",
96
95
// value>
97
96
nameOrId = (String ) k ;
98
- } else if (k
99
- instanceof
100
- Number ) { // valueMap() -> Map<1, value>
97
+ } else if (k instanceof Number ) { // valueMap() -> Map<1, value>
101
98
nameOrId = String .valueOf (k );
102
99
}
103
100
if (nameOrId == null || nameOrId .isEmpty ()) {
104
101
throw new GremlinResultParserException (
105
- "map value should have property"
106
- + " key" );
102
+ "map value should have property" + " key" );
107
103
}
108
104
String property = getPropertyName (nameOrId );
109
- result .put (property , Collections .singletonList (v ));
105
+ if (step instanceof PropertyMapStep ) {
106
+ result .put (property , Collections .singletonList (v ));
107
+ } else if (property .equals (T .id .getAccessor ())) {
108
+ result .put (T .id , v );
109
+ } else if (property .equals (T .label .getAccessor ())) {
110
+ result .put (T .label , v );
111
+ } else {
112
+ result .put (property , v );
113
+ }
110
114
}
111
115
}
112
116
}
0 commit comments