axion_data/dataframe/
types.rs

1use std::hash::{Hash, Hasher};
2use std::fmt::Debug;
3
4/// 表示分组键中的单个值
5/// 
6/// 在 GroupBy 操作中用于构建分组键,支持常用的可哈希和可比较的数据类型。
7/// 
8/// # 支持的类型
9/// 
10/// - `Int` - 32位整数
11/// - `Str` - 字符串
12/// - `Bool` - 布尔值
13/// 
14/// # 示例
15/// 
16/// ```rust
17/// use axion::dataframe::types::GroupKeyValue;
18/// 
19/// let key1 = GroupKeyValue::Int(42);
20/// let key2 = GroupKeyValue::Str("category".to_string());
21/// let key3 = GroupKeyValue::Bool(true);
22/// ```
23#[derive(PartialEq, Eq, Clone, Debug)]
24pub enum GroupKeyValue {
25    Int(i32),
26    Str(String),
27    Bool(bool),
28}
29
30impl Hash for GroupKeyValue {
31    fn hash<H: Hasher>(&self, state: &mut H) {
32        std::mem::discriminant(self).hash(state);
33        match self {
34            GroupKeyValue::Int(i) => i.hash(state),
35            GroupKeyValue::Str(s) => s.hash(state),
36            GroupKeyValue::Bool(b) => b.hash(state),
37        }
38    }
39}
40
41/// 复合分组键类型
42/// 
43/// 当按多列分组时,使用此类型表示组合键。
44/// 每个 `GroupKey` 是一个 `GroupKeyValue` 的向量,
45/// 按分组列的顺序排列。
46/// 
47/// # 示例
48/// 
49/// ```rust
50/// use axion::dataframe::types::{GroupKey, GroupKeyValue};
51/// 
52/// // 按 "类别" 和 "状态" 两列分组的键
53/// let group_key: GroupKey = vec![
54///     GroupKeyValue::Str("A类".to_string()),
55///     GroupKeyValue::Bool(true),
56/// ];
57/// ```
58pub type GroupKey = Vec<GroupKeyValue>;