diff --git a/presto-main/src/main/java/com/facebook/presto/operator/BigintGroupByHash.java b/presto-main/src/main/java/com/facebook/presto/operator/BigintGroupByHash.java index ad41da795b729..77cf8c09d6c4a 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/BigintGroupByHash.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/BigintGroupByHash.java @@ -357,7 +357,7 @@ public AddPageWork(Block block) public boolean process() { int positionCount = block.getPositionCount(); - checkState(lastPosition < positionCount, "position count out of bound"); + checkState(lastPosition <= positionCount, "position count out of bound"); // needRehash() == false indicates we have reached capacity boundary and a rehash is needed. // We can only proceed if tryRehash() successfully did a rehash. @@ -402,7 +402,7 @@ public GetGroupIdsWork(Block block) public boolean process() { int positionCount = block.getPositionCount(); - checkState(lastPosition < positionCount, "position count out of bound"); + checkState(lastPosition <= positionCount, "position count out of bound"); checkState(!finished); // needRehash() == false indicates we have reached capacity boundary and a rehash is needed. diff --git a/presto-main/src/main/java/com/facebook/presto/operator/MultiChannelGroupByHash.java b/presto-main/src/main/java/com/facebook/presto/operator/MultiChannelGroupByHash.java index 44d797995e286..a4eaa447e1cb0 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/MultiChannelGroupByHash.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/MultiChannelGroupByHash.java @@ -590,7 +590,7 @@ public AddNonDictionaryPageWork(Page page) public boolean process() { int positionCount = page.getPositionCount(); - checkState(lastPosition < positionCount, "position count out of bound"); + checkState(lastPosition <= positionCount, "position count out of bound"); // needRehash() == false indicates we have reached capacity boundary and a rehash is needed. // We can only proceed if tryRehash() successfully did a rehash. @@ -637,7 +637,7 @@ public AddDictionaryPageWork(Page page) public boolean process() { int positionCount = page.getPositionCount(); - checkState(lastPosition < positionCount, "position count out of bound"); + checkState(lastPosition <= positionCount, "position count out of bound"); // needRehash() == false indicates we have reached capacity boundary and a rehash is needed. // We can only proceed if tryRehash() successfully did a rehash. @@ -780,7 +780,7 @@ public GetDictionaryGroupIdsWork(Page page) public boolean process() { int positionCount = page.getPositionCount(); - checkState(lastPosition < positionCount, "position count out of bound"); + checkState(lastPosition <= positionCount, "position count out of bound"); checkState(!finished); // needRehash() == false indicates we have reached capacity boundary and a rehash is needed. diff --git a/presto-main/src/test/java/com/facebook/presto/operator/TestGroupByHash.java b/presto-main/src/test/java/com/facebook/presto/operator/TestGroupByHash.java index 96f033c0125bd..7e00d7197f722 100644 --- a/presto-main/src/test/java/com/facebook/presto/operator/TestGroupByHash.java +++ b/presto-main/src/test/java/com/facebook/presto/operator/TestGroupByHash.java @@ -285,6 +285,38 @@ else if (type == BIGINT) { assertEquals(rehashCount.get(), log2(length / 0.75, RoundingMode.FLOOR)); } + @Test(dataProvider = "dataType") + public void testEmptyPage(Type type) + { + // Create an empty page + int length = 0; + Block valuesBlock; + if (type == VARCHAR) { + valuesBlock = createStringSequenceBlock(0, length); + } + else if (type == BIGINT) { + valuesBlock = createLongSequenceBlock(0, length); + } + else { + throw new IllegalArgumentException("unsupported data type"); + } + Block hashBlock = getHashBlock(ImmutableList.of(type), valuesBlock); + Page page = new Page(valuesBlock, hashBlock); + AtomicInteger currentQuota = new AtomicInteger(0); + AtomicInteger allowedQuota = new AtomicInteger(3); + UpdateMemory updateMemory = () -> { + if (currentQuota.get() < allowedQuota.get()) { + currentQuota.getAndIncrement(); + return true; + } + return false; + }; + + GroupByHash groupByHash = createGroupByHash(ImmutableList.of(type), new int[] {0}, Optional.of(1), 1, false, JOIN_COMPILER, updateMemory); + Work addPageWork = groupByHash.addPage(page); + assertTrue(addPageWork.process()); + } + @Test(dataProvider = "dataType") public void testMemoryReservationYield(Type type) {