SketchAggregator.updateUnion should handle null inside List update object (#10055)

This commit is contained in:
Maytas Monsereenusorn 2020-06-19 17:29:25 -10:00 committed by GitHub
parent 191572ad5e
commit 9bab6b6371
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -122,7 +122,9 @@ public class SketchAggregator implements Aggregator
union.update((long[]) update);
} else if (update instanceof List) {
for (Object entry : (List) update) {
union.update(entry.toString());
if (entry != null) {
union.update(entry.toString());
}
}
} else {
throw new ISE("Illegal type received while theta sketch merging [%s]", update.getClass());

View File

@ -35,8 +35,10 @@ import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.java.util.common.guava.Sequence;
import org.apache.druid.query.Query;
import org.apache.druid.query.aggregation.AggregationTestHelper;
import org.apache.druid.query.aggregation.Aggregator;
import org.apache.druid.query.aggregation.AggregatorFactory;
import org.apache.druid.query.aggregation.PostAggregator;
import org.apache.druid.query.aggregation.TestObjectColumnSelector;
import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator;
import org.apache.druid.query.groupby.GroupByQuery;
import org.apache.druid.query.groupby.GroupByQueryConfig;
@ -493,6 +495,25 @@ public class SketchAggregationTest
Assert.assertEquals(holders[0].getEstimate(), holders[1].getEstimate(), 0);
}
@Test
public void testUpdateUnionWithNullInList()
{
List<String> value = new ArrayList<>();
value.add("foo");
value.add(null);
value.add("bar");
List[] columnValues = new List[]{value};
final TestObjectColumnSelector selector = new TestObjectColumnSelector(columnValues);
final Aggregator agg = new SketchAggregator(selector, 4096);
agg.aggregate();
Assert.assertFalse(agg.isNull());
Assert.assertNotNull(agg.get());
Assert.assertTrue(agg.get() instanceof SketchHolder);
Assert.assertEquals(2, ((SketchHolder) agg.get()).getEstimate(), 0);
Assert.assertNotNull(((SketchHolder) agg.get()).getSketch());
Assert.assertEquals(2, ((SketchHolder) agg.get()).getSketch().getEstimate(), 0);
}
private void assertPostAggregatorSerde(PostAggregator agg) throws Exception
{
Assert.assertEquals(