Skip to content

Commit 759d98b

Browse files
committed
Sharding: optimized reduce algorithm
1 parent c0df24b commit 759d98b

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

server/src/main/java/com/orientechnologies/orient/server/distributed/ODistributedStorage.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,28 @@ public Object command(final OCommandRequestText iCommand) {
210210
final ODocument doc = new ODocument();
211211
list.add(doc);
212212

213-
// MERGE NON AGGREGATED FIELDS
214-
for (Map.Entry<String, Object> entry : ((Map<String, Object>) result).entrySet()) {
215-
final List<Object> resultSet = (List<Object>) entry.getValue();
213+
boolean hasNonAggregates = false;
214+
for (Map.Entry<String, Object> p : proj.entrySet()) {
215+
if (!(p.getValue() instanceof OSQLFunctionRuntime)) {
216+
hasNonAggregates = true;
217+
break;
218+
}
219+
}
220+
221+
if (hasNonAggregates) {
222+
// MERGE NON AGGREGATED FIELDS
223+
for (Map.Entry<String, Object> entry : ((Map<String, Object>) result).entrySet()) {
224+
final List<Object> resultSet = (List<Object>) entry.getValue();
216225

217-
for (Object r : resultSet) {
218-
if (r instanceof ODocument) {
219-
final ODocument d = (ODocument) r;
226+
for (Object r : resultSet) {
227+
if (r instanceof ODocument) {
228+
final ODocument d = (ODocument) r;
220229

221-
for (Map.Entry<String, Object> p : proj.entrySet()) {
222-
// WRITE THE FIELD AS IS
223-
if (!(p.getValue() instanceof OSQLFunctionRuntime))
224-
doc.field(p.getKey(), p.getValue());
230+
for (Map.Entry<String, Object> p : proj.entrySet()) {
231+
// WRITE THE FIELD AS IS
232+
if (!(p.getValue() instanceof OSQLFunctionRuntime))
233+
doc.field(p.getKey(), p.getValue());
234+
}
225235
}
226236
}
227237
}

0 commit comments

Comments
 (0)