Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with while adding DistinctSketches #17184

Merged
merged 2 commits into from
Sep 30, 2024
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 @@ -120,8 +120,9 @@ public void add(RowKey key, long weight)
if (isNewMin || isKeySelected(key)) {
if (isNewMin && !retainedKeys.isEmpty() && !isKeySelected(retainedKeys.firstKey())) {
// Old min should be kicked out.
totalWeightUnadjusted -= retainedKeys.removeLong(retainedKeys.firstKey());
retainedBytes -= retainedKeys.firstKey().estimatedObjectSizeBytes();
RowKey rowKey = retainedKeys.firstKey();
totalWeightUnadjusted -= retainedKeys.removeLong(rowKey);
retainedBytes -= rowKey.estimatedObjectSizeBytes();
}

if (retainedKeys.putIfAbsent(key, weight) == MISSING_KEY_WEIGHT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.druid.msq.statistics;

import com.google.common.collect.ImmutableList;
import it.unimi.dsi.fastutil.objects.Object2LongRBTreeMap;
import org.apache.druid.common.config.NullHandling;
import org.apache.druid.frame.key.ClusterBy;
import org.apache.druid.frame.key.ClusterByPartition;
Expand Down Expand Up @@ -90,6 +91,21 @@ public void test_sequentialKeys_unweighted()
);
}

@Test
public void test_single_key_addition()
{
DistinctKeyCollector distinctKeyCollector = new DistinctKeyCollector(
clusterBy.keyComparator(signature),
new Object2LongRBTreeMap<>(comparator),
2
);
List<Pair<RowKey, Integer>> pairs = KeyCollectorTestUtils.sequentialKeys(2);

distinctKeyCollector.add(pairs.get(1).lhs, pairs.get(1).rhs);
distinctKeyCollector.downSample();
distinctKeyCollector.add(pairs.get(0).lhs, pairs.get(0).rhs);
}

@Test
public void test_uniformRandomKeys_unweighted()
{
Expand Down
Loading