-
Notifications
You must be signed in to change notification settings - Fork 841
feat(query): enable hashtable state pass from partial to final #9809
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
158650d
update
sundy-li 3e5bb9c
enable hashstate info
sundy-li ed533d5
remove tail array in hashtable
sundy-li 5e777a9
keep holder in meta
sundy-li 55ed033
keep holder in meta
sundy-li 0f59b80
add unique serde info
sundy-li 1574e56
fix unwrap
sundy-li cabb794
Merge branch 'main' into hashtable-state
sundy-li 20433b9
fix(query): remove tail array
sundy-li b6a652e
fix(query): fix copyright
sundy-li File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,141 @@ | ||
| // Copyright 2021 Datafuse Labs. | ||
| // | ||
| // Licensed 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. | ||
|
|
||
| use std::alloc::Allocator; | ||
|
|
||
| use super::table0::Entry; | ||
| use super::traits::Keyable; | ||
|
|
||
| const SIZE: usize = 4096; | ||
|
|
||
| pub struct TailArray<K, V, A: Allocator> { | ||
| allocator: A, | ||
| pub(crate) datas: Vec<Box<[Entry<K, V>; SIZE], A>>, | ||
| pub(crate) num_items: usize, | ||
| } | ||
|
|
||
| impl<K, V, A> TailArray<K, V, A> | ||
| where | ||
| K: Keyable, | ||
| A: Allocator + Clone, | ||
| { | ||
| pub fn new(allocator: A) -> Self { | ||
| Self { | ||
| datas: vec![], | ||
| num_items: 0, | ||
| allocator, | ||
| } | ||
| } | ||
|
|
||
| pub fn insert(&mut self, key: K) -> &mut Entry<K, V> { | ||
| let pos = self.num_items % SIZE; | ||
| if pos == 0 { | ||
| let data = unsafe { | ||
| Box::<[Entry<K, V>; SIZE], A>::new_zeroed_in(self.allocator.clone()).assume_init() | ||
| }; | ||
| self.datas.push(data); | ||
| } | ||
|
|
||
| let tail = self.datas.last_mut().unwrap(); | ||
| unsafe { tail[pos].set_key(key) }; | ||
|
|
||
| self.num_items += 1; | ||
| &mut tail[pos] | ||
| } | ||
|
|
||
| pub fn iter(&self) -> TailArrayIter<'_, K, V> { | ||
| TailArrayIter { | ||
| values: self.datas.iter().map(|v| v.as_ref().as_ref()).collect(), | ||
| num_items: self.num_items, | ||
| i: 0, | ||
| } | ||
| } | ||
|
|
||
| #[allow(dead_code)] | ||
| pub fn iter_mut(&mut self) -> TailArrayIterMut<'_, K, V> { | ||
| TailArrayIterMut { | ||
| values: self.datas.iter_mut().map(|v| v.as_mut().as_mut()).collect(), | ||
| num_items: self.num_items, | ||
| i: 0, | ||
| } | ||
| } | ||
|
|
||
| pub fn len(&self) -> usize { | ||
| self.num_items | ||
| } | ||
|
|
||
| pub fn capacity(&self) -> usize { | ||
| self.datas.len() * SIZE | ||
| } | ||
| } | ||
|
|
||
| pub struct TailArrayIter<'a, K, V> { | ||
| values: Vec<&'a [Entry<K, V>]>, | ||
| num_items: usize, | ||
| i: usize, | ||
| } | ||
|
|
||
| impl<'a, K, V> Iterator for TailArrayIter<'a, K, V> { | ||
| type Item = &'a Entry<K, V>; | ||
|
|
||
| fn next(&mut self) -> Option<Self::Item> { | ||
| if self.i >= self.num_items { | ||
| None | ||
| } else { | ||
| let array = self.i / SIZE; | ||
| let pos = self.i % SIZE; | ||
|
|
||
| let v = self.values[array]; | ||
| let res = &v[pos]; | ||
| self.i += 1; | ||
| Some(res) | ||
| } | ||
| } | ||
|
|
||
| #[inline] | ||
| fn size_hint(&self) -> (usize, Option<usize>) { | ||
| (self.num_items - self.i, Some(self.num_items - self.i)) | ||
| } | ||
| } | ||
|
|
||
| pub struct TailArrayIterMut<'a, K, V> { | ||
| values: Vec<&'a mut [Entry<K, V>]>, | ||
| num_items: usize, | ||
| i: usize, | ||
| } | ||
|
|
||
| impl<'a, K, V> Iterator for TailArrayIterMut<'a, K, V> | ||
| where Self: 'a | ||
| { | ||
| type Item = &'a mut Entry<K, V> where Self: 'a ; | ||
|
|
||
| fn next(&mut self) -> Option<Self::Item> { | ||
| if self.i >= self.num_items { | ||
| None | ||
| } else { | ||
| let array = self.i / SIZE; | ||
| let pos = self.i % SIZE; | ||
|
|
||
| let v = &mut self.values[array]; | ||
| let res = unsafe { &mut *(v.as_ptr().add(pos) as *mut _) }; | ||
| self.i += 1; | ||
| Some(res) | ||
| } | ||
| } | ||
|
|
||
| #[inline] | ||
| fn size_hint(&self) -> (usize, Option<usize>) { | ||
| (self.num_items - self.i, Some(self.num_items - self.i)) | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
79 changes: 79 additions & 0 deletions
79
src/query/service/src/pipelines/processors/transforms/aggregator/aggregate_hashstate_info.rs
This file contains hidden or 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,79 @@ | ||
| // Copyright 2022 Datafuse Labs. | ||
| // | ||
| // Licensed 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. | ||
|
|
||
| use std::any::Any; | ||
|
|
||
| use common_expression::BlockMetaInfo; | ||
| use common_expression::BlockMetaInfoPtr; | ||
| use serde::Deserialize; | ||
| use serde::Deserializer; | ||
| use serde::Serialize; | ||
| use serde::Serializer; | ||
|
|
||
| use crate::pipelines::processors::transforms::group_by::ArenaHolder; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct AggregateHashStateInfo { | ||
| pub bucket: usize, | ||
| // a subhashtable state | ||
| pub hash_state: Box<dyn Any + Send + Sync>, | ||
| pub state_holder: Option<ArenaHolder>, | ||
| } | ||
|
|
||
| impl AggregateHashStateInfo { | ||
| pub fn create( | ||
| bucket: usize, | ||
| hash_state: Box<dyn Any + Send + Sync>, | ||
| state_holder: Option<ArenaHolder>, | ||
| ) -> BlockMetaInfoPtr { | ||
| Box::new(AggregateHashStateInfo { | ||
| bucket, | ||
| hash_state, | ||
| state_holder, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl Serialize for AggregateHashStateInfo { | ||
| fn serialize<S>(&self, _: S) -> Result<S::Ok, S::Error> | ||
| where S: Serializer { | ||
| unreachable!("AggregateHashStateInfo does not support exchanging between multiple nodes") | ||
| } | ||
| } | ||
|
|
||
| impl<'de> Deserialize<'de> for AggregateHashStateInfo { | ||
| fn deserialize<D>(_: D) -> Result<Self, D::Error> | ||
| where D: Deserializer<'de> { | ||
| unreachable!("AggregateHashStateInfo does not support exchanging between multiple nodes") | ||
| } | ||
| } | ||
|
|
||
| #[typetag::serde(name = "aggregate_hash_state_info")] | ||
| impl BlockMetaInfo for AggregateHashStateInfo { | ||
| fn as_any(&self) -> &dyn Any { | ||
| self | ||
| } | ||
|
|
||
| fn as_mut_any(&mut self) -> &mut dyn Any { | ||
| self | ||
| } | ||
|
|
||
| fn clone_self(&self) -> Box<dyn BlockMetaInfo> { | ||
| unimplemented!("Unimplemented clone for AggregateHashStateInfo") | ||
| } | ||
|
|
||
| fn equals(&self, _: &Box<dyn BlockMetaInfo>) -> bool { | ||
| unimplemented!("Unimplemented equals for AggregateHashStateInfo") | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.