Skip to content
Merged
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 @@ -240,8 +240,12 @@ public Comparator<DoublesSketch> getComparator()
public Object combine(final Object lhs, final Object rhs)
{
final DoublesUnion union = DoublesUnion.builder().setMaxK(k).build();
union.union((DoublesSketch) lhs);
union.union((DoublesSketch) rhs);
if (lhs != null) {
union.union((DoublesSketch) lhs);
}
if (rhs != null) {
union.union((DoublesSketch) rhs);
}
return union.getResultAndReset();
}

Expand All @@ -263,7 +267,9 @@ public void reset(final ColumnValueSelector selector)
public void fold(final ColumnValueSelector selector)
{
final DoublesSketch sketch = (DoublesSketch) selector.getObject();
union.union(sketch);
if (sketch != null) {
union.union(sketch);
}
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
import org.apache.druid.jackson.DefaultObjectMapper;
import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.query.Druids;
import org.apache.druid.query.aggregation.AggregateCombiner;
import org.apache.druid.query.aggregation.Aggregator;
import org.apache.druid.query.aggregation.AggregatorFactory;
import org.apache.druid.query.aggregation.CountAggregatorFactory;
import org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl;
import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator;
import org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator;
import org.apache.druid.query.timeseries.TimeseriesQuery;
Expand Down Expand Up @@ -172,4 +175,24 @@ public void testWithName()
Assert.assertEquals(factory, factory.withName("myFactory"));
Assert.assertEquals("newTest", factory.withName("newTest").getName());
}

@Test
public void testNullSketches()
{
final DoublesSketchAggregatorFactory factory = new DoublesSketchAggregatorFactory(
"myFactory",
"myField",
1024,
1000L,
null
);
final double[] values = new double[]{1, 2, 3, 4, 5, 6};
final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(values);
final Aggregator agg1 = new DoublesSketchBuildAggregator(selector, 8);
Assert.assertNotNull(factory.combine(null, agg1.get()));
Assert.assertNotNull(factory.combine(agg1.get(), null));
AggregateCombiner ac = factory.makeAggregateCombiner();
ac.fold(new TestDoublesSketchColumnValueSelector());
Assert.assertNotNull(ac.getObject());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.query.aggregation.datasketches.quantiles;

import org.apache.datasketches.quantiles.DoublesSketch;
import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import org.apache.druid.segment.ColumnValueSelector;

import javax.annotation.Nullable;

public class TestDoublesSketchColumnValueSelector implements ColumnValueSelector<DoublesSketch>
{
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
}

@Override
public double getDouble()
{
return 99;
}

@Override
public float getFloat()
{
return 99;
}

@Override
public long getLong()
{
return 99;
}

@Override
public boolean isNull()
{
return false;
}

@Nullable
@Override
public DoublesSketch getObject()
{
return DoublesSketchOperations.EMPTY_SKETCH;
}

@Override
public Class<? extends DoublesSketch> classOfObject()
{
return DoublesSketchOperations.EMPTY_SKETCH.getClass();
}
}