Skip to main content

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

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