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

feature(query): support FixedKey u128, u256, u512 in group query #5678

Merged
merged 7 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
97 changes: 95 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/datablocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ common-io = { path = "../io" }
# Crates.io dependencies
ahash = "0.7.6"
comfy-table = "5.0.1"
primitive-types = "0.6.1"
regex = "1.5.5"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
Expand Down
32 changes: 31 additions & 1 deletion common/datablocks/src/kernels/data_block_group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ use crate::kernels::HashMethodKind;
use crate::kernels::HashMethodSerializer;
use crate::DataBlock;
use crate::HashMethod;
use crate::HashMethodKeysU128;
use crate::HashMethodKeysU256;
use crate::HashMethodKeysU512;
use crate::HashMethodSingleString;

impl DataBlock {
Expand Down Expand Up @@ -80,7 +83,9 @@ impl DataBlock {
2 => Ok(HashMethodKind::KeysU16(HashMethodKeysU16::default())),
3..=4 => Ok(HashMethodKind::KeysU32(HashMethodKeysU32::default())),
5..=8 => Ok(HashMethodKind::KeysU64(HashMethodKeysU64::default())),
// TODO support u128, u256
9..=16 => Ok(HashMethodKind::KeysU128(HashMethodKeysU128::default())),
17..=32 => Ok(HashMethodKind::KeysU256(HashMethodKeysU256::default())),
33..=64 => Ok(HashMethodKind::KeysU512(HashMethodKeysU512::default())),
_ => Ok(HashMethodKind::Serializer(HashMethodSerializer::default())),
}
}
Expand Down Expand Up @@ -138,6 +143,31 @@ impl DataBlock {
.collect();
blocks
}

HashMethodKind::KeysU128(s) => {
let blocks = s
.group_by(block, column_names)?
.iter()
.map(|(_, _, b)| b.clone())
.collect();
blocks
}
HashMethodKind::KeysU256(s) => {
let blocks = s
.group_by(block, column_names)?
.iter()
.map(|(_, _, b)| b.clone())
.collect();
blocks
}
HashMethodKind::KeysU512(s) => {
let blocks = s
.group_by(block, column_names)?
.iter()
.map(|(_, _, b)| b.clone())
.collect();
blocks
}
})
}
}
28 changes: 21 additions & 7 deletions common/datablocks/src/kernels/data_block_group_by_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use std::ops::Not;
use common_datavalues::prelude::*;
use common_exception::Result;
use common_io::prelude::FormatSettings;
use primitive_types::U256;
use primitive_types::U512;

use crate::DataBlock;

Expand Down Expand Up @@ -126,6 +128,9 @@ pub type HashMethodKeysU8 = HashMethodFixedKeys<u8>;
pub type HashMethodKeysU16 = HashMethodFixedKeys<u16>;
pub type HashMethodKeysU32 = HashMethodFixedKeys<u32>;
pub type HashMethodKeysU64 = HashMethodFixedKeys<u64>;
pub type HashMethodKeysU128 = HashMethodFixedKeys<u128>;
pub type HashMethodKeysU256 = HashMethodFixedKeys<U256>;
pub type HashMethodKeysU512 = HashMethodFixedKeys<U512>;

/// These methods are `generic` method to generate hash key,
/// that is the 'numeric' or 'binary` representation of each column value as hash key.
Expand All @@ -136,6 +141,9 @@ pub enum HashMethodKind {
KeysU16(HashMethodKeysU16),
KeysU32(HashMethodKeysU32),
KeysU64(HashMethodKeysU64),
KeysU128(HashMethodKeysU128),
KeysU256(HashMethodKeysU256),
KeysU512(HashMethodKeysU512),
}

impl HashMethodKind {
Expand All @@ -147,6 +155,9 @@ impl HashMethodKind {
HashMethodKind::KeysU16(v) => v.name(),
HashMethodKind::KeysU32(v) => v.name(),
HashMethodKind::KeysU64(v) => v.name(),
HashMethodKind::KeysU128(v) => v.name(),
HashMethodKind::KeysU256(v) => v.name(),
HashMethodKind::KeysU512(v) => v.name(),
}
}
pub fn data_type(&self) -> DataTypeImpl {
Expand All @@ -157,6 +168,9 @@ impl HashMethodKind {
HashMethodKind::KeysU16(_) => u16::to_data_type(),
HashMethodKind::KeysU32(_) => u32::to_data_type(),
HashMethodKind::KeysU64(_) => u64::to_data_type(),
HashMethodKind::KeysU128(_) => Vu8::to_data_type(),
HashMethodKind::KeysU256(_) => Vu8::to_data_type(),
HashMethodKind::KeysU512(_) => Vu8::to_data_type(),
}
}
}
Expand Down Expand Up @@ -274,14 +288,16 @@ pub struct HashMethodFixedKeys<T> {
impl<T> HashMethodFixedKeys<T>
where T: PrimitiveType
{
pub fn default() -> Self {
HashMethodFixedKeys { t: PhantomData }
}

#[inline]
pub fn get_key(&self, column: &PrimitiveColumn<T>, row: usize) -> T {
unsafe { column.value_unchecked(row) }
}
}

impl<T> HashMethodFixedKeys<T> {
pub fn default() -> Self {
HashMethodFixedKeys { t: PhantomData }
}

pub fn deserialize_group_columns(
&self,
Expand Down Expand Up @@ -375,9 +391,7 @@ where T: PrimitiveType
}

impl<T> HashMethod for HashMethodFixedKeys<T>
where
T: PrimitiveType,
T: std::cmp::Eq + Hash + Clone + Debug,
where T: std::cmp::Eq + Hash + Clone + Debug + Default + 'static
{
type HashKey<'a> = T;

Expand Down
1 change: 1 addition & 0 deletions common/datavalues/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ common-base = { path = "../base" }
common-exception = { path = "../exception" }
common-io = { path = "../io" }
common-macros = { path = "../macros" }
primitive-types = "0.6.1"

# Github dependencies
opensrv-clickhouse = { git = "https://github.com/datafuselabs/opensrv", rev = "15786d3", package = "opensrv-clickhouse" }
Expand Down
Loading