Skip to main content

harmos_domain/model/storage/query/transform/
aggregate.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14/* === Imports === */
15
16// Standard Library Imports
17
18// Third Party Imports
19
20// Local Imports
21use crate::model::storage::codec::{Nested, Repeated, Text, product};
22
23use super::FieldPath;
24use super::project::Projection;
25use crate::MemorySize;
26
27/* === Constants === */
28
29/* === Macros === */
30
31product!(Aggregate { groups: Repeated<Projection> => 1, measures: Repeated<Measure> => 2 });
32product!(Measure { field: Nested<FieldPath> => 1, statistic: Nested<crate::Aggregate> => 2, name: Text => 3 });
33
34/* === Type Aliases === */
35
36/* === Structs === */
37
38#[derive(Clone, Debug)]
39pub struct Aggregate {
40    pub groups: Vec<Projection>,
41    pub measures: Vec<Measure>,
42}
43#[derive(Clone, Debug)]
44pub struct Measure {
45    pub field: FieldPath,
46    pub statistic: crate::Aggregate,
47    pub name: String,
48}
49
50/* === Enums === */
51
52/* === Traits === */
53
54/* === Implementations === */
55
56impl MemorySize for Aggregate {
57    fn memory_size(&self) -> usize {
58        std::mem::size_of::<Self>()
59            + self.groups.memory_size().saturating_sub(std::mem::size_of_val(&self.groups))
60            + self.measures.memory_size().saturating_sub(std::mem::size_of_val(&self.measures))
61    }
62}
63impl MemorySize for Measure {
64    fn memory_size(&self) -> usize {
65        std::mem::size_of::<Self>() + self.field.memory_size().saturating_sub(std::mem::size_of_val(&self.field)) + self.name.capacity()
66    }
67}
68
69/* === Public Functions === */
70
71/* === Private Functions === */
72
73/* === Tests === */