From a28b8c26745cc9656ce4aa3e0301f6ebd8ed76f4 Mon Sep 17 00:00:00 2001 From: Adarsh Sanjeev Date: Tue, 8 Nov 2022 10:12:07 +0530 Subject: [PATCH] Improve rowkey object size estimate (#13319) * Improve rowkey object size estimate * Address review comments * Update comment * Fix test --- .../msq/statistics/DelegateOrMinKeyCollector.java | 2 +- .../druid/msq/statistics/DistinctKeyCollector.java | 6 +++--- .../msq/statistics/QuantilesSketchKeyCollector.java | 2 +- .../QuantilesSketchKeyCollectorFactory.java | 2 +- .../statistics/DelegateOrMinKeyCollectorTest.java | 8 ++++---- .../statistics/QuantilesSketchKeyCollectorTest.java | 6 +++--- .../main/java/org/apache/druid/frame/key/RowKey.java | 12 ++++++++++-- .../java/org/apache/druid/frame/key/RowKeyTest.java | 4 ++-- 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/DelegateOrMinKeyCollector.java b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/DelegateOrMinKeyCollector.java index e2e2282a6bb..e076194f2a8 100644 --- a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/DelegateOrMinKeyCollector.java +++ b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/DelegateOrMinKeyCollector.java @@ -133,7 +133,7 @@ public class DelegateOrMinKeyCollector if (delegate != null) { return delegate.estimatedRetainedBytes(); } else { - return minKey != null ? minKey.getNumberOfBytes() : 0; + return minKey != null ? minKey.estimatedObjectSizeBytes() : 0; } } diff --git a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/DistinctKeyCollector.java b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/DistinctKeyCollector.java index 9a1716a9fbb..f88174b3335 100644 --- a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/DistinctKeyCollector.java +++ b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/DistinctKeyCollector.java @@ -121,13 +121,13 @@ public class DistinctKeyCollector implements KeyCollector if (isNewMin && !retainedKeys.isEmpty() && !isKeySelected(retainedKeys.firstKey())) { // Old min should be kicked out. totalWeightUnadjusted -= retainedKeys.removeLong(retainedKeys.firstKey()); - retainedBytes -= retainedKeys.firstKey().getNumberOfBytes(); + retainedBytes -= retainedKeys.firstKey().estimatedObjectSizeBytes(); } if (retainedKeys.putIfAbsent(key, weight) == MISSING_KEY_WEIGHT) { // We did add this key. (Previous value was zero, meaning absent.) totalWeightUnadjusted += weight; - retainedBytes += key.getNumberOfBytes(); + retainedBytes += key.estimatedObjectSizeBytes(); } while (retainedBytes >= maxBytes) { @@ -305,7 +305,7 @@ public class DistinctKeyCollector implements KeyCollector if (!isKeySelected(key)) { totalWeightUnadjusted -= entry.getLongValue(); - retainedBytes -= entry.getKey().getNumberOfBytes(); + retainedBytes -= entry.getKey().estimatedObjectSizeBytes(); iterator.remove(); } } diff --git a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/QuantilesSketchKeyCollector.java b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/QuantilesSketchKeyCollector.java index 16203247354..2a5ee777a04 100644 --- a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/QuantilesSketchKeyCollector.java +++ b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/QuantilesSketchKeyCollector.java @@ -64,7 +64,7 @@ public class QuantilesSketchKeyCollector implements KeyCollector