Skip to content

Commit

Permalink
Pre-allocate the results size in Graph ResultSetBuilder (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Aug 11, 2022
1 parent b24aa55 commit 81302a1
Showing 1 changed file with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,43 @@ public ResultSetImpl(List<Object> rawResponse, RedisGraph redisGraph, GraphCache
*/
@SuppressWarnings("unchecked")
private List<Record> parseResult(List<List<Object>> rawResultSet) {
List<Record> results = new ArrayList<>();
if (rawResultSet == null || rawResultSet.isEmpty()) {
return results;
} else {
// go over each raw result
for (List<Object> row : rawResultSet) {

List<Object> parsedRow = new ArrayList<>(row.size());
// go over each object in the result
for (int i = 0; i < row.size(); i++) {
// get raw representation of the object
List<Object> obj = (List<Object>) row.get(i);
// get object type
Header.ResultSetColumnTypes objType = header.getSchemaTypes().get(i);
// deserialize according to type and
switch (objType) {
case COLUMN_NODE:
parsedRow.add(deserializeNode(obj));
break;
case COLUMN_RELATION:
parsedRow.add(deserializeEdge(obj));
break;
case COLUMN_SCALAR:
parsedRow.add(deserializeScalar(obj));
break;
default:
parsedRow.add(null);
break;
}
return new ArrayList<>(0);
}

List<Record> results = new ArrayList<>(rawResultSet.size());
// go over each raw result
for (List<Object> row : rawResultSet) {

List<Object> parsedRow = new ArrayList<>(row.size());
// go over each object in the result
for (int i = 0; i < row.size(); i++) {
// get raw representation of the object
List<Object> obj = (List<Object>) row.get(i);
// get object type
Header.ResultSetColumnTypes objType = header.getSchemaTypes().get(i);
// deserialize according to type and
switch (objType) {
case COLUMN_NODE:
parsedRow.add(deserializeNode(obj));
break;
case COLUMN_RELATION:
parsedRow.add(deserializeEdge(obj));
break;
case COLUMN_SCALAR:
parsedRow.add(deserializeScalar(obj));
break;
default:
parsedRow.add(null);
break;
}
// create new record from deserialized objects
Record record = new RecordImpl(header.getSchemaNames(), parsedRow);
results.add(record);
}

// create new record from deserialized objects
Record record = new RecordImpl(header.getSchemaNames(), parsedRow);
results.add(record);
}

return results;
}

Expand Down

0 comments on commit 81302a1

Please sign in to comment.