Repository navigation
fix(query-engine): run top-k CMSHeap on FastPath #829
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -758,8 +758,12 @@ impl AccumulatorUpdater for CmsWithHeapAccumulatorUpdater { | |
| } | ||
|
|
||
| fn update_keyed(&mut self, key: &KeyByLabelValues, value: f64, _timestamp_ms: i64) { | ||
| let weight = if self.count_events { 1.0 } else { value }; | ||
| self.acc.inner.update(&key.to_semicolon_str(), weight); | ||
| let count = if self.count_events { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fractional SUM values lost. Every sample is rounded to i32 and anything ≤0 is dropped by |
||
| 1 | ||
| } else { | ||
| value.round() as i32 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silent clamping. |
||
| }; | ||
| self.acc.update(&key.to_semicolon_str(), count); | ||
| } | ||
|
|
||
| impl_accumulator_methods!(acc); | ||
|
|
@@ -775,7 +779,7 @@ impl AccumulatorUpdater for CmsWithHeapAccumulatorUpdater { | |
|
|
||
| fn memory_usage_bytes(&self) -> usize { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Memory undercounted. |
||
| std::mem::size_of::<CountMinSketchWithHeapAccumulator>() | ||
| + self.row_num * self.col_num * std::mem::size_of::<f64>() | ||
| + self.row_num * self.col_num * std::mem::size_of::<i32>() | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1928,14 +1932,24 @@ mod tests { | |
|
|
||
| let key = KeyByLabelValues::new_with_labels(vec!["10.0.0.1".to_string()]); | ||
| for _ in 0..5 { | ||
| updater.update_keyed(&key, 10.0, 0); | ||
| updater.update_keyed(&key, 1.6, 0); | ||
| } | ||
| let acc = updater.take_accumulator(); | ||
| let cms = acc | ||
| .as_any() | ||
| .downcast_ref::<CountMinSketchWithHeapAccumulator>() | ||
| .unwrap(); | ||
| assert_eq!(cms.query_key(&key), 50.0, "sum of 5×10 == 50"); | ||
| assert_eq!(cms.query_key(&key), 10.0, "sum of 5×round(1.6) == 10"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_cms_with_heap_memory_uses_i32_counters() { | ||
| let updater = CmsWithHeapAccumulatorUpdater::new(3, 7, 32, true); | ||
|
|
||
| assert_eq!( | ||
| updater.memory_usage_bytes(), | ||
| std::mem::size_of::<CountMinSketchWithHeapAccumulator>() + 3 * 7 * 4 | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stale doc comment (~line 729, outside the diff): the updater doc still says it wraps
CountMinSketchWithHeapand feeds "the sample value itself", but it now rounds to i32 on the FastPath CMSHeap. Checklist §3: docs must change with behavior.