You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "clintropolis (via GitHub)" <gi...@apache.org> on 2024/10/10 02:03:45 UTC
[PR] add substituteCombiningFactory implementations for datasketches aggs (druid)
clintropolis opened a new pull request, #17314:
URL: https://github.com/apache/druid/pull/17314
Follow up to #17214, adds implementations for `substituteCombiningFactory` so that more datasketches aggs can match projections, along with some projections tests for datasketches.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] add substituteCombiningFactory implementations for datasketches aggs (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #17314:
URL: https://github.com/apache/druid/pull/17314#discussion_r1794745527
##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchAggregatorFactory.java:
##########
@@ -266,6 +267,22 @@ public byte[] getCacheKey()
.array();
}
+ @Override
+ public AggregatorFactory substituteCombiningFactory(AggregatorFactory preAggregated)
Review Comment:
hmm, i suppose it wouldn't hurt, though i can't imagine the field would be the same name and `isInputThetaSketch` be true in query agg but not in projection agg, or the other way, can add just in case since i need to make some other changes
##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchAggregatorFactory.java:
##########
@@ -307,6 +307,29 @@ public ColumnType getResultType()
return ColumnType.DOUBLE;
}
+ @Nullable
+ @Override
+ public AggregatorFactory substituteCombiningFactory(AggregatorFactory preAggregated)
+ {
+ if (this == preAggregated) {
+ return getCombiningFactory();
+ }
+
+ if (getClass() != preAggregated.getClass()) {
+ return null;
+ }
+
+ ArrayOfDoublesSketchAggregatorFactory that = (ArrayOfDoublesSketchAggregatorFactory) preAggregated;
+ if (nominalEntries <= that.nominalEntries &&
+ numberOfValues <= that.numberOfValues &&
Review Comment:
ah yeah, good catch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] add substituteCombiningFactory implementations for datasketches aggs (druid)
Posted by "gianm (via GitHub)" <gi...@apache.org>.
gianm commented on code in PR #17314:
URL: https://github.com/apache/druid/pull/17314#discussion_r1794719929
##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/HllSketchAggregatorFactory.java:
##########
@@ -289,10 +289,11 @@ public AggregatorFactory substituteCombiningFactory(AggregatorFactory preAggrega
return null;
}
HllSketchAggregatorFactory that = (HllSketchAggregatorFactory) preAggregated;
- if (lgK == that.lgK && tgtHllType == that.tgtHllType && stringEncoding == that.stringEncoding && Objects.equals(
- fieldName,
- that.fieldName
- )) {
+ if (lgK <= that.lgK &&
+ tgtHllType.ordinal() <= that.tgtHllType.ordinal() &&
Review Comment:
I don't think the `TgtHllType` needs to be part of the check here, since according to the datasketches docs:
> These three target types are isomorphic representations of the same underlying HLL algorithm. Thus, given the same value of lgConfigK and the same input, all three HLL target types will produce identical estimates and have identical error distributions.
& I think that the aggregator is able to merge two different HLL types together.
##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchAggregatorFactory.java:
##########
@@ -266,6 +267,22 @@ public byte[] getCacheKey()
.array();
}
+ @Override
+ public AggregatorFactory substituteCombiningFactory(AggregatorFactory preAggregated)
Review Comment:
does `SketchMergeAggregatorFactory` need to override this with an impl that checks `isInputThetaSketch`?
##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchAggregatorFactory.java:
##########
@@ -307,6 +307,29 @@ public ColumnType getResultType()
return ColumnType.DOUBLE;
}
+ @Nullable
+ @Override
+ public AggregatorFactory substituteCombiningFactory(AggregatorFactory preAggregated)
+ {
+ if (this == preAggregated) {
+ return getCombiningFactory();
+ }
+
+ if (getClass() != preAggregated.getClass()) {
+ return null;
+ }
+
+ ArrayOfDoublesSketchAggregatorFactory that = (ArrayOfDoublesSketchAggregatorFactory) preAggregated;
+ if (nominalEntries <= that.nominalEntries &&
+ numberOfValues <= that.numberOfValues &&
Review Comment:
I think `numberOfValues` needs to match. There's some code in `ArrayOfDoublesUnion` like:
```
if (gadget_.getNumValues() != tupleSketch.getNumValues()) {
throw new SketchesArgumentException("Incompatible sketches: number of values mismatch "
+ gadget_.getNumValues() + " and " + tupleSketch.getNumValues());
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] add substituteCombiningFactory implementations for datasketches aggs (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #17314:
URL: https://github.com/apache/druid/pull/17314#discussion_r1794744534
##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/HllSketchAggregatorFactory.java:
##########
@@ -289,10 +289,11 @@ public AggregatorFactory substituteCombiningFactory(AggregatorFactory preAggrega
return null;
}
HllSketchAggregatorFactory that = (HllSketchAggregatorFactory) preAggregated;
- if (lgK == that.lgK && tgtHllType == that.tgtHllType && stringEncoding == that.stringEncoding && Objects.equals(
- fieldName,
- that.fieldName
- )) {
+ if (lgK <= that.lgK &&
+ tgtHllType.ordinal() <= that.tgtHllType.ordinal() &&
Review Comment:
ah good catch :+1:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] add substituteCombiningFactory implementations for datasketches aggs (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17314:
URL: https://github.com/apache/druid/pull/17314#discussion_r1794523274
##########
extensions-core/datasketches/src/test/java/org/apache/druid/segment/DatasketchesProjectionTest.java:
##########
@@ -0,0 +1,464 @@
+/*
+ * 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.segment;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.datasketches.common.Family;
+import org.apache.datasketches.hll.HllSketch;
+import org.apache.datasketches.quantiles.DoublesSketch;
+import org.apache.datasketches.theta.SetOperation;
+import org.apache.datasketches.theta.Union;
+import org.apache.datasketches.thetacommon.ThetaUtil;
+import org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch;
+import org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketch;
+import org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketchBuilder;
+import org.apache.druid.collections.CloseableDefaultBlockingPool;
+import org.apache.druid.collections.CloseableStupidPool;
+import org.apache.druid.collections.NonBlockingPool;
+import org.apache.druid.data.input.impl.AggregateProjectionSpec;
+import org.apache.druid.data.input.impl.DimensionSchema;
+import org.apache.druid.data.input.impl.DimensionsSpec;
+import org.apache.druid.data.input.impl.DoubleDimensionSchema;
+import org.apache.druid.data.input.impl.FloatDimensionSchema;
+import org.apache.druid.data.input.impl.LongDimensionSchema;
+import org.apache.druid.data.input.impl.StringDimensionSchema;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.granularity.Granularities;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.query.DruidProcessingConfig;
+import org.apache.druid.query.QueryContexts;
+import org.apache.druid.query.aggregation.AggregatorFactory;
+import org.apache.druid.query.aggregation.datasketches.hll.HllSketchBuildAggregatorFactory;
+import org.apache.druid.query.aggregation.datasketches.hll.HllSketchHolder;
+import org.apache.druid.query.aggregation.datasketches.hll.HllSketchModule;
+import org.apache.druid.query.aggregation.datasketches.kll.KllDoublesSketchAggregatorFactory;
+import org.apache.druid.query.aggregation.datasketches.kll.KllSketchModule;
+import org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchAggregatorFactory;
+import org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchModule;
+import org.apache.druid.query.aggregation.datasketches.theta.SketchHolder;
+import org.apache.druid.query.aggregation.datasketches.theta.SketchMergeAggregatorFactory;
+import org.apache.druid.query.aggregation.datasketches.theta.SketchModule;
+import org.apache.druid.query.aggregation.datasketches.tuple.ArrayOfDoublesSketchAggregatorFactory;
+import org.apache.druid.query.aggregation.datasketches.tuple.ArrayOfDoublesSketchModule;
+import org.apache.druid.query.groupby.GroupByQuery;
+import org.apache.druid.query.groupby.GroupByQueryConfig;
+import org.apache.druid.query.groupby.GroupByResourcesReservationPool;
+import org.apache.druid.query.groupby.GroupingEngine;
+import org.apache.druid.query.groupby.ResultRow;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.segment.incremental.IncrementalIndex;
+import org.apache.druid.segment.incremental.IncrementalIndexCursorFactory;
+import org.apache.druid.segment.incremental.IncrementalIndexSchema;
+import org.apache.druid.testing.InitializedNullHandlingTest;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@RunWith(Parameterized.class)
+public class DatasketchesProjectionTest extends InitializedNullHandlingTest
+{
+ private static final Closer CLOSER = Closer.create();
+
+ private static final List<AggregateProjectionSpec> PROJECTIONS = Collections.singletonList(
+ new AggregateProjectionSpec(
+ "a_projection",
+ VirtualColumns.create(
+ Granularities.toVirtualColumn(Granularities.HOUR, "__gran")
+ ),
+ Arrays.asList(
+ new LongDimensionSchema("__gran"),
+ new StringDimensionSchema("a")
+ ),
+ new AggregatorFactory[]{
+ new HllSketchBuildAggregatorFactory("_b_hll", "b", null, null, null, null, false),
+ new SketchMergeAggregatorFactory("_b_theta", "b", null, null, false, null),
+ new DoublesSketchAggregatorFactory("_d_doubles", "d", null),
+ new ArrayOfDoublesSketchAggregatorFactory("_bcd_aod", "b", null, Arrays.asList("c", "d"), null),
+ new KllDoublesSketchAggregatorFactory("_d_kll", "d", null, null)
+ }
+ )
+ );
+
+ private static final List<AggregateProjectionSpec> AUTO_PROJECTIONS = PROJECTIONS.stream().map(projection -> {
+ return new AggregateProjectionSpec(
+ projection.getName(),
+ projection.getVirtualColumns(),
+ projection.getGroupingColumns()
+ .stream()
+ .map(x -> new AutoTypeColumnSchema(x.getName(), null))
+ .collect(Collectors.toList()),
+ projection.getAggregators()
+ );
+ }).collect(Collectors.toList());
+
+ @Parameterized.Parameters(name = "name: {0}, sortByDim: {3}, autoSchema: {4}")
+ public static Collection<?> constructorFeeder()
+ {
+ HllSketchModule.registerSerde();
+ TestHelper.JSON_MAPPER.registerModules(new HllSketchModule().getJacksonModules());
+ SketchModule.registerSerde();
+ TestHelper.JSON_MAPPER.registerModules(new SketchModule().getJacksonModules());
+ KllSketchModule.registerSerde();
+ TestHelper.JSON_MAPPER.registerModules(new KllSketchModule().getJacksonModules());
+ DoublesSketchModule.registerSerde();
+ TestHelper.JSON_MAPPER.registerModules(new DoublesSketchModule().getJacksonModules());
+ ArrayOfDoublesSketchModule.registerSerde();
+ TestHelper.JSON_MAPPER.registerModules(new ArrayOfDoublesSketchModule().getJacksonModules());
+
+ final List<Object[]> constructors = new ArrayList<>();
+ final DimensionsSpec.Builder dimensionsBuilder =
+ DimensionsSpec.builder()
+ .setDimensions(
+ Arrays.asList(
+ new StringDimensionSchema("a"),
+ new StringDimensionSchema("b"),
+ new LongDimensionSchema("c"),
+ new DoubleDimensionSchema("d"),
+ new FloatDimensionSchema("e")
+ )
+ );
+ DimensionsSpec dimsTimeOrdered = dimensionsBuilder.build();
+ DimensionsSpec dimsOrdered = dimensionsBuilder.setForceSegmentSortByTime(false).build();
+
+
+ List<DimensionSchema> autoDims = dimsOrdered.getDimensions()
+ .stream()
+ .map(x -> new AutoTypeColumnSchema(x.getName(), null))
+ .collect(Collectors.toList());
+ for (boolean incremental : new boolean[]{true, false}) {
+ for (boolean sortByDim : new boolean[]{true, false}) {
+ for (boolean autoSchema : new boolean[]{true, false}) {
+ final DimensionsSpec dims;
+ if (sortByDim) {
+ if (autoSchema) {
+ dims = dimsOrdered.withDimensions(autoDims);
+ } else {
+ dims = dimsOrdered;
+ }
+ } else {
+ if (autoSchema) {
+ dims = dimsTimeOrdered.withDimensions(autoDims);
+ } else {
+ dims = dimsTimeOrdered;
+ }
+ }
+ if (incremental) {
+ IncrementalIndex index = CLOSER.register(makeBuilder(dims, autoSchema).buildIncrementalIndex());
+ constructors.add(new Object[]{
+ "incrementalIndex",
+ new IncrementalIndexCursorFactory(index),
+ new IncrementalIndexTimeBoundaryInspector(index),
+ sortByDim,
+ autoSchema
+ });
+ } else {
+ QueryableIndex index = CLOSER.register(makeBuilder(dims, autoSchema).buildMMappedIndex());
+ constructors.add(new Object[]{
+ "queryableIndex",
+ new QueryableIndexCursorFactory(index),
+ QueryableIndexTimeBoundaryInspector.create(index),
+ sortByDim,
+ autoSchema
+ });
+ }
+ }
+ }
+ }
+ return constructors;
+ }
+
+ @AfterClass
+ public static void cleanup() throws IOException
+ {
+ CLOSER.close();
+ }
+
+ private static IndexBuilder makeBuilder(DimensionsSpec dimensionsSpec, boolean autoSchema)
+ {
+ File tmp = FileUtils.createTempDir();
+ CLOSER.register(tmp::delete);
+ return IndexBuilder.create()
+ .tmpDir(tmp)
+ .schema(
+ IncrementalIndexSchema.builder()
+ .withDimensionsSpec(dimensionsSpec)
+ .withRollup(false)
+ .withMinTimestamp(CursorFactoryProjectionTest.TIMESTAMP.getMillis())
+ .withProjections(autoSchema ? AUTO_PROJECTIONS : PROJECTIONS)
+ .build()
+ )
+ .rows(CursorFactoryProjectionTest.ROWS);
+ }
+
+ public final CursorFactory projectionsCursorFactory;
+ public final TimeBoundaryInspector projectionsTimeBoundaryInspector;
+
+ private final GroupingEngine groupingEngine;
+
+ private final NonBlockingPool<ByteBuffer> nonBlockingPool;
+ public final boolean sortByDim;
+ public final boolean autoSchema;
+
+ @Rule
+ public final CloserRule closer = new CloserRule(false);
+
+ public DatasketchesProjectionTest(
+ String name,
Review Comment:
## Useless parameter
The parameter 'name' is never used.
[Show more details](https://github.com/apache/druid/security/code-scanning/8389)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] add substituteCombiningFactory implementations for datasketches aggs (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz merged PR #17314:
URL: https://github.com/apache/druid/pull/17314
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org