mirror of https://github.com/apache/druid.git
Adding withName implementation to AggregatorFactory (#12862)
* Adding agg factory with name impl * Adding test cases * Fixing test case * Fixing test case * Updated java docs.
This commit is contained in:
parent
2045a1345c
commit
607b0b9310
|
@ -89,6 +89,12 @@ public class DistinctCountAggregatorFactory extends AggregatorFactory
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new DistinctCountAggregatorFactory(newName, getFieldName(), getBitMapFactory());
|
||||
}
|
||||
|
||||
private DimensionSelector makeDimensionSelector(final ColumnSelectorFactory columnFactory)
|
||||
{
|
||||
return columnFactory.makeDimensionSelector(new DefaultDimensionSpec(fieldName, fieldName));
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.apache.druid.segment.incremental.IncrementalIndexSchema;
|
|||
import org.apache.druid.segment.incremental.OnheapIncrementalIndex;
|
||||
import org.apache.druid.testing.InitializedNullHandlingTest;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -157,4 +158,16 @@ public class DistinctCountGroupByQueryTest extends InitializedNullHandlingTest
|
|||
);
|
||||
TestHelper.assertExpectedObjects(expectedResults, results, "distinct-count");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
DistinctCountAggregatorFactory aggregatorFactory = new DistinctCountAggregatorFactory(
|
||||
"distinct",
|
||||
"visitor_id",
|
||||
null
|
||||
);
|
||||
Assert.assertEquals(aggregatorFactory, aggregatorFactory.withName("distinct"));
|
||||
Assert.assertEquals("newTest", aggregatorFactory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -264,6 +264,12 @@ public class MomentSketchAggregatorFactory extends AggregatorFactory
|
|||
return (k + 2) * Double.BYTES + 2 * Integer.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new MomentSketchAggregatorFactory(newName, getFieldName(), getK(), getCompress(), cacheTypeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.apache.druid.query.aggregation.momentsketch.aggregator;
|
|||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.apache.druid.query.aggregation.Aggregator;
|
||||
import org.apache.druid.query.aggregation.AggregatorFactory;
|
||||
import org.apache.druid.query.aggregation.AggregatorUtil;
|
||||
import org.apache.druid.query.aggregation.BufferAggregator;
|
||||
import org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper;
|
||||
|
@ -59,4 +60,9 @@ public class MomentSketchMergeAggregatorFactory extends MomentSketchAggregatorFa
|
|||
return new MomentSketchMergeBufferAggregator(selector, getK(), getCompress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new MomentSketchMergeAggregatorFactory(newName, getK(), getCompress());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,4 +86,21 @@ public class MomentSketchAggregatorFactoryTest
|
|||
new TimeseriesQueryQueryToolChest().resultArraySignature(query)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
MomentSketchAggregatorFactory sketchAggFactory = new MomentSketchAggregatorFactory(
|
||||
"name", "fieldName", 128, true
|
||||
);
|
||||
Assert.assertEquals(sketchAggFactory, sketchAggFactory.withName("name"));
|
||||
Assert.assertEquals("newTest", sketchAggFactory.withName("newTest").getName());
|
||||
|
||||
|
||||
MomentSketchMergeAggregatorFactory sketchMergeAggregatorFactory = new MomentSketchMergeAggregatorFactory(
|
||||
"name", 128, true
|
||||
);
|
||||
Assert.assertEquals(sketchMergeAggregatorFactory, sketchMergeAggregatorFactory.withName("name"));
|
||||
Assert.assertEquals("newTest", sketchMergeAggregatorFactory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.druid.segment.column.ColumnType;
|
|||
import javax.annotation.Nullable;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A wrapper around averagers that makes them appear to be aggregators.
|
||||
|
@ -181,4 +182,29 @@ public class AveragerFactoryWrapper<T, R> extends AggregatorFactory
|
|||
{
|
||||
throw new UnsupportedOperationException("Invalid operation for AveragerFactoryWrapper.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new AveragerFactoryWrapper(af, newName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
AveragerFactoryWrapper<?, ?> that = (AveragerFactoryWrapper<?, ?>) o;
|
||||
return af.equals(that.af) && prefix.equals(that.prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(af, prefix);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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.movingaverage.averagers;
|
||||
|
||||
import org.apache.druid.query.movingaverage.AveragerFactoryWrapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AveragerFactoryWrapperTest
|
||||
{
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
AveragerFactoryWrapper factoryWrapper = new AveragerFactoryWrapper(
|
||||
new DoubleMaxAveragerFactory("double", 1, 1, "test"),
|
||||
"test"
|
||||
);
|
||||
Assert.assertEquals(factoryWrapper, factoryWrapper.withName("test"));
|
||||
Assert.assertEquals("newTestdouble", factoryWrapper.withName("newTest").getName());
|
||||
}
|
||||
}
|
|
@ -233,6 +233,12 @@ public class TDigestSketchAggregatorFactory extends AggregatorFactory
|
|||
return TDigestSketchUtils.getMaxIntermdiateTDigestSize(compression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new TDigestSketchAggregatorFactory(newName, getFieldName(), getCompression(), cacheTypeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregateCombiner makeAggregateCombiner()
|
||||
{
|
||||
|
|
|
@ -62,4 +62,12 @@ public class TDigestSketchAggregatorFactoryTest
|
|||
new TimeseriesQueryQueryToolChest().resultArraySignature(query)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
TDigestSketchAggregatorFactory factory = new TDigestSketchAggregatorFactory("tdigest", "col", null);
|
||||
Assert.assertEquals(factory, factory.withName("tdigest"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,12 @@ public class TimestampMaxAggregatorFactory extends TimestampAggregatorFactory
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new TimestampMaxAggregatorFactory(newName, getFieldName(), getTimeFormat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -54,6 +54,12 @@ public class TimestampMinAggregatorFactory extends TimestampAggregatorFactory
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new TimestampMinAggregatorFactory(newName, getFieldName(), getTimeFormat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -119,4 +119,16 @@ public class TimestampMinMaxAggregatorFactoryTest
|
|||
new TimeseriesQueryQueryToolChest().resultArraySignature(query)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
TimestampMaxAggregatorFactory maxAgg = new TimestampMaxAggregatorFactory("timeMax", "__time", null);
|
||||
Assert.assertEquals(maxAgg, maxAgg.withName("timeMax"));
|
||||
Assert.assertEquals("newTest", maxAgg.withName("newTest").getName());
|
||||
|
||||
TimestampMinAggregatorFactory minAgg = new TimestampMinAggregatorFactory("timeMin", "__time", null);
|
||||
Assert.assertEquals(minAgg, minAgg.withName("timeMin"));
|
||||
Assert.assertEquals("newTest", minAgg.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.datasketches.hll.HllSketch;
|
|||
import org.apache.datasketches.hll.TgtHllType;
|
||||
import org.apache.druid.java.util.common.ISE;
|
||||
import org.apache.druid.query.aggregation.Aggregator;
|
||||
import org.apache.druid.query.aggregation.AggregatorFactory;
|
||||
import org.apache.druid.query.aggregation.AggregatorUtil;
|
||||
import org.apache.druid.query.aggregation.BufferAggregator;
|
||||
import org.apache.druid.query.aggregation.VectorAggregator;
|
||||
|
@ -121,6 +122,12 @@ public class HllSketchBuildAggregatorFactory extends HllSketchAggregatorFactory
|
|||
return HllSketch.getMaxUpdatableSerializationBytes(getLgK(), TgtHllType.valueOf(getTgtHllType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new HllSketchBuildAggregatorFactory(newName, getFieldName(), getLgK(), getTgtHllType(), isRound());
|
||||
}
|
||||
|
||||
private void validateInputs(@Nullable ColumnCapabilities capabilities)
|
||||
{
|
||||
if (capabilities != null) {
|
||||
|
|
|
@ -131,4 +131,10 @@ public class HllSketchMergeAggregatorFactory extends HllSketchAggregatorFactory
|
|||
return Union.getMaxSerializationBytes(getLgK());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new HllSketchMergeAggregatorFactory(newName, getFieldName(), getLgK(), getTgtHllType(), isRound());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -304,6 +304,12 @@ public class DoublesSketchAggregatorFactory extends AggregatorFactory
|
|||
return DoublesSketch.getUpdatableStorageBytes(k, rows);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new DoublesSketchAggregatorFactory(newName, getFieldName(), getK(), getMaxStreamLength(), cacheTypeId);
|
||||
}
|
||||
|
||||
// Quantiles sketches never stop growing, but they do so very slowly.
|
||||
// This size must suffice for overwhelming majority of sketches,
|
||||
// but some sketches may request more memory on heap and move there
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.apache.datasketches.quantiles.DoublesSketch;
|
||||
import org.apache.druid.query.aggregation.Aggregator;
|
||||
import org.apache.druid.query.aggregation.AggregatorFactory;
|
||||
import org.apache.druid.query.aggregation.AggregatorUtil;
|
||||
import org.apache.druid.query.aggregation.BufferAggregator;
|
||||
import org.apache.druid.segment.ColumnSelectorFactory;
|
||||
|
@ -74,4 +75,9 @@ public class DoublesSketchMergeAggregatorFactory extends DoublesSketchAggregator
|
|||
return new DoublesSketchMergeBufferAggregator(selector, getK(), getMaxIntermediateSizeWithNulls());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new DoublesSketchMergeAggregatorFactory(newName, getK(), getMaxStreamLength());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,6 +164,19 @@ public class SketchMergeAggregatorFactory extends SketchAggregatorFactory
|
|||
return getIntermediateType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new SketchMergeAggregatorFactory(
|
||||
newName,
|
||||
getFieldName(),
|
||||
getSize(),
|
||||
getShouldFinalize(),
|
||||
getIsInputThetaSketch(),
|
||||
getErrorBoundsStdDev()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.druid.query.aggregation.datasketches.theta.oldapi;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.apache.druid.query.aggregation.AggregatorFactory;
|
||||
import org.apache.druid.query.aggregation.datasketches.theta.SketchMergeAggregatorFactory;
|
||||
|
||||
/**
|
||||
|
@ -36,4 +37,10 @@ public class OldSketchBuildAggregatorFactory extends SketchMergeAggregatorFactor
|
|||
{
|
||||
super(name, fieldName, size, true, false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new OldSketchBuildAggregatorFactory(newName, getFieldName(), getSize());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.druid.query.aggregation.datasketches.theta.oldapi;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.apache.druid.query.aggregation.AggregatorFactory;
|
||||
import org.apache.druid.query.aggregation.datasketches.theta.SketchMergeAggregatorFactory;
|
||||
|
||||
/**
|
||||
|
@ -37,4 +38,11 @@ public class OldSketchMergeAggregatorFactory extends SketchMergeAggregatorFactor
|
|||
{
|
||||
super(name, fieldName, size, shouldFinalize, true, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new OldSketchMergeAggregatorFactory(newName, getFieldName(), getSize(), getShouldFinalize());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -266,6 +266,18 @@ public class ArrayOfDoublesSketchAggregatorFactory extends AggregatorFactory
|
|||
return ArrayOfDoublesUnion.getMaxBytes(nominalEntries, numberOfValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new ArrayOfDoublesSketchAggregatorFactory(
|
||||
newName,
|
||||
getFieldName(),
|
||||
getNominalEntries(),
|
||||
getMetricColumns(),
|
||||
getNumberOfValues()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AggregatorFactory> getRequiredColumns()
|
||||
{
|
||||
|
|
|
@ -83,6 +83,17 @@ public class HllSketchAggregatorFactoryTest
|
|||
Assert.assertEquals(ROUND, aggregatorFactory.isRound());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
List<AggregatorFactory> aggregatorFactories = target.getRequiredColumns();
|
||||
Assert.assertEquals(1, aggregatorFactories.size());
|
||||
HllSketchAggregatorFactory aggregatorFactory = (HllSketchAggregatorFactory) aggregatorFactories.get(0);
|
||||
Assert.assertEquals(aggregatorFactory, aggregatorFactory.withName(aggregatorFactory.getName()));
|
||||
Assert.assertEquals("newTest", aggregatorFactory.withName("newTest").getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFinalizeComputationNull()
|
||||
{
|
||||
|
@ -362,5 +373,11 @@ public class HllSketchAggregatorFactoryTest
|
|||
{
|
||||
return DUMMY_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new TestHllSketchAggregatorFactory(newName, getFieldName(), getLgK(), getTgtHllType(), isRound());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,4 +156,12 @@ public class HllSketchMergeAggregatorFactoryTest
|
|||
HllSketchAggregatorFactory result = (HllSketchAggregatorFactory) targetRound.getMergingFactory(targetRound);
|
||||
Assert.assertTrue(result.isRound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName() throws Exception
|
||||
{
|
||||
HllSketchAggregatorFactory factory = (HllSketchAggregatorFactory) targetRound.getMergingFactory(targetRound);
|
||||
Assert.assertEquals(factory, factory.withName(targetRound.getName()));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,4 +153,17 @@ public class DoublesSketchAggregatorFactoryTest
|
|||
new TimeseriesQueryQueryToolChest().resultArraySignature(query)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
final DoublesSketchAggregatorFactory factory = new DoublesSketchAggregatorFactory(
|
||||
"myFactory",
|
||||
"myField",
|
||||
1024,
|
||||
1000L
|
||||
);
|
||||
Assert.assertEquals(factory, factory.withName("myFactory"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,4 +60,16 @@ public class DoublesSketchMergeAggregatorFactoryTest
|
|||
);
|
||||
Assert.assertEquals(factory, fromJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
final DoublesSketchMergeAggregatorFactory factory = new DoublesSketchMergeAggregatorFactory(
|
||||
"myFactory",
|
||||
1024,
|
||||
1000L
|
||||
);
|
||||
Assert.assertEquals(factory, factory.withName("myFactory"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,4 +160,11 @@ public class SketchAggregatorFactoryTest
|
|||
new TimeseriesQueryQueryToolChest().resultArraySignature(query)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
Assert.assertEquals(AGGREGATOR_16384, AGGREGATOR_16384.withName("x"));
|
||||
Assert.assertEquals("newTest", AGGREGATOR_16384.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,6 +242,23 @@ public class OldApiSketchAggregationTest extends InitializedNullHandlingTest
|
|||
Assert.assertEquals(holders[0].getEstimate(), holders[1].getEstimate(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithNameMerge()
|
||||
{
|
||||
OldSketchMergeAggregatorFactory factory = new OldSketchMergeAggregatorFactory("name", "fieldName", 16, null);
|
||||
Assert.assertEquals(factory, factory.withName("name"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithNameBuild()
|
||||
{
|
||||
OldSketchBuildAggregatorFactory factory = new OldSketchBuildAggregatorFactory("name", "fieldName", 16);
|
||||
Assert.assertEquals(factory, factory.withName("name"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
|
||||
private void assertPostAggregatorSerde(PostAggregator agg) throws Exception
|
||||
{
|
||||
Assert.assertEquals(
|
||||
|
|
|
@ -110,4 +110,12 @@ public class ArrayOfDoublesSketchAggregatorFactoryTest
|
|||
new TimeseriesQueryQueryToolChest().resultArraySignature(query)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
AggregatorFactory factory = new ArrayOfDoublesSketchAggregatorFactory("name", "", null, null, null);
|
||||
Assert.assertEquals(factory, factory.withName("name"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,6 +207,12 @@ public class BloomFilterAggregatorFactory extends AggregatorFactory
|
|||
return BloomKFilter.computeSizeBytes(maxNumEntries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new BloomFilterAggregatorFactory(newName, getField(), getMaxNumEntries());
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -71,6 +71,12 @@ public class BloomFilterMergeAggregatorFactory extends BloomFilterAggregatorFact
|
|||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new BloomFilterMergeAggregatorFactory(newName, fieldName, getMaxNumEntries());
|
||||
}
|
||||
|
||||
private BloomFilterMergeAggregator makeMergeAggregator(ColumnSelectorFactory metricFactory)
|
||||
{
|
||||
final BaseNullableColumnValueSelector selector = metricFactory.makeColumnValueSelector(fieldName);
|
||||
|
|
|
@ -69,4 +69,25 @@ public class BloomFilterAggregatorFactoryTest
|
|||
new TimeseriesQueryQueryToolChest().resultArraySignature(query)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithNameBloomFilterAggFactory()
|
||||
{
|
||||
BloomFilterAggregatorFactory factory = new BloomFilterAggregatorFactory(
|
||||
"bloom",
|
||||
DefaultDimensionSpec.of("col"),
|
||||
1024
|
||||
);
|
||||
Assert.assertEquals(factory, factory.withName("bloom"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithNameBloomFilterMergeAggFactory()
|
||||
{
|
||||
BloomFilterMergeAggregatorFactory factory = new BloomFilterMergeAggregatorFactory("bloomMerge", "bloom", 1024);
|
||||
Assert.assertEquals(factory, factory.withName("bloomMerge"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -347,6 +347,20 @@ public class ApproximateHistogramAggregatorFactory extends AggregatorFactory
|
|||
return new ApproximateHistogram(resolution).getMaxStorageSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new ApproximateHistogramAggregatorFactory(
|
||||
newName,
|
||||
getFieldName(),
|
||||
getResolution(),
|
||||
getNumBuckets(),
|
||||
getLowerLimit(),
|
||||
getUpperLimit(),
|
||||
finalizeAsBase64Binary
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -142,6 +142,20 @@ public class ApproximateHistogramFoldingAggregatorFactory extends ApproximateHis
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new ApproximateHistogramFoldingAggregatorFactory(
|
||||
newName,
|
||||
getFieldName(),
|
||||
getResolution(),
|
||||
getNumBuckets(),
|
||||
getLowerLimit(),
|
||||
getUpperLimit(),
|
||||
finalizeAsBase64Binary
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -302,6 +302,20 @@ public class FixedBucketsHistogramAggregatorFactory extends AggregatorFactory
|
|||
return FixedBucketsHistogram.SERDE_HEADER_SIZE + FixedBucketsHistogram.getFullStorageSize(numBuckets);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new FixedBucketsHistogramAggregatorFactory(
|
||||
newName,
|
||||
getFieldName(),
|
||||
getNumBuckets(),
|
||||
getLowerLimit(),
|
||||
getUpperLimit(),
|
||||
getOutlierHandlingMode(),
|
||||
isFinalizeAsBase64Binary()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -155,4 +155,20 @@ public class ApproximateHistogramAggregatorTest extends InitializedNullHandlingT
|
|||
new TimeseriesQueryQueryToolChest().resultArraySignature(query)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
ApproximateHistogramAggregatorFactory factory = new ApproximateHistogramAggregatorFactory(
|
||||
"approxHisto",
|
||||
"col",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false
|
||||
);
|
||||
Assert.assertEquals(factory, factory.withName("approxHisto"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,14 @@ public class ApproximateHistogramFoldingVectorAggregatorTest
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
ApproximateHistogramFoldingAggregatorFactory factory = buildHistogramFactory();
|
||||
Assert.assertEquals(factory, factory.withName("approximateHistoFold"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
|
||||
private ApproximateHistogramFoldingAggregatorFactory buildHistogramFactory()
|
||||
{
|
||||
return buildHistogramFactory("field");
|
||||
|
|
|
@ -176,4 +176,20 @@ public class FixedBucketsHistogramBufferAggregatorTest
|
|||
new TimeseriesQueryQueryToolChest().resultArraySignature(query)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
FixedBucketsHistogramAggregatorFactory factory = new FixedBucketsHistogramAggregatorFactory(
|
||||
"billy",
|
||||
"billy",
|
||||
5,
|
||||
0,
|
||||
50,
|
||||
FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW,
|
||||
false
|
||||
);
|
||||
Assert.assertEquals(factory, factory.withName("billy"));
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,6 +117,12 @@ public class VarianceAggregatorFactory extends AggregatorFactory
|
|||
return VarianceAggregatorCollector.getMaxIntermediateSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new VarianceAggregatorFactory(newName, getFieldName(), getEstimator(), inputType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Aggregator factorize(ColumnSelectorFactory metricFactory)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.druid.query.aggregation.variance;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.apache.druid.query.aggregation.AggregatorFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -37,4 +38,10 @@ public class VarianceFoldingAggregatorFactory extends VarianceAggregatorFactory
|
|||
{
|
||||
super(name, fieldName, estimator, "variance");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new VarianceFoldingAggregatorFactory(newName, getFieldName(), getEstimator());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,4 +85,20 @@ public class VarianceAggregatorFactoryTest extends InitializedNullHandlingTest
|
|||
VarianceAggregatorFactory target = new VarianceAggregatorFactory("test", "test", null, null);
|
||||
Assert.assertEquals(NullHandling.defaultDoubleValue(), target.finalizeComputation(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
VarianceAggregatorFactory varianceAggregatorFactory = new VarianceAggregatorFactory("variance", "col");
|
||||
Assert.assertEquals(varianceAggregatorFactory, varianceAggregatorFactory.withName("variance"));
|
||||
Assert.assertEquals("newTest", varianceAggregatorFactory.withName("newTest").getName());
|
||||
|
||||
VarianceFoldingAggregatorFactory varianceFoldingAggregatorFactory = new VarianceFoldingAggregatorFactory(
|
||||
"varianceFold",
|
||||
"col",
|
||||
null
|
||||
);
|
||||
Assert.assertEquals(varianceFoldingAggregatorFactory, varianceFoldingAggregatorFactory.withName("varianceFold"));
|
||||
Assert.assertEquals("newTest", varianceFoldingAggregatorFactory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -227,6 +227,9 @@ public abstract class AggregatorFactory implements Cacheable
|
|||
@Nullable
|
||||
public abstract Object finalizeComputation(@Nullable Object object);
|
||||
|
||||
/**
|
||||
* @return output name of the aggregator column.
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
|
@ -347,6 +350,23 @@ public abstract class AggregatorFactory implements Cacheable
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in cases where we want to change the output name of the aggregator to something else. For eg: if we have
|
||||
* a query `select a, sum(b) as total group by a from table` the aggregator returned from the native group by query is "a0" set in
|
||||
* {@link org.apache.druid.sql.calcite.rel.DruidQuery#computeAggregations}. We can use withName("total") to set the output name
|
||||
* of the aggregator to "total".
|
||||
* <p>
|
||||
* As all implementations of this interface method may not exist, callers of this method are advised to handle such a case.
|
||||
*
|
||||
* @param newName newName of the output for aggregator factory
|
||||
* @return AggregatorFactory with the output name set as the input param.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
throw new UOE("Cannot change output name for AggregatorFactory[%s].", this.getClass().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the list of AggregatorFactory[] (presumable from metadata of some segments being merged) and
|
||||
* returns merged AggregatorFactory[] (for the metadata for merged segment).
|
||||
|
|
|
@ -109,6 +109,12 @@ public class CountAggregatorFactory extends AggregatorFactory
|
|||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new CountAggregatorFactory(newName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object finalizeComputation(@Nullable Object object)
|
||||
|
|
|
@ -117,6 +117,12 @@ public class DoubleMaxAggregatorFactory extends SimpleDoubleAggregatorFactory
|
|||
return Collections.singletonList(new DoubleMaxAggregatorFactory(fieldName, fieldName, expression, macroTable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new DoubleMaxAggregatorFactory(newName, getFieldName(), getExpression(), macroTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -117,6 +117,12 @@ public class DoubleMinAggregatorFactory extends SimpleDoubleAggregatorFactory
|
|||
return Collections.singletonList(new DoubleMinAggregatorFactory(fieldName, fieldName, expression, macroTable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new DoubleMinAggregatorFactory(newName, getFieldName(), getExpression(), macroTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -117,6 +117,12 @@ public class DoubleSumAggregatorFactory extends SimpleDoubleAggregatorFactory
|
|||
return Collections.singletonList(new DoubleSumAggregatorFactory(fieldName, fieldName, expression, macroTable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new DoubleSumAggregatorFactory(newName, getFieldName(), getExpression(), macroTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -452,6 +452,27 @@ public class ExpressionLambdaAggregatorFactory extends AggregatorFactory
|
|||
return getIntermediateType().isNumeric() ? 2 + Long.BYTES : maxSizeBytes.getBytesInInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new ExpressionLambdaAggregatorFactory(
|
||||
newName,
|
||||
fields,
|
||||
accumulatorId,
|
||||
initialValueExpressionString,
|
||||
initialCombineValueExpressionString,
|
||||
isNullUnlessAggregated,
|
||||
shouldAggregateNullInputs,
|
||||
shouldCombineAggregateNullInputs,
|
||||
foldExpressionString,
|
||||
combineExpressionString,
|
||||
compareExpressionString,
|
||||
finalizeExpressionString,
|
||||
maxSizeBytes,
|
||||
macroTable
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -165,6 +165,12 @@ public class FilteredAggregatorFactory extends AggregatorFactory
|
|||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new FilteredAggregatorFactory(delegate.withName(newName), dimFilter, newName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> requiredFields()
|
||||
{
|
||||
|
|
|
@ -117,6 +117,12 @@ public class FloatMaxAggregatorFactory extends SimpleFloatAggregatorFactory
|
|||
return Collections.singletonList(new FloatMaxAggregatorFactory(fieldName, fieldName, expression, macroTable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new FloatMaxAggregatorFactory(newName, getFieldName(), getExpression(), macroTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -117,6 +117,12 @@ public class FloatMinAggregatorFactory extends SimpleFloatAggregatorFactory
|
|||
return Collections.singletonList(new FloatMinAggregatorFactory(fieldName, fieldName, expression, macroTable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new FloatMinAggregatorFactory(newName, getFieldName(), getExpression(), macroTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -117,6 +117,12 @@ public class FloatSumAggregatorFactory extends SimpleFloatAggregatorFactory
|
|||
return Collections.singletonList(new FloatSumAggregatorFactory(fieldName, fieldName, expression, macroTable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new FloatSumAggregatorFactory(newName, getFieldName(), getExpression(), macroTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -224,6 +224,12 @@ public class GroupingAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new GroupingAggregatorFactory(newName, groupings, keyDimensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -229,6 +229,12 @@ public class HistogramAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES * (breaks.length + 1) + Float.BYTES * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new HistogramAggregatorFactory(newName, fieldName, breaksList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -285,6 +285,19 @@ public class JavaScriptAggregatorFactory extends AggregatorFactory
|
|||
return Double.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new JavaScriptAggregatorFactory(
|
||||
newName,
|
||||
getFieldNames(),
|
||||
getFnAggregate(),
|
||||
getFnReset(),
|
||||
getFnCombine(),
|
||||
config
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -117,6 +117,12 @@ public class LongMaxAggregatorFactory extends SimpleLongAggregatorFactory
|
|||
return Collections.singletonList(new LongMaxAggregatorFactory(fieldName, fieldName, expression, macroTable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new LongMaxAggregatorFactory(newName, getFieldName(), getExpression(), macroTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -117,6 +117,12 @@ public class LongMinAggregatorFactory extends SimpleLongAggregatorFactory
|
|||
return Collections.singletonList(new LongMinAggregatorFactory(fieldName, fieldName, expression, macroTable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new LongMinAggregatorFactory(newName, getFieldName(), getExpression(), macroTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -105,6 +105,12 @@ public class LongSumAggregatorFactory extends SimpleLongAggregatorFactory
|
|||
return new LongSumAggregateCombiner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new LongSumAggregatorFactory(newName, getFieldName(), getExpression(), macroTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory getCombiningFactory()
|
||||
{
|
||||
|
|
|
@ -169,6 +169,12 @@ public class SuppressedAggregatorFactory extends AggregatorFactory
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new SuppressedAggregatorFactory(delegate.withName(newName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -226,6 +226,12 @@ public class DoubleAnyAggregatorFactory extends AggregatorFactory
|
|||
return Double.BYTES + Byte.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new DoubleAnyAggregatorFactory(newName, getFieldName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -224,6 +224,12 @@ public class FloatAnyAggregatorFactory extends AggregatorFactory
|
|||
return Float.BYTES + Byte.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new FloatAnyAggregatorFactory(newName, getFieldName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -222,6 +222,12 @@ public class LongAnyAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES + Byte.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new LongAnyAggregatorFactory(newName, getFieldName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
|
|
|
@ -196,6 +196,12 @@ public class StringAnyAggregatorFactory extends AggregatorFactory
|
|||
return Integer.BYTES + maxStringBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new StringAnyAggregatorFactory(newName, getFieldName(), getMaxStringBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -338,6 +338,12 @@ public class CardinalityAggregatorFactory extends AggregatorFactory
|
|||
return HyperLogLogCollector.getLatestNumBytesForDenseStorage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new CardinalityAggregatorFactory(newName, null, getFields(), byRow, round);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
|
|
|
@ -302,6 +302,12 @@ public class DoubleFirstAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES + Byte.BYTES + Double.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new DoubleFirstAggregatorFactory(newName, getFieldName(), getTimeColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -297,6 +297,12 @@ public class FloatFirstAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES + Byte.BYTES + Float.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new FloatFirstAggregatorFactory(newName, getFieldName(), getTimeColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -295,6 +295,12 @@ public class LongFirstAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES + Byte.BYTES + Long.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new LongFirstAggregatorFactory(newName, getFieldName(), getTimeColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -260,6 +260,12 @@ public class StringFirstAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES + Integer.BYTES + maxStringBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new StringFirstAggregatorFactory(newName, getFieldName(), getTimeColumn(), getMaxStringBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.apache.druid.query.aggregation.first;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import org.apache.druid.query.aggregation.AggregatorFactory;
|
||||
|
||||
/**
|
||||
* For backwards compatibility; equivalent to a regular StringFirstAggregatorFactory.
|
||||
|
@ -31,4 +32,10 @@ public class StringFirstFoldingAggregatorFactory extends StringFirstAggregatorFa
|
|||
{
|
||||
super(name, fieldName, null, maxStringBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new StringFirstFoldingAggregatorFactory(newName, getFieldName(), getMaxStringBytes());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,6 +284,12 @@ public class HyperUniquesAggregatorFactory extends AggregatorFactory
|
|||
return HyperLogLogCollector.getLatestNumBytesForDenseStorage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new HyperUniquesAggregatorFactory(newName, getFieldName(), getIsInputHyperUnique(), isRound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -330,6 +330,12 @@ public class DoubleLastAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES + Byte.BYTES + Double.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new DoubleLastAggregatorFactory(newName, getFieldName(), getTimeColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -325,6 +325,12 @@ public class FloatLastAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES + Byte.BYTES + Float.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new FloatLastAggregatorFactory(newName, getFieldName(), getTimeColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -322,6 +322,12 @@ public class LongLastAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES + Byte.BYTES + Long.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new LongLastAggregatorFactory(newName, getFieldName(), getTimeColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -275,6 +275,12 @@ public class StringLastAggregatorFactory extends AggregatorFactory
|
|||
return Long.BYTES + Integer.BYTES + maxStringBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new StringLastAggregatorFactory(newName, getFieldName(), getTimeColumn(), getMaxStringBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.apache.druid.query.aggregation.last;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import org.apache.druid.query.aggregation.AggregatorFactory;
|
||||
|
||||
/**
|
||||
* For backwards compatibility; equivalent to a regular StringLastAggregatorFactory.
|
||||
|
@ -31,4 +32,10 @@ public class StringLastFoldingAggregatorFactory extends StringLastAggregatorFact
|
|||
{
|
||||
super(name, fieldName, null, maxStringBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new StringLastFoldingAggregatorFactory(newName, getFieldName(), getMaxStringBytes());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import javax.annotation.Nullable;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -100,6 +101,12 @@ public class DoubleMeanAggregatorFactory extends AggregatorFactory
|
|||
return DoubleMeanHolder.MAX_INTERMEDIATE_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new DoubleMeanAggregatorFactory(newName, getFieldName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Aggregator factorize(ColumnSelectorFactory metricFactory)
|
||||
{
|
||||
|
@ -196,4 +203,23 @@ public class DoubleMeanAggregatorFactory extends AggregatorFactory
|
|||
.appendString(fieldName)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
DoubleMeanAggregatorFactory that = (DoubleMeanAggregatorFactory) o;
|
||||
return Objects.equals(name, that.name) && Objects.equals(fieldName, that.fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(name, fieldName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.apache.druid.query;
|
||||
|
||||
import org.apache.druid.query.aggregation.AggregatorFactory;
|
||||
import org.apache.druid.query.aggregation.DoubleSumAggregatorFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -45,6 +46,12 @@ public class TestBigDecimalSumAggregatorFactory extends DoubleSumAggregatorFacto
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new TestBigDecimalSumAggregatorFactory(newName, getFieldName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object deserialize(Object object)
|
||||
{
|
||||
|
|
|
@ -50,6 +50,7 @@ import org.junit.Assert;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -267,4 +268,64 @@ public class AggregatorFactoryTest extends InitializedNullHandlingTest
|
|||
new TimeseriesQueryQueryToolChest().resultArraySignature(query)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
List<AggregatorFactory> aggregatorFactories = Arrays.asList(
|
||||
new CountAggregatorFactory("col"),
|
||||
new JavaScriptAggregatorFactory(
|
||||
"col",
|
||||
ImmutableList.of("col"),
|
||||
"function(a,b) { return a + b; }",
|
||||
"function() { return 0; }",
|
||||
"function(a,b) { return a + b }",
|
||||
new JavaScriptConfig(true)
|
||||
),
|
||||
// long aggs
|
||||
new LongSumAggregatorFactory("col", "long-col"),
|
||||
new LongMinAggregatorFactory("col", "long-col"),
|
||||
new LongMaxAggregatorFactory("col", "long-col"),
|
||||
new LongFirstAggregatorFactory("col", "long-col", null),
|
||||
new LongLastAggregatorFactory("col", "long-col", null),
|
||||
new LongAnyAggregatorFactory("col", "long-col"),
|
||||
// double aggs
|
||||
new DoubleSumAggregatorFactory("col", "double-col"),
|
||||
new DoubleMinAggregatorFactory("col", "double-col"),
|
||||
new DoubleMaxAggregatorFactory("col", "double-col"),
|
||||
new DoubleFirstAggregatorFactory("col", "double-col", null),
|
||||
new DoubleLastAggregatorFactory("col", "double-col", null),
|
||||
new DoubleAnyAggregatorFactory("col", "double-col"),
|
||||
new DoubleMeanAggregatorFactory("col", "double-col"),
|
||||
// float aggs
|
||||
new FloatSumAggregatorFactory("col", "float-col"),
|
||||
new FloatMinAggregatorFactory("col", "float-col"),
|
||||
new FloatMaxAggregatorFactory("col", "float-col"),
|
||||
new FloatFirstAggregatorFactory("col", "float-col", null),
|
||||
new FloatLastAggregatorFactory("col", "float-col", null),
|
||||
new FloatAnyAggregatorFactory("col", "float-col"),
|
||||
// string aggregators
|
||||
new StringFirstAggregatorFactory("col", "col", null, 1024),
|
||||
new StringLastAggregatorFactory("col", "col", null, 1024),
|
||||
new StringAnyAggregatorFactory("col", "col", 1024),
|
||||
// sketch aggs
|
||||
new CardinalityAggregatorFactory("col", ImmutableList.of(DefaultDimensionSpec.of("some-col")), false),
|
||||
new HyperUniquesAggregatorFactory("col", "hyperunique"),
|
||||
new HistogramAggregatorFactory("col", "histogram", ImmutableList.of(0.25f, 0.5f, 0.75f)),
|
||||
// delegate aggs
|
||||
new FilteredAggregatorFactory(
|
||||
new HyperUniquesAggregatorFactory("col", "hyperunique"),
|
||||
new SelectorDimFilter("col", "hello", null),
|
||||
"col"
|
||||
),
|
||||
new SuppressedAggregatorFactory(
|
||||
new HyperUniquesAggregatorFactory("col", "hyperunique")
|
||||
)
|
||||
);
|
||||
|
||||
for (AggregatorFactory aggregatorFactory : aggregatorFactories) {
|
||||
Assert.assertEquals(aggregatorFactory, aggregatorFactory.withName("col"));
|
||||
Assert.assertEquals("newTest", aggregatorFactory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,4 +61,13 @@ public class CountAggregatorTest
|
|||
Assert.assertEquals(0, comp.compare(agg.get(), agg.get()));
|
||||
Assert.assertEquals(1, comp.compare(agg.get(), first));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithName()
|
||||
{
|
||||
CountAggregatorFactory factory = new CountAggregatorFactory("test");
|
||||
Assert.assertEquals(factory, factory.withName("test"));
|
||||
|
||||
Assert.assertEquals("newTest", factory.withName("newTest").getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -476,6 +476,12 @@ public class SegmentAnalyzerTest extends InitializedNullHandlingTest
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new InvalidAggregatorFactory(newName, fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.druid.segment.virtual;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.apache.druid.query.aggregation.Aggregator;
|
||||
import org.apache.druid.query.aggregation.AggregatorFactory;
|
||||
import org.apache.druid.query.aggregation.BufferAggregator;
|
||||
import org.apache.druid.query.aggregation.CountAggregatorFactory;
|
||||
import org.apache.druid.query.aggregation.CountVectorAggregator;
|
||||
|
@ -83,7 +84,8 @@ public class AlwaysTwoCounterAggregatorFactory extends CountAggregatorFactory
|
|||
return new AlwaysTwoCounterVectorAggregator(selectorFactory.makeMultiValueDimensionSelector(
|
||||
DefaultDimensionSpec.of(fieldName)));
|
||||
}
|
||||
return new AlwaysTwoCounterVectorAggregator(selectorFactory.makeSingleValueDimensionSelector(DefaultDimensionSpec.of(fieldName)));
|
||||
return new AlwaysTwoCounterVectorAggregator(selectorFactory.makeSingleValueDimensionSelector(
|
||||
DefaultDimensionSpec.of(fieldName)));
|
||||
}
|
||||
return new AlwaysTwoCounterVectorAggregator(selectorFactory.makeObjectSelector(fieldName));
|
||||
default:
|
||||
|
@ -91,6 +93,12 @@ public class AlwaysTwoCounterAggregatorFactory extends CountAggregatorFactory
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregatorFactory withName(String newName)
|
||||
{
|
||||
return new AlwaysTwoCounterAggregatorFactory(newName, fieldName);
|
||||
}
|
||||
|
||||
public static class AlwaysTwoCounterVectorAggregator extends CountVectorAggregator
|
||||
{
|
||||
@Nullable
|
||||
|
|
Loading…
Reference in New Issue