-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend Merge Rollup Capabilities for Datasketches (#14625)
- Loading branch information
1 parent
26ad816
commit e12aab4
Showing
7 changed files
with
288 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...apache/pinot/core/segment/processing/aggregator/DistinctCountCPCSketchAggregatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* 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.pinot.core.segment.processing.aggregator; | ||
|
||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.datasketches.cpc.CpcSketch; | ||
import org.apache.pinot.core.common.ObjectSerDeUtils; | ||
import org.apache.pinot.segment.spi.Constants; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
public class DistinctCountCPCSketchAggregatorTest { | ||
|
||
private DistinctCountCPCSketchAggregator _cpcSketchAggregator; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
_cpcSketchAggregator = new DistinctCountCPCSketchAggregator(); | ||
} | ||
|
||
@Test | ||
public void testAggregateWithDefaultLgK() { | ||
CpcSketch firstSketch = new CpcSketch(10); | ||
CpcSketch secondSketch = new CpcSketch(20); | ||
byte[] value1 = ObjectSerDeUtils.DATA_SKETCH_CPC_SER_DE.serialize(firstSketch); | ||
byte[] value2 = ObjectSerDeUtils.DATA_SKETCH_CPC_SER_DE.serialize(secondSketch); | ||
|
||
Map<String, String> functionParameters = new HashMap<>(); | ||
byte[] result = (byte[]) _cpcSketchAggregator.aggregate(value1, value2, functionParameters); | ||
|
||
CpcSketch resultSketch = ObjectSerDeUtils.DATA_SKETCH_CPC_SER_DE.deserialize(result); | ||
assertNotNull(resultSketch); | ||
assertEquals(resultSketch.getLgK(), 12); | ||
} | ||
|
||
@Test | ||
public void testAggregateWithFunctionParameters() { | ||
CpcSketch firstSketch = new CpcSketch(10); | ||
CpcSketch secondSketch = new CpcSketch(20); | ||
byte[] value1 = ObjectSerDeUtils.DATA_SKETCH_CPC_SER_DE.serialize(firstSketch); | ||
byte[] value2 = ObjectSerDeUtils.DATA_SKETCH_CPC_SER_DE.serialize(secondSketch); | ||
|
||
Map<String, String> functionParameters = new HashMap<>(); | ||
functionParameters.put(Constants.CPCSKETCH_LGK_KEY, "15"); | ||
|
||
byte[] result = (byte[]) _cpcSketchAggregator.aggregate(value1, value2, functionParameters); | ||
|
||
CpcSketch resultSketch = ObjectSerDeUtils.DATA_SKETCH_CPC_SER_DE.deserialize(result); | ||
assertNotNull(resultSketch); | ||
assertEquals(resultSketch.getLgK(), 15); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...ache/pinot/core/segment/processing/aggregator/DistinctCountThetaSketchAggregatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* 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.pinot.core.segment.processing.aggregator; | ||
|
||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.datasketches.theta.Sketch; | ||
import org.apache.datasketches.theta.UpdateSketch; | ||
import org.apache.pinot.core.common.ObjectSerDeUtils; | ||
import org.apache.pinot.segment.spi.Constants; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
public class DistinctCountThetaSketchAggregatorTest { | ||
|
||
private DistinctCountThetaSketchAggregator _thetaSketchAggregator; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
_thetaSketchAggregator = new DistinctCountThetaSketchAggregator(); | ||
} | ||
|
||
@Test | ||
public void testAggregateWithDefaultBehaviour() { | ||
Sketch firstSketch = createThetaSketch(64); | ||
Sketch secondSketch = createThetaSketch(32); | ||
byte[] value1 = ObjectSerDeUtils.DATA_SKETCH_THETA_SER_DE.serialize(firstSketch); | ||
byte[] value2 = ObjectSerDeUtils.DATA_SKETCH_THETA_SER_DE.serialize(secondSketch); | ||
Map<String, String> functionParameters = new HashMap<>(); | ||
|
||
byte[] result = (byte[]) _thetaSketchAggregator.aggregate(value1, value2, functionParameters); | ||
|
||
Sketch resultSketch = ObjectSerDeUtils.DATA_SKETCH_THETA_SER_DE.deserialize(result); | ||
assertNotNull(resultSketch); | ||
assertEquals(resultSketch.getRetainedEntries(), 64); | ||
} | ||
|
||
@Test | ||
public void testAggregateWithNominalEntries() { | ||
Sketch firstSketch = createThetaSketch(64); | ||
Sketch secondSketch = createThetaSketch(32); | ||
byte[] value1 = ObjectSerDeUtils.DATA_SKETCH_THETA_SER_DE.serialize(firstSketch); | ||
byte[] value2 = ObjectSerDeUtils.DATA_SKETCH_THETA_SER_DE.serialize(secondSketch); | ||
|
||
Map<String, String> functionParameters = new HashMap<>(); | ||
functionParameters.put(Constants.THETA_TUPLE_SKETCH_NOMINAL_ENTRIES, "32"); | ||
|
||
byte[] result = (byte[]) _thetaSketchAggregator.aggregate(value1, value2, functionParameters); | ||
|
||
Sketch resultSketch = ObjectSerDeUtils.DATA_SKETCH_THETA_SER_DE.deserialize(result); | ||
assertNotNull(resultSketch); | ||
assertEquals(resultSketch.getRetainedEntries(), 32); | ||
} | ||
|
||
@Test | ||
public void testAggregateWithSamplingProbability() { | ||
Sketch firstSketch = createThetaSketch(64); | ||
Sketch secondSketch = createThetaSketch(32); | ||
byte[] value1 = ObjectSerDeUtils.DATA_SKETCH_THETA_SER_DE.serialize(firstSketch); | ||
byte[] value2 = ObjectSerDeUtils.DATA_SKETCH_THETA_SER_DE.serialize(secondSketch); | ||
|
||
Map<String, String> functionParameters = new HashMap<>(); | ||
functionParameters.put(Constants.THETA_TUPLE_SKETCH_SAMPLING_PROBABILITY, "0.1"); | ||
|
||
byte[] result = (byte[]) _thetaSketchAggregator.aggregate(value1, value2, functionParameters); | ||
|
||
Sketch resultSketch = ObjectSerDeUtils.DATA_SKETCH_THETA_SER_DE.deserialize(result); | ||
assertNotNull(resultSketch); | ||
assertTrue(resultSketch.getRetainedEntries() < 64); | ||
} | ||
|
||
private Sketch createThetaSketch(int nominalEntries) { | ||
UpdateSketch updateSketch = UpdateSketch.builder().setNominalEntries(nominalEntries).build(); | ||
for (int i = 0; i < nominalEntries; i++) { | ||
updateSketch.update(i); | ||
} | ||
return updateSketch.compact(); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...org/apache/pinot/core/segment/processing/aggregator/IntegerTupleSketchAggregatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* 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.pinot.core.segment.processing.aggregator; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.datasketches.tuple.CompactSketch; | ||
import org.apache.datasketches.tuple.Sketch; | ||
import org.apache.datasketches.tuple.aninteger.IntegerSketch; | ||
import org.apache.datasketches.tuple.aninteger.IntegerSummary; | ||
import org.apache.pinot.core.common.ObjectSerDeUtils; | ||
import org.apache.pinot.segment.spi.Constants; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNotNull; | ||
|
||
|
||
public class IntegerTupleSketchAggregatorTest { | ||
|
||
private IntegerTupleSketchAggregator _tupleSketchAggregator; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
_tupleSketchAggregator = new IntegerTupleSketchAggregator(IntegerSummary.Mode.Max); | ||
} | ||
|
||
@Test | ||
public void testAggregateWithDefaultBehaviour() { | ||
Sketch<IntegerSummary> firstSketch = createTupleSketch(64); | ||
Sketch<IntegerSummary> secondSketch = createTupleSketch(32); | ||
byte[] value1 = ObjectSerDeUtils.DATA_SKETCH_INT_TUPLE_SER_DE.serialize(firstSketch); | ||
byte[] value2 = ObjectSerDeUtils.DATA_SKETCH_INT_TUPLE_SER_DE.serialize(secondSketch); | ||
Map<String, String> functionParameters = new HashMap<>(); | ||
|
||
byte[] result = (byte[]) _tupleSketchAggregator.aggregate(value1, value2, functionParameters); | ||
|
||
Sketch<IntegerSummary> resultSketch = ObjectSerDeUtils.DATA_SKETCH_INT_TUPLE_SER_DE.deserialize(result); | ||
assertNotNull(resultSketch); | ||
assertEquals(resultSketch.getRetainedEntries(), 64); | ||
} | ||
|
||
@Test | ||
public void testAggregateWithNominalEntries() { | ||
Sketch<IntegerSummary> firstSketch = createTupleSketch(64); | ||
Sketch<IntegerSummary> secondSketch = createTupleSketch(32); | ||
byte[] value1 = ObjectSerDeUtils.DATA_SKETCH_INT_TUPLE_SER_DE.serialize(firstSketch); | ||
byte[] value2 = ObjectSerDeUtils.DATA_SKETCH_INT_TUPLE_SER_DE.serialize(secondSketch); | ||
|
||
Map<String, String> functionParameters = new HashMap<>(); | ||
functionParameters.put(Constants.THETA_TUPLE_SKETCH_NOMINAL_ENTRIES, "32"); | ||
|
||
byte[] result = (byte[]) _tupleSketchAggregator.aggregate(value1, value2, functionParameters); | ||
|
||
Sketch<IntegerSummary> resultSketch = ObjectSerDeUtils.DATA_SKETCH_INT_TUPLE_SER_DE.deserialize(result); | ||
assertNotNull(resultSketch); | ||
assertEquals(resultSketch.getRetainedEntries(), 32); | ||
} | ||
|
||
private CompactSketch<IntegerSummary> createTupleSketch(int nominalEntries) { | ||
int lgK = (int) (Math.log(nominalEntries) / Math.log(2)); | ||
IntegerSketch integerSketch = new IntegerSketch(lgK, IntegerSummary.Mode.Max); | ||
for (int i = 0; i < nominalEntries; i++) { | ||
integerSketch.update(i, 1); | ||
} | ||
return integerSketch.compact(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters