1111import redis .clients .jedis .util .SafeEncoder ;
1212import redis .clients .jedis .exceptions .JedisDataException ;
1313
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 .*;
1915
2016public class ResultSetImpl implements ResultSet {
21-
17+
2218
2319 private final Header header ;
2420 private final Statistics statistics ;
25- private final List <Record > results ;
21+ private final List <Record > results ;
2622
2723 private int position = 0 ;
2824 private final RedisGraph redisGraph ;
@@ -31,15 +27,15 @@ public class ResultSetImpl implements ResultSet {
3127 /**
3228 * @param rawResponse the raw representation of response is at most 3 lists of objects.
3329 * 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
3632 */
3733 public ResultSetImpl (List <Object > rawResponse , RedisGraph redisGraph , GraphCache cache ) {
3834 this .redisGraph = redisGraph ;
3935 this .cache = cache ;
4036
4137 // 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 ) {
4339
4440 throw new JRedisGraphRunTimeException ((Throwable ) rawResponse .get (rawResponse .size () - 1 ));
4541 }
@@ -48,8 +44,8 @@ public ResultSetImpl(List<Object> rawResponse, RedisGraph redisGraph, GraphCache
4844
4945 header = parseHeader (new ArrayList <>());
5046 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 ));
5349
5450 } else {
5551
@@ -61,7 +57,6 @@ public ResultSetImpl(List<Object> rawResponse, RedisGraph redisGraph, GraphCache
6157
6258
6359 /**
64- *
6560 * @param rawResultSet - raw result set representation
6661 * @return parsed result set
6762 */
@@ -88,10 +83,10 @@ private List<Record> parseResult(List<List<Object>> rawResultSet) {
8883 case COLUMN_RELATION :
8984 parsedRow .add (deserializeEdge (obj ));
9085 break ;
91- case COLUMN_SCALAR :
86+ case COLUMN_SCALAR :
9287 parsedRow .add (deserializeScalar (obj ));
9388 break ;
94- default :
89+ default :
9590 parsedRow .add (null );
9691 break ;
9792 }
@@ -106,7 +101,6 @@ private List<Record> parseResult(List<List<Object>> rawResultSet) {
106101 }
107102
108103 /**
109- *
110104 * @param rawStatistics raw statistics representation
111105 * @return parsed statistics
112106 */
@@ -116,7 +110,6 @@ private StatisticsImpl parseStatistics(Object rawStatistics) {
116110
117111
118112 /**
119- *
120113 * @param rawHeader - raw header representation
121114 * @return parsed header
122115 */
@@ -180,11 +173,11 @@ private Edge deserializeEdge(List<Object> rawEdgeData) {
180173 deserializeGraphEntityId (edge , rawEdgeData .get (0 ));
181174
182175 String relationshipType = cache .getRelationshipType (((Long ) rawEdgeData .get (1 )).intValue (),
183- redisGraph );
176+ redisGraph );
184177 edge .setRelationshipType (relationshipType );
185178
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 ));
188181
189182 deserializeGraphEntityProperties (edge , (List <List <Object >>) rawEdgeData .get (4 ));
190183
@@ -205,7 +198,7 @@ private void deserializeGraphEntityProperties(GraphEntity entity, List<List<Obje
205198 for (List <Object > rawProperty : rawProperties ) {
206199 Property <Object > property = new Property <>();
207200 property .setName (cache .getPropertyName (((Long ) rawProperty .get (0 )).intValue (),
208- redisGraph ));
201+ redisGraph ));
209202
210203 //trimmed for getting to value using deserializeScalar
211204 List <Object > propertyScalar = rawProperty .subList (1 , rawProperty .size ());
@@ -244,12 +237,25 @@ private Object deserializeScalar(List<Object> rawScalarData) {
244237 return deserializeEdge ((List <Object >) obj );
245238 case VALUE_PATH :
246239 return deserializePath (obj );
240+ case VALUE_MAP :
241+ return deserializeMap (obj );
247242 case VALUE_UNKNOWN :
248243 default :
249244 return obj ;
250245 }
251246 }
252247
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+
253259 private Path deserializePath (Object rawScalarData ) {
254260 List <List <Object >> array = (List <List <Object >>) rawScalarData ;
255261 List <Node > nodes = (List <Node >) deserializeScalar (array .get (0 ));
@@ -322,9 +328,9 @@ public String toString() {
322328 }
323329
324330
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+ }
330336}
0 commit comments