From 29137207f945bfbe51107610de0dea4160626671 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Thu, 11 Jul 2024 15:19:44 +0200 Subject: [PATCH] sql: rename `Aggregation` node to `Aggregate` --- src/sql/execution/execute.rs | 2 +- src/sql/planner/plan.rs | 16 ++++++------ src/sql/planner/planner.rs | 2 +- src/sql/testscripts/queries/aggregate | 36 +++++++++++++-------------- src/sql/testscripts/queries/group_by | 36 +++++++++++++-------------- src/sql/testscripts/queries/having | 8 +++--- 6 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/sql/execution/execute.rs b/src/sql/execution/execute.rs index c385fbdbd..7e8ceb45b 100644 --- a/src/sql/execution/execute.rs +++ b/src/sql/execution/execute.rs @@ -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 { 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) } diff --git a/src/sql/planner/plan.rs b/src/sql/planner/plan.rs index df33a0c2a..00f790f81 100644 --- a/src/sql/planner/plan.rs +++ b/src/sql/planner/plan.rs @@ -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, aggregates: Vec, group_by: Vec }, + /// Computes aggregate values for the given expressions and group_by buckets + /// across all rows in the source node. + Aggregate { source: Box, aggregates: Vec, group_by: Vec }, /// Filters source rows, by only emitting rows for which the predicate /// evaluates to true. Filter { source: Box, predicate: Expression }, @@ -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 } @@ -265,7 +265,7 @@ impl Node { .collect::>()?, }, - node @ (Self::Aggregation { .. } + node @ (Self::Aggregate { .. } | Self::HashJoin { .. } | Self::IndexLookup { .. } | Self::KeyLookup { .. } @@ -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(", "))?; } diff --git a/src/sql/planner/planner.rs b/src/sql/planner/planner.rs index 468e6c41f..a6d2c3fb9 100644 --- a/src/sql/planner/planner.rs +++ b/src/sql/planner/planner.rs @@ -371,7 +371,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) } diff --git a/src/sql/testscripts/queries/aggregate b/src/sql/testscripts/queries/aggregate index be7d000df..9f3725b87 100644 --- a/src/sql/testscripts/queries/aggregate +++ b/src/sql/testscripts/queries/aggregate @@ -21,7 +21,7 @@ ok [plan]> SELECT COUNT(*) FROM test --- Projection: #0 -└─ Aggregation: count(TRUE) +└─ Aggregate: count(TRUE) └─ Scan: test 6 @@ -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 @@ -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 @@ -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 @@ -57,7 +57,7 @@ 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 @@ -65,7 +65,7 @@ NULL, TRUE, 1, 3.14, NaN, foo [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 @@ -73,7 +73,7 @@ NULL, NULL, NULL, NULL [plan]> SELECT MAX(id) FROM test --- Projection: #0 -└─ Aggregation: max(id) +└─ Aggregate: max(id) └─ Scan: test 5 @@ -107,7 +107,7 @@ 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 @@ -115,7 +115,7 @@ NULL, TRUE, 1, 3.14, NaN, foo [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 @@ -123,7 +123,7 @@ NULL, NULL, NULL, NULL [plan]> SELECT MIN(id) FROM test --- Projection: #0 -└─ Aggregation: min(id) +└─ Aggregate: min(id) └─ Scan: test 0 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/sql/testscripts/queries/group_by b/src/sql/testscripts/queries/group_by index e3c89e07c..6576c0388 100644 --- a/src/sql/testscripts/queries/group_by +++ b/src/sql/testscripts/queries/group_by @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/sql/testscripts/queries/having b/src/sql/testscripts/queries/having index 0761bc213..82665b9d8 100644 --- a/src/sql/testscripts/queries/having +++ b/src/sql/testscripts/queries/having @@ -46,7 +46,7 @@ Projection: #0 Projection: #0, #1 └─ Filter: #2 > 10 └─ Projection: test.group, #0, #1 - └─ Aggregation: max(int), max(int) group by group + └─ Aggregate: max(int), max(int) group by group └─ Scan: test b, 42 @@ -55,7 +55,7 @@ b, 42 --- Filter: m > 10 └─ Projection: test.group, #0 - └─ Aggregation: max(int) group by group + └─ Aggregate: max(int) group by group └─ Scan: test b, 42 @@ -65,7 +65,7 @@ b, 42 Projection: #0, #1 └─ Filter: #2 > 10 └─ Projection: test.group, #0, #1 - └─ Aggregation: count(TRUE), max(int) group by group + └─ Aggregate: count(TRUE), max(int) group by group └─ Scan: test b, 3 @@ -75,7 +75,7 @@ b, 3 Projection: #0, #1 └─ Filter: #2 / #3 > 3 └─ Projection: test.group, #0, #1, #2 - └─ Aggregation: count(TRUE), max(int), count(TRUE) group by group + └─ Aggregate: count(TRUE), max(int), count(TRUE) group by group └─ Scan: test b, 3