Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,9 @@ Object[] getAggregateResult() throws HopValueException {
Double[] latencies = new Double[latenciesList.size()];
latencies = latenciesList.toArray(latencies);
int index = (int) Math.ceil((percentileValue / 100) * latencies.length);
ag = latencies[index - 1];
// No values in the group (all null, or no rows at all): no percentile. The 0th
// percentile is the smallest value.
ag = latencies.length == 0 ? null : latencies[Math.max(index, 1) - 1];
break;
case Aggregation.TYPE_GROUP_COUNT_ANY, Aggregation.TYPE_GROUP_COUNT_ALL:
ag = data.counts[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -269,6 +270,49 @@ void calcAggregateUpdatesSumAndCount() throws Exception {
assertEquals(2L, ((Number) result[1]).longValue());
}

@Test
void percentileNearestRankOfAGroupWithoutValuesIsNull() throws Exception {
data.inputRowMeta = inputRowMeta;
data.subjectnrs = new int[] {1, 1};
data.counts = new long[2];
data.mean = new double[2];
data.previousSums = new Object[0];
data.previousAvgSum = new Object[0];
data.previousAvgCount = new long[0];
data.movingAvgWindows = new ArrayDeque[2];

meta.getAggregations().clear();
meta.getAggregations()
.add(
new Aggregation(
"p75",
"amount",
Aggregation.getTypeDescLongFromCode(Aggregation.TYPE_GROUP_PERCENTILE_NEAREST_RANK),
"75"));
meta.getAggregations()
.add(
new Aggregation(
"p0",
"amount",
Aggregation.getTypeDescLongFromCode(Aggregation.TYPE_GROUP_PERCENTILE_NEAREST_RANK),
"0"));

// Only null amounts: no values to rank
groupBy.newAggregate(new Object[] {"A", null});
groupBy.calcAggregate(new Object[] {"A", null});
Object[] result = groupBy.getAggregateResult();
assertNull(result[0]);
assertNull(result[1]);

// A 0th percentile is the smallest value, not an index before the first one
groupBy.newAggregate(new Object[] {"A", 4.0});
groupBy.calcAggregate(new Object[] {"A", 4.0});
groupBy.calcAggregate(new Object[] {"A", 2.0});
result = groupBy.getAggregateResult();
assertEquals(4.0, (Double) result[0], 1e-9);
assertEquals(2.0, (Double) result[1], 1e-9);
}

@Test
void batchCompleteFlushesCurrentGroup() throws Exception {
QueueRowSet input = new QueueRowSet();
Expand Down
Loading