Skip to content

Commit

Permalink
sql: rename Aggregation node to Aggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Jul 11, 2024
1 parent 5bdd8e3 commit ca6cad1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/sql/execution/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn execute_plan(
/// TODO: since iterators are lazy, make this infallible if possible.
pub fn execute(node: Node, txn: &impl Transaction) -> Result<Rows> {
match node {
Node::Aggregation { source, aggregates, group_by } => {
Node::Aggregate { source, aggregates, group_by } => {
let source = execute(*source, txn)?;
aggregate::aggregate(source, aggregates, group_by)
}
Expand Down
16 changes: 8 additions & 8 deletions src/sql/planner/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ impl Plan {
/// A query plan node. These return row iterators and can be nested.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Node {
/// Computes aggregate values for the given expressions and group_by
/// buckets across all rows in the source nod3.
Aggregation { source: Box<Node>, aggregates: Vec<Aggregate>, group_by: Vec<Expression> },
/// Computes aggregate values for the given expressions and group_by buckets
/// across all rows in the source node.
Aggregate { source: Box<Node>, aggregates: Vec<Aggregate>, group_by: Vec<Expression> },
/// Filters source rows, by only emitting rows for which the predicate
/// evaluates to true.
Filter { source: Box<Node>, predicate: Expression },
Expand Down Expand Up @@ -161,8 +161,8 @@ impl Node {

self = before(self)?;
self = match self {
Self::Aggregation { source, aggregates, group_by } => {
Self::Aggregation { source: transform(source)?, aggregates, group_by }
Self::Aggregate { source, aggregates, group_by } => {
Self::Aggregate { source: transform(source)?, aggregates, group_by }
}
Self::Filter { source, predicate } => {
Self::Filter { source: transform(source)?, predicate }
Expand Down Expand Up @@ -265,7 +265,7 @@ impl Node {
.collect::<Result<_>>()?,
},

node @ (Self::Aggregation { .. }
node @ (Self::Aggregate { .. }
| Self::HashJoin { .. }
| Self::IndexLookup { .. }
| Self::KeyLookup { .. }
Expand Down Expand Up @@ -339,8 +339,8 @@ impl Node {

// Format the node.
match self {
Self::Aggregation { source, aggregates, group_by } => {
write!(f, "Aggregation: {}", aggregates.iter().join(", "))?;
Self::Aggregate { source, aggregates, group_by } => {
write!(f, "Aggregate: {}", aggregates.iter().join(", "))?;
if !group_by.is_empty() {
write!(f, " group by {}", group_by.iter().join(", "))?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sql/planner/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl<'a, C: Catalog> Planner<'a, C> {
group_by.push(expr);
labels.push(Label::maybe_name(label));
}
let node = Node::Aggregation { source: Box::new(source), group_by, aggregates };
let node = Node::Aggregate { source: Box::new(source), group_by, aggregates };
*scope = scope.project(&expressions, &labels)?;
Ok(node)
}
Expand Down
36 changes: 18 additions & 18 deletions src/sql/testscripts/queries/aggregate
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ok
[plan]> SELECT COUNT(*) FROM test
---
Projection: #0
└─ Aggregation: count(TRUE)
└─ Aggregate: count(TRUE)
└─ Scan: test
6

Expand All @@ -30,7 +30,7 @@ Projection: #0
[plan,header]> SELECT COUNT(NULL), COUNT(TRUE), COUNT(1), COUNT(3.14), COUNT(NAN), COUNT('')
---
Projection: #0, #1, #2, #3, #4, #5
└─ Aggregation: count(NULL), count(TRUE), count(1), count(3.14), count(NaN), count()
└─ Aggregate: count(NULL), count(TRUE), count(1), count(3.14), count(NaN), count()
└─ EmptyRow
, , , , ,
0, 1, 1, 1, 1, 1
Expand All @@ -39,7 +39,7 @@ Projection: #0, #1, #2, #3, #4, #5
[plan]> SELECT COUNT(id), COUNT("bool"), COUNT("float"), COUNT("string") FROM test WHERE false
---
Projection: #0, #1, #2, #3
└─ Aggregation: count(id), count(bool), count(float), count(string)
└─ Aggregate: count(id), count(bool), count(float), count(string)
└─ Nothing
0, 0, 0, 0

Expand All @@ -48,7 +48,7 @@ Projection: #0, #1, #2, #3
[plan,header]> SELECT COUNT(id), COUNT("bool"), COUNT("float"), COUNT("string") FROM test
---
Projection: #0, #1, #2, #3
└─ Aggregation: count(id), count(bool), count(float), count(string)
└─ Aggregate: count(id), count(bool), count(float), count(string)
└─ Scan: test
, , ,
6, 3, 5, 4
Expand All @@ -57,23 +57,23 @@ Projection: #0, #1, #2, #3
[plan]> SELECT MAX(NULL), MAX(TRUE), MAX(1), MAX(3.14), MAX(NAN), MAX('foo') FROM test
---
Projection: #0, #1, #2, #3, #4, #5
└─ Aggregation: max(NULL), max(TRUE), max(1), max(3.14), max(NaN), max(foo)
└─ Aggregate: max(NULL), max(TRUE), max(1), max(3.14), max(NaN), max(foo)
└─ Scan: test
NULL, TRUE, 1, 3.14, NaN, foo

# MAX works on no rows.
[plan]> SELECT MAX(id), MAX("bool"), MAX("float"), MAX("string") FROM test WHERE false
---
Projection: #0, #1, #2, #3
└─ Aggregation: max(id), max(bool), max(float), max(string)
└─ Aggregate: max(id), max(bool), max(float), max(string)
└─ Nothing
NULL, NULL, NULL, NULL

# MAX returns the max value, or NULL if any value is NULL.
[plan]> SELECT MAX(id) FROM test
---
Projection: #0
└─ Aggregation: max(id)
└─ Aggregate: max(id)
└─ Scan: test
5

Expand Down Expand Up @@ -107,23 +107,23 @@ NULL
[plan]> SELECT MIN(NULL), MIN(TRUE), MIN(1), MIN(3.14), MIN(NAN), MIN('foo') FROM test
---
Projection: #0, #1, #2, #3, #4, #5
└─ Aggregation: min(NULL), min(TRUE), min(1), min(3.14), min(NaN), min(foo)
└─ Aggregate: min(NULL), min(TRUE), min(1), min(3.14), min(NaN), min(foo)
└─ Scan: test
NULL, TRUE, 1, 3.14, NaN, foo

# MIN works on no rows.
[plan]> SELECT MIN(id), MIN("bool"), MIN("float"), MIN("string") FROM test WHERE false
---
Projection: #0, #1, #2, #3
└─ Aggregation: min(id), min(bool), min(float), min(string)
└─ Aggregate: min(id), min(bool), min(float), min(string)
└─ Nothing
NULL, NULL, NULL, NULL

# MIN returns the min value, or NULL if any value is NULL.
[plan]> SELECT MIN(id) FROM test
---
Projection: #0
└─ Aggregation: min(id)
└─ Aggregate: min(id)
└─ Scan: test
0

Expand Down Expand Up @@ -155,7 +155,7 @@ NULL
[plan]> SELECT SUM(NULL), SUM(1), SUM(3.14), SUM(NAN) FROM test
---
Projection: #0, #1, #2, #3
└─ Aggregation: sum(NULL), sum(1), sum(3.14), sum(NaN)
└─ Aggregate: sum(NULL), sum(1), sum(3.14), sum(NaN)
└─ Scan: test
NULL, 6, 18.84, NaN

Expand All @@ -169,7 +169,7 @@ Error: invalid input: can't add 0 and foo
[plan]> SELECT SUM(id), SUM("bool"), SUM("float"), SUM("string") FROM test WHERE false
---
Projection: #0, #1, #2, #3
└─ Aggregation: sum(id), sum(bool), sum(float), sum(string)
└─ Aggregate: sum(id), sum(bool), sum(float), sum(string)
└─ Nothing
NULL, NULL, NULL, NULL

Expand All @@ -178,7 +178,7 @@ NULL, NULL, NULL, NULL
[plan]> SELECT SUM(id) FROM test
---
Projection: #0
└─ Aggregation: sum(id)
└─ Aggregate: sum(id)
└─ Scan: test
15

Expand Down Expand Up @@ -216,7 +216,7 @@ NULL
[plan]> SELECT AVG(NULL), AVG(1), AVG(3.14), AVG(NAN) FROM test
---
Projection: #0, #1, #2, #3
└─ Aggregation: avg(NULL), avg(1), avg(3.14), avg(NaN)
└─ Aggregate: avg(NULL), avg(1), avg(3.14), avg(NaN)
└─ Scan: test
NULL, 1, 3.14, NaN

Expand All @@ -230,7 +230,7 @@ Error: invalid input: can't add 0 and foo
[plan]> SELECT AVG(id), AVG("bool"), AVG("float"), AVG("string") FROM test WHERE false
---
Projection: #0, #1, #2, #3
└─ Aggregation: avg(id), avg(bool), avg(float), avg(string)
└─ Aggregate: avg(id), avg(bool), avg(float), avg(string)
└─ Nothing
NULL, NULL, NULL, NULL

Expand All @@ -239,7 +239,7 @@ NULL, NULL, NULL, NULL
[plan]> SELECT AVG(id) FROM test
---
Projection: #0
└─ Aggregation: avg(id)
└─ Aggregate: avg(id)
└─ Scan: test
2

Expand Down Expand Up @@ -279,7 +279,7 @@ NULL
[plan]> SELECT COUNT(1), MIN(1), MAX(1), SUM(1), AVG(1) FROM test
---
Projection: #0, #1, #2, #3, #4
└─ Aggregation: count(1), min(1), max(1), sum(1), avg(1)
└─ Aggregate: count(1), min(1), max(1), sum(1), avg(1)
└─ Scan: test
6, 1, 1, 6, 1

Expand All @@ -296,7 +296,7 @@ Error: invalid input: unknown field id
[plan]> SELECT SUM("int" * 10) / COUNT("int") + 7 FROM test WHERE "int" IS NOT NULL
---
Projection: #0 / #1 + 7
└─ Aggregation: sum(int * 10), count(int)
└─ Aggregate: sum(int * 10), count(int)
└─ Scan: test (NOT int IS NULL)
117

Expand Down
36 changes: 18 additions & 18 deletions src/sql/testscripts/queries/group_by
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ ok
[plan]> SELECT COUNT(id), MIN(id), MAX(id), SUM(id), AVG(id) FROM test WHERE FALSE GROUP BY id
---
Projection: #0, #1, #2, #3, #4
└─ Aggregation: count(id), min(id), max(id), sum(id), avg(id) group by id
└─ Aggregate: count(id), min(id), max(id), sum(id), avg(id) group by id
└─ Nothing

# Simple GROUP BY.
[plan]> SELECT "group", COUNT(*) FROM test GROUP BY "group"
---
Projection: test.group, #0
└─ Aggregation: count(TRUE) group by group
└─ Aggregate: count(TRUE) group by group
└─ Scan: test
NULL, 1
a, 3
Expand All @@ -42,7 +42,7 @@ b, 3
FROM test WHERE id != 0 GROUP BY "group"
---
Projection: test.group, #0, #1, #2, #3, #4
└─ Aggregation: count(TRUE), min(bool), max(string), sum(int), avg(float) group by group
└─ Aggregate: count(TRUE), min(bool), max(string), sum(int), avg(float) group by group
└─ Scan: test (NOT id = 0)
a, 3, FALSE, AB, 9, NaN
b, 3, FALSE, 👋, 41, NaN
Expand All @@ -51,7 +51,7 @@ b, 3, FALSE, 👋, 41, NaN
[plan]> SELECT "group", COUNT(*) FROM test GROUP BY "group"
---
Projection: test.group, #0
└─ Aggregation: count(TRUE) group by group
└─ Aggregate: count(TRUE) group by group
└─ Scan: test
NULL, 1
a, 3
Expand All @@ -61,7 +61,7 @@ b, 3
[plan]> SELECT "bool", COUNT(*) FROM test WHERE id != 0 GROUP BY "bool"
---
Projection: test.bool, #0
└─ Aggregation: count(TRUE) group by bool
└─ Aggregate: count(TRUE) group by bool
└─ Scan: test (NOT id = 0)
FALSE, 3
TRUE, 3
Expand All @@ -70,7 +70,7 @@ TRUE, 3
[plan]> SELECT "int", COUNT(*) FROM test WHERE id != 0 GROUP BY "int"
---
Projection: test.int, #0
└─ Aggregation: count(TRUE) group by int
└─ Aggregate: count(TRUE) group by int
└─ Scan: test (NOT id = 0)
-1, 2
0, 1
Expand All @@ -82,7 +82,7 @@ Projection: test.int, #0
[plan]> SELECT "float", COUNT(*) FROM test WHERE id != 0 GROUP BY "float"
---
Projection: test.float, #0
└─ Aggregation: count(TRUE) group by float
└─ Aggregate: count(TRUE) group by float
└─ Scan: test (NOT id = 0)
0, 2
3.14, 1
Expand All @@ -93,7 +93,7 @@ NaN, 2
[plan]> SELECT "string", COUNT(*) FROM test WHERE id != 0 GROUP BY "string"
---
Projection: test.string, #0
└─ Aggregation: count(TRUE) group by string
└─ Aggregate: count(TRUE) group by string
└─ Scan: test (NOT id = 0)
, 2
AB, 1
Expand All @@ -104,7 +104,7 @@ abc, 2
[plan]> SELECT COUNT(*) FROM test WHERE id != 0 GROUP BY "group"
---
Projection: #0
└─ Aggregation: count(TRUE) group by group
└─ Aggregate: count(TRUE) group by group
└─ Scan: test (NOT id = 0)
3
3
Expand All @@ -113,7 +113,7 @@ Projection: #0
[plan]> SELECT "group" FROM test WHERE id != 0 GROUP BY "group"
---
Projection: test.group
└─ Aggregation: group by group
└─ Aggregate: group by group
└─ Scan: test (NOT id = 0)
a
b
Expand All @@ -122,7 +122,7 @@ b
[plan]> SELECT "group" AS g, COUNT(*) FROM test GROUP BY g
---
Projection: g, #0
└─ Aggregation: count(TRUE) group by group
└─ Aggregate: count(TRUE) group by group
└─ Scan: test
NULL, 1
a, 3
Expand All @@ -131,7 +131,7 @@ b, 3
[plan]> SELECT "group", COUNT(*) FROM test AS t GROUP BY t."group"
---
Projection: group, #0
└─ Aggregation: count(TRUE) group by t.group
└─ Aggregate: count(TRUE) group by t.group
└─ Scan: test as t
NULL, 1
a, 3
Expand All @@ -158,14 +158,14 @@ Error: invalid input: unknown table unknown
[plan]> SELECT COUNT(*) FROM test GROUP BY 1
---
Projection: #0
└─ Aggregation: count(TRUE) group by 1
└─ Aggregate: count(TRUE) group by 1
└─ Scan: test
7

[plan]> SELECT COUNT(*) FROM test GROUP BY id % 2
---
Projection: #0
└─ Aggregation: count(TRUE) group by id % 2
└─ Aggregate: count(TRUE) group by id % 2
└─ Scan: test
4
3
Expand All @@ -174,7 +174,7 @@ Projection: #0
[plan]> SELECT id % 2, COUNT(*) FROM test GROUP BY id % 2
---
Projection: #1, #0
└─ Aggregation: count(TRUE) group by id % 2
└─ Aggregate: count(TRUE) group by id % 2
└─ Scan: test
0, 4
1, 3
Expand All @@ -183,7 +183,7 @@ Projection: #1, #0
[plan]> SELECT id % 2 AS mod, COUNT(*) FROM test GROUP BY mod
---
Projection: mod, #0
└─ Aggregation: count(TRUE) group by id % 2
└─ Aggregate: count(TRUE) group by id % 2
└─ Scan: test
0, 4
1, 3
Expand All @@ -197,7 +197,7 @@ Error: invalid input: group expression cannot contain aggregates
[plan]> SELECT "group", "bool", COUNT(*) FROM test WHERE id != 0 GROUP BY "group", "bool"
---
Projection: test.group, test.bool, #0
└─ Aggregation: count(TRUE) group by group, bool
└─ Aggregate: count(TRUE) group by group, bool
└─ Scan: test (NOT id = 0)
a, FALSE, 1
a, TRUE, 2
Expand All @@ -208,7 +208,7 @@ b, TRUE, 1
[plan]> SELECT t.id % 2, COUNT(*) FROM test t JOIN other o ON t.id % 2 = o.id GROUP BY t.id % 2
---
Projection: #1, #0
└─ Aggregation: count(TRUE) group by t.id % 2
└─ Aggregate: count(TRUE) group by t.id % 2
└─ NestedLoopJoin: inner on t.id % 2 = o.id
├─ Scan: test as t
└─ Scan: other as o
Expand Down
Loading

0 comments on commit ca6cad1

Please sign in to comment.