• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

flowlight0 / simpledb-rs / #120

21 Jun 2025 03:35PM UTC coverage: 78.998% (+0.2%) from 78.816%
#120

push

web-flow
Implement GROUP BY clause support (#128)

* fix planner order for group by

* Add GROUP BY tests for query planners

* Support AS alias for aggregation functions

* refactor: handle aggregation aliases via ExtendPlan

* Update grammar.rs

20 of 27 new or added lines in 3 files covered. (74.07%)

6 existing lines in 1 file now uncovered.

2979 of 3771 relevant lines covered (79.0%)

1.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.89
/src/parser/statement.rs
1
use crate::record::field::{Spec, Value};
2

3
use super::{expression::Expression, predicate::Predicate};
4
use crate::materialization::aggregation_function::AggregationFn;
5

6
#[derive(Debug, PartialEq, Eq)]
7
pub enum Statement {
8
    Query(QueryData),
9
    UpdateCommand(UpdateCommand),
10
}
11

12
#[derive(Debug, PartialEq, Eq)]
13
pub enum SelectField {
14
    Expression(Expression, Option<String>),
15
    Aggregation(AggregationFn, Option<String>),
16
}
17

18
#[derive(Debug, PartialEq, Eq)]
19
pub struct QueryData {
20
    pub fields: Option<Vec<String>>, // None means all fields
21
    pub tables: Vec<String>,
22
    pub predicate: Option<Predicate>,
23
    pub group_by: Option<Vec<String>>, // None means no grouping
24
    pub order_by: Option<Vec<String>>, // None means no ordering
25
    pub extend_fields: Vec<(Expression, String)>,
26
    pub aggregation_functions: Vec<AggregationFn>,
27
}
28

29
impl QueryData {
30
    pub fn new_full(
3✔
31
        fields: Option<Vec<String>>,
32
        tables: Vec<String>,
33
        predicate: Option<Predicate>,
34
        group_by: Option<Vec<String>>,
35
        order_by: Option<Vec<String>>,
36
        extend_fields: Vec<(Expression, String)>,
37
        aggregation_functions: Vec<AggregationFn>,
38
    ) -> Self {
39
        QueryData {
40
            fields,
41
            tables,
42
            predicate,
43
            group_by,
44
            order_by,
45
            extend_fields,
46
            aggregation_functions,
47
        }
48
    }
49

50
    pub fn new(fields: Vec<String>, tables: Vec<String>, predicate: Option<Predicate>) -> Self {
1✔
51
        QueryData::new_with_order_and_extend(fields, tables, predicate, None, vec![])
1✔
52
    }
53

54
    pub fn new_all(tables: Vec<String>, predicate: Option<Predicate>) -> Self {
1✔
55
        QueryData::new_all_with_order(tables, predicate, None)
1✔
56
    }
57

58
    pub fn new_with_order(
×
59
        fields: Vec<String>,
60
        tables: Vec<String>,
61
        predicate: Option<Predicate>,
62
        order_by: Option<Vec<String>>,
63
    ) -> Self {
64
        QueryData::new_full(
NEW
65
            Some(fields),
×
UNCOV
66
            tables,
×
UNCOV
67
            predicate,
×
NEW
68
            None,
×
69
            order_by,
×
NEW
70
            Vec::new(),
×
NEW
71
            Vec::new(),
×
72
        )
73
    }
74

75
    pub fn new_all_with_order(
1✔
76
        tables: Vec<String>,
77
        predicate: Option<Predicate>,
78
        order_by: Option<Vec<String>>,
79
    ) -> Self {
80
        QueryData::new_full(
81
            None,
1✔
82
            tables,
1✔
83
            predicate,
1✔
84
            None,
1✔
85
            order_by,
1✔
86
            Vec::new(),
1✔
87
            Vec::new(),
1✔
88
        )
89
    }
90

91
    pub fn new_with_order_and_extend(
1✔
92
        fields: Vec<String>,
93
        tables: Vec<String>,
94
        predicate: Option<Predicate>,
95
        order_by: Option<Vec<String>>,
96
        extend_fields: Vec<(Expression, String)>,
97
    ) -> Self {
98
        QueryData::new_full(
99
            Some(fields),
1✔
100
            tables,
1✔
101
            predicate,
1✔
102
            None,
1✔
103
            order_by,
1✔
104
            extend_fields,
1✔
105
            Vec::new(),
1✔
106
        )
107
    }
108

109
    pub fn new_all_with_order_and_extend(
×
110
        tables: Vec<String>,
111
        predicate: Option<Predicate>,
112
        order_by: Option<Vec<String>>,
113
        extend_fields: Vec<(Expression, String)>,
114
    ) -> Self {
115
        QueryData::new_full(
NEW
116
            None,
×
UNCOV
117
            tables,
×
UNCOV
118
            predicate,
×
NEW
119
            None,
×
UNCOV
120
            order_by,
×
UNCOV
121
            extend_fields,
×
NEW
122
            Vec::new(),
×
123
        )
124
    }
125
}
126

127
#[derive(Debug, PartialEq, Eq)]
128
pub enum UpdateCommand {
129
    Insert(String, Vec<String>, Vec<Value>),
130
    Delete(String, Option<Predicate>),
131
    Modify(String, String, Expression, Option<Predicate>),
132
    Create(CreateCommand),
133
}
134

135
#[derive(Debug, PartialEq, Eq)]
136
pub enum CreateCommand {
137
    Table(String, Vec<FieldDefinition>),
138
    View(String, QueryData),
139
    Index(String, String, String),
140
}
141

142
#[derive(Debug, PartialEq, Eq)]
143
pub struct FieldDefinition {
144
    pub name: String,
145
    pub field_type: Spec,
146
}
147

148
impl FieldDefinition {
149
    pub fn new(name: String, field_type: Spec) -> Self {
3✔
150
        FieldDefinition { name, field_type }
151
    }
152
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc