From f3595c93d92f39298956a27691e93cf3459fb5fb Mon Sep 17 00:00:00 2001 From: Roman Leventov Date: Mon, 30 Jul 2018 16:39:38 -0500 Subject: [PATCH] Fix a bug in GroupByQueryEngine (#6062) --- .../query/groupby/GroupByQueryEngine.java | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/processing/src/main/java/io/druid/query/groupby/GroupByQueryEngine.java b/processing/src/main/java/io/druid/query/groupby/GroupByQueryEngine.java index d3543cd8627..1d77d08e2cd 100644 --- a/processing/src/main/java/io/druid/query/groupby/GroupByQueryEngine.java +++ b/processing/src/main/java/io/druid/query/groupby/GroupByQueryEngine.java @@ -178,37 +178,33 @@ public class GroupByQueryEngine return positions; } - private List updateValues( - ByteBuffer key, - List dims - ) + @Nullable + private List updateValues(ByteBuffer key, List dims) { if (dims.size() > 0) { - List retVal = null; - List unaggregatedBuffers = null; - final DimensionSelector dimSelector = dims.get(0); final IndexedInts row = dimSelector.getRow(); final int rowSize = row.size(); if (rowSize == 0) { ByteBuffer newKey = key.duplicate(); newKey.putInt(MISSING_VALUE); - unaggregatedBuffers = updateValues(newKey, dims.subList(1, dims.size())); + return updateValues(newKey, dims.subList(1, dims.size())); } else { + List retVal = null; for (int i = 0; i < rowSize; i++) { ByteBuffer newKey = key.duplicate(); int dimValue = row.get(i); newKey.putInt(dimValue); - unaggregatedBuffers = updateValues(newKey, dims.subList(1, dims.size())); + List unaggregatedBuffers = updateValues(newKey, dims.subList(1, dims.size())); + if (unaggregatedBuffers != null) { + if (retVal == null) { + retVal = Lists.newArrayList(); + } + retVal.addAll(unaggregatedBuffers); + } } + return retVal; } - if (unaggregatedBuffers != null) { - if (retVal == null) { - retVal = Lists.newArrayList(); - } - retVal.addAll(unaggregatedBuffers); - } - return retVal; } else { key.clear(); Integer position = positionsHash.get(key); @@ -222,7 +218,7 @@ public class GroupByQueryEngine position = positionMaintainer.getNext(); if (position == null) { - return Lists.newArrayList(keyCopy); + return Collections.singletonList(keyCopy); } positions.put(keyCopy, position);