diff --git a/processing/src/main/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregator.java b/processing/src/main/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregator.java index 045360ba616..f10584a2c74 100644 --- a/processing/src/main/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregator.java +++ b/processing/src/main/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregator.java @@ -42,7 +42,7 @@ public class StringLastVectorAggregator implements VectorAggregator protected long lastTime; public StringLastVectorAggregator( - final BaseLongVectorValueSelector timeSelector, + @Nullable final BaseLongVectorValueSelector timeSelector, final VectorObjectSelector valueSelector, final int maxStringBytes ) @@ -124,6 +124,9 @@ public class StringLastVectorAggregator implements VectorAggregator int positionOffset ) { + if (timeSelector == null) { + return; + } long[] timeVector = timeSelector.getLongVector(); Object[] objectsWhichMightBeStrings = valueSelector.getObjectVector(); diff --git a/processing/src/test/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregatorTest.java b/processing/src/test/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregatorTest.java index 428ff3e3742..6e5c0275107 100644 --- a/processing/src/test/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregatorTest.java +++ b/processing/src/test/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregatorTest.java @@ -129,6 +129,25 @@ public class StringLastVectorAggregatorTest extends InitializedNullHandlingTest Assert.assertEquals(VALUES[3], result.rhs); } + @Test + public void aggregateNoOp() + { + // Test that aggregates run just fine when the input field does not exist + StringLastVectorAggregator aggregator = new StringLastVectorAggregator(null, selector, 10); + aggregator.aggregate(buf, 0, 0, VALUES.length); + } + + @Test + public void aggregateBatchNoOp() + { + // Test that aggregates run just fine when the input field does not exist + StringLastVectorAggregator aggregator = new StringLastVectorAggregator(null, selector, 10); + int[] positions = new int[]{0, 43, 70}; + int positionOffset = 2; + clearBufferForPositions(positionOffset, positions); + aggregator.aggregate(buf, 3, positions, null, positionOffset); + } + @Test public void aggregateBatchWithoutRows() {