11
11
import redis .clients .jedis .util .SafeEncoder ;
12
12
import redis .clients .jedis .exceptions .JedisDataException ;
13
13
14
- import java .util .ArrayList ;
15
- import java .util .Iterator ;
16
- import java .util .List ;
17
- import java .util .NoSuchElementException ;
18
- import java .util .Objects ;
14
+ import java .util .*;
19
15
20
16
public class ResultSetImpl implements ResultSet {
21
-
17
+
22
18
23
19
private final Header header ;
24
20
private final Statistics statistics ;
25
- private final List <Record > results ;
21
+ private final List <Record > results ;
26
22
27
23
private int position = 0 ;
28
24
private final RedisGraph redisGraph ;
@@ -31,15 +27,15 @@ public class ResultSetImpl implements ResultSet {
31
27
/**
32
28
* @param rawResponse the raw representation of response is at most 3 lists of objects.
33
29
* The last list is the statistics list.
34
- * @param redisGraph the graph connection
35
- * @param cache the graph local cache
30
+ * @param redisGraph the graph connection
31
+ * @param cache the graph local cache
36
32
*/
37
33
public ResultSetImpl (List <Object > rawResponse , RedisGraph redisGraph , GraphCache cache ) {
38
34
this .redisGraph = redisGraph ;
39
35
this .cache = cache ;
40
36
41
37
// If a run-time error occurred, the last member of the rawResponse will be a JedisDataException.
42
- if (rawResponse .get (rawResponse .size ()- 1 ) instanceof JedisDataException ) {
38
+ if (rawResponse .get (rawResponse .size () - 1 ) instanceof JedisDataException ) {
43
39
44
40
throw new JRedisGraphRunTimeException ((Throwable ) rawResponse .get (rawResponse .size () - 1 ));
45
41
}
@@ -48,8 +44,8 @@ public ResultSetImpl(List<Object> rawResponse, RedisGraph redisGraph, GraphCache
48
44
49
45
header = parseHeader (new ArrayList <>());
50
46
results = new ArrayList <>();
51
- statistics = rawResponse .isEmpty () ? parseStatistics (new ArrayList <Objects >()) :
52
- parseStatistics (rawResponse .get (rawResponse .size () - 1 )) ;
47
+ statistics = rawResponse .isEmpty () ? parseStatistics (new ArrayList <Objects >()) :
48
+ parseStatistics (rawResponse .get (rawResponse .size () - 1 ));
53
49
54
50
} else {
55
51
@@ -61,7 +57,6 @@ public ResultSetImpl(List<Object> rawResponse, RedisGraph redisGraph, GraphCache
61
57
62
58
63
59
/**
64
- *
65
60
* @param rawResultSet - raw result set representation
66
61
* @return parsed result set
67
62
*/
@@ -88,10 +83,10 @@ private List<Record> parseResult(List<List<Object>> rawResultSet) {
88
83
case COLUMN_RELATION :
89
84
parsedRow .add (deserializeEdge (obj ));
90
85
break ;
91
- case COLUMN_SCALAR :
86
+ case COLUMN_SCALAR :
92
87
parsedRow .add (deserializeScalar (obj ));
93
88
break ;
94
- default :
89
+ default :
95
90
parsedRow .add (null );
96
91
break ;
97
92
}
@@ -106,7 +101,6 @@ private List<Record> parseResult(List<List<Object>> rawResultSet) {
106
101
}
107
102
108
103
/**
109
- *
110
104
* @param rawStatistics raw statistics representation
111
105
* @return parsed statistics
112
106
*/
@@ -116,7 +110,6 @@ private StatisticsImpl parseStatistics(Object rawStatistics) {
116
110
117
111
118
112
/**
119
- *
120
113
* @param rawHeader - raw header representation
121
114
* @return parsed header
122
115
*/
@@ -180,11 +173,11 @@ private Edge deserializeEdge(List<Object> rawEdgeData) {
180
173
deserializeGraphEntityId (edge , rawEdgeData .get (0 ));
181
174
182
175
String relationshipType = cache .getRelationshipType (((Long ) rawEdgeData .get (1 )).intValue (),
183
- redisGraph );
176
+ redisGraph );
184
177
edge .setRelationshipType (relationshipType );
185
178
186
- edge .setSource ( (long ) rawEdgeData .get (2 ));
187
- edge .setDestination ( (long ) rawEdgeData .get (3 ));
179
+ edge .setSource ((long ) rawEdgeData .get (2 ));
180
+ edge .setDestination ((long ) rawEdgeData .get (3 ));
188
181
189
182
deserializeGraphEntityProperties (edge , (List <List <Object >>) rawEdgeData .get (4 ));
190
183
@@ -205,7 +198,7 @@ private void deserializeGraphEntityProperties(GraphEntity entity, List<List<Obje
205
198
for (List <Object > rawProperty : rawProperties ) {
206
199
Property <Object > property = new Property <>();
207
200
property .setName (cache .getPropertyName (((Long ) rawProperty .get (0 )).intValue (),
208
- redisGraph ));
201
+ redisGraph ));
209
202
210
203
//trimmed for getting to value using deserializeScalar
211
204
List <Object > propertyScalar = rawProperty .subList (1 , rawProperty .size ());
@@ -244,12 +237,25 @@ private Object deserializeScalar(List<Object> rawScalarData) {
244
237
return deserializeEdge ((List <Object >) obj );
245
238
case VALUE_PATH :
246
239
return deserializePath (obj );
240
+ case VALUE_MAP :
241
+ return deserializeMap (obj );
247
242
case VALUE_UNKNOWN :
248
243
default :
249
244
return obj ;
250
245
}
251
246
}
252
247
248
+ private Map <String , Object > deserializeMap (Object rawScalarData ) {
249
+ List <Object > keyTypeValueEntries = (List <Object >) rawScalarData ;
250
+ Map <String , Object > map = new HashMap <>();
251
+ for (int i = 0 ; i < keyTypeValueEntries .size (); i += 2 ) {
252
+ String key = SafeEncoder .encode ((byte []) keyTypeValueEntries .get (i ));
253
+ Object value = deserializeScalar ((List <Object >) keyTypeValueEntries .get (i + 1 ));
254
+ map .put (key , value );
255
+ }
256
+ return map ;
257
+ }
258
+
253
259
private Path deserializePath (Object rawScalarData ) {
254
260
List <List <Object >> array = (List <List <Object >>) rawScalarData ;
255
261
List <Node > nodes = (List <Node >) deserializeScalar (array .get (0 ));
@@ -322,9 +328,9 @@ public String toString() {
322
328
}
323
329
324
330
325
- @ Override
326
- public Iterator <Record > iterator () {
327
- // TODO Auto-generated method stub
328
- return results .iterator ();
329
- }
331
+ @ Override
332
+ public Iterator <Record > iterator () {
333
+ // TODO Auto-generated method stub
334
+ return results .iterator ();
335
+ }
330
336
}
0 commit comments