Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAX -> max, MIN -> min
Browse files Browse the repository at this point in the history
edmondop committed Aug 3, 2024
1 parent 0c96042 commit cdcda3f
Showing 24 changed files with 257 additions and 593 deletions.
2 changes: 1 addition & 1 deletion datafusion/core/src/dataframe/mod.rs
Original file line number Diff line number Diff line change
@@ -2060,7 +2060,7 @@ mod tests {

assert_batches_sorted_eq!(
["+----+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-------------------------------+----------------------------------------+",
"| c1 | MIN(aggregate_test_100.c12) | MAX(aggregate_test_100.c12) | avg(aggregate_test_100.c12) | sum(aggregate_test_100.c12) | count(aggregate_test_100.c12) | count(DISTINCT aggregate_test_100.c12) |",
"| c1 | min(aggregate_test_100.c12) | max(aggregate_test_100.c12) | avg(aggregate_test_100.c12) | sum(aggregate_test_100.c12) | count(aggregate_test_100.c12) | count(DISTINCT aggregate_test_100.c12) |",
"+----+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-------------------------------+----------------------------------------+",
"| a | 0.02182578039211991 | 0.9800193410444061 | 0.48754517466109415 | 10.238448667882977 | 21 | 21 |",
"| b | 0.04893135681998029 | 0.9185813970744787 | 0.41040709263815384 | 7.797734760124923 | 19 | 19 |",
6 changes: 3 additions & 3 deletions datafusion/core/src/execution/context/mod.rs
Original file line number Diff line number Diff line change
@@ -159,7 +159,7 @@ where
/// assert_batches_eq!(
/// &[
/// "+---+----------------+",
/// "| a | MIN(?table?.b) |",
/// "| a | min(?table?.b) |",
/// "+---+----------------+",
/// "| 1 | 2 |",
/// "+---+----------------+",
@@ -182,14 +182,14 @@ where
/// let mut ctx = SessionContext::new();
/// ctx.register_csv("example", "tests/data/example.csv", CsvReadOptions::new()).await?;
/// let results = ctx
/// .sql("SELECT a, MIN(b) FROM example GROUP BY a LIMIT 100")
/// .sql("SELECT a, min(b) FROM example GROUP BY a LIMIT 100")
/// .await?
/// .collect()
/// .await?;
/// assert_batches_eq!(
/// &[
/// "+---+----------------+",
/// "| a | MIN(example.b) |",
/// "| a | min(example.b) |",
/// "+---+----------------+",
/// "| 1 | 2 |",
/// "+---+----------------+",
2 changes: 1 addition & 1 deletion datafusion/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@
//!
//! let expected = vec![
//! "+---+----------------+",
//! "| a | MIN(example.b) |",
//! "| a | min(example.b) |",
//! "+---+----------------+",
//! "| 1 | 2 |",
//! "+---+----------------+"
4 changes: 2 additions & 2 deletions datafusion/core/tests/custom_sources_cases/mod.rs
Original file line number Diff line number Diff line change
@@ -284,8 +284,8 @@ async fn optimizers_catch_all_statistics() {
let expected = RecordBatch::try_new(
Arc::new(Schema::new(vec![
Field::new("count(*)", DataType::Int64, false),
Field::new("MIN(test.c1)", DataType::Int32, false),
Field::new("MAX(test.c1)", DataType::Int32, false),
Field::new("min(test.c1)", DataType::Int32, false),
Field::new("max(test.c1)", DataType::Int32, false),
])),
vec![
Arc::new(Int64Array::from(vec![4])),
6 changes: 3 additions & 3 deletions datafusion/core/tests/expr_api/parse_sql_expr.rs
Original file line number Diff line number Diff line change
@@ -49,9 +49,9 @@ async fn round_trip_parse_sql_expr() -> Result<()> {
"((a = 10) AND b NOT IN (20, 30))",
"sum(a)",
"(sum(a) + 1)",
"(MIN(a) + MAX(b))",
"(MIN(a) + (MAX(b) * sum(c)))",
"(MIN(a) + ((MAX(b) * sum(c)) / 10))",
"(min(a) + max(b))",
"(min(a) + (max(b) * sum(c)))",
"(min(a) + ((max(b) * sum(c)) / 10))",
];

for test in tests {
6 changes: 3 additions & 3 deletions datafusion/core/tests/sql/explain_analyze.rs
Original file line number Diff line number Diff line change
@@ -615,11 +615,11 @@ async fn test_physical_plan_display_indent() {
"GlobalLimitExec: skip=0, fetch=10",
" SortPreservingMergeExec: [the_min@2 DESC], fetch=10",
" SortExec: TopK(fetch=10), expr=[the_min@2 DESC], preserve_partitioning=[true]",
" ProjectionExec: expr=[c1@0 as c1, MAX(aggregate_test_100.c12)@1 as MAX(aggregate_test_100.c12), MIN(aggregate_test_100.c12)@2 as the_min]",
" AggregateExec: mode=FinalPartitioned, gby=[c1@0 as c1], aggr=[MAX(aggregate_test_100.c12), MIN(aggregate_test_100.c12)]",
" ProjectionExec: expr=[c1@0 as c1, max(aggregate_test_100.c12)@1 as max(aggregate_test_100.c12), min(aggregate_test_100.c12)@2 as the_min]",
" AggregateExec: mode=FinalPartitioned, gby=[c1@0 as c1], aggr=[max(aggregate_test_100.c12), min(aggregate_test_100.c12)]",
" CoalesceBatchesExec: target_batch_size=4096",
" RepartitionExec: partitioning=Hash([c1@0], 9000), input_partitions=9000",
" AggregateExec: mode=Partial, gby=[c1@0 as c1], aggr=[MAX(aggregate_test_100.c12), MIN(aggregate_test_100.c12)]",
" AggregateExec: mode=Partial, gby=[c1@0 as c1], aggr=[max(aggregate_test_100.c12), min(aggregate_test_100.c12)]",
" CoalesceBatchesExec: target_batch_size=4096",
" FilterExec: c12@1 < 10",
" RepartitionExec: partitioning=RoundRobinBatch(9000), input_partitions=1",
8 changes: 4 additions & 4 deletions datafusion/expr/src/test/function_stub.rs
Original file line number Diff line number Diff line change
@@ -326,7 +326,7 @@ impl Default for Min {
impl Min {
pub fn new() -> Self {
Self {
aliases: vec!["min".to_string()],
aliases: vec!["MIN".to_string()],
signature: Signature::variadic_any(Volatility::Immutable),
}
}
@@ -338,7 +338,7 @@ impl AggregateUDFImpl for Min {
}

fn name(&self) -> &str {
"MIN"
"min"
}

fn signature(&self) -> &Signature {
@@ -413,7 +413,7 @@ impl Default for Max {
impl Max {
pub fn new() -> Self {
Self {
aliases: vec!["max".to_string()],
aliases: vec!["MAX".to_string()],
signature: Signature::variadic_any(Volatility::Immutable),
}
}
@@ -425,7 +425,7 @@ impl AggregateUDFImpl for Max {
}

fn name(&self) -> &str {
"MAX"
"max"
}

fn signature(&self) -> &Signature {
8 changes: 4 additions & 4 deletions datafusion/functions-aggregate/src/min_max.rs
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ pub struct Max {
impl Max {
pub fn new() -> Self {
Self {
aliases: vec!["max".to_owned()],
aliases: vec!["MAX".to_owned()],
signature: Signature::user_defined(Volatility::Immutable),
}
}
@@ -146,7 +146,7 @@ impl AggregateUDFImpl for Max {
}

fn name(&self) -> &str {
"MAX"
"max"
}

fn signature(&self) -> &Signature {
@@ -898,7 +898,7 @@ impl Min {
pub fn new() -> Self {
Self {
signature: Signature::user_defined(Volatility::Immutable),
aliases: vec!["min".to_owned()],
aliases: vec!["MIN".to_owned()],
}
}
}
@@ -915,7 +915,7 @@ impl AggregateUDFImpl for Min {
}

fn name(&self) -> &str {
"MIN"
"min"
}

fn signature(&self) -> &Signature {
2 changes: 1 addition & 1 deletion datafusion/optimizer/src/analyzer/count_wildcard_rule.rs
Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ mod tests {
.build()?;

let expected = "Projection: count(Int64(1)) AS count(*) [count(*):Int64]\
\n Aggregate: groupBy=[[]], aggr=[[MAX(count(Int64(1))) AS MAX(count(*))]] [MAX(count(*)):Int64;N]\
\n Aggregate: groupBy=[[]], aggr=[[max(count(Int64(1))) AS max(count(*))]] [MAX(count(*)):Int64;N]\
\n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";
assert_plan_eq(plan, expected)
}
30 changes: 15 additions & 15 deletions datafusion/optimizer/src/optimize_projections/mod.rs
Original file line number Diff line number Diff line change
@@ -1361,7 +1361,7 @@ mod tests {
.aggregate(Vec::<Expr>::new(), vec![max(col("b"))])?
.build()?;

let expected = "Aggregate: groupBy=[[]], aggr=[[MAX(test.b)]]\
let expected = "Aggregate: groupBy=[[]], aggr=[[max(test.b)]]\
\n TableScan: test projection=[b]";

assert_optimized_plan_equal(plan, expected)
@@ -1375,7 +1375,7 @@ mod tests {
.aggregate(vec![col("c")], vec![max(col("b"))])?
.build()?;

let expected = "Aggregate: groupBy=[[test.c]], aggr=[[MAX(test.b)]]\
let expected = "Aggregate: groupBy=[[test.c]], aggr=[[max(test.b)]]\
\n TableScan: test projection=[b, c]";

assert_optimized_plan_equal(plan, expected)
@@ -1390,7 +1390,7 @@ mod tests {
.aggregate(vec![col("c")], vec![max(col("b"))])?
.build()?;

let expected = "Aggregate: groupBy=[[a.c]], aggr=[[MAX(a.b)]]\
let expected = "Aggregate: groupBy=[[a.c]], aggr=[[max(a.b)]]\
\n SubqueryAlias: a\
\n TableScan: test projection=[b, c]";

@@ -1406,7 +1406,7 @@ mod tests {
.aggregate(Vec::<Expr>::new(), vec![max(col("b"))])?
.build()?;

let expected = "Aggregate: groupBy=[[]], aggr=[[MAX(test.b)]]\
let expected = "Aggregate: groupBy=[[]], aggr=[[max(test.b)]]\
\n Projection: test.b\
\n Filter: test.c > Int32(1)\
\n TableScan: test projection=[b, c]";
@@ -1422,7 +1422,7 @@ mod tests {
// "tag.one", not a column named "one" in a table named "tag"):
//
// Projection: tag.one
// Aggregate: groupBy=[], aggr=[MAX("tag.one") AS "tag.one"]
// Aggregate: groupBy=[], aggr=[max("tag.one") AS "tag.one"]
// TableScan
let plan = table_scan(Some("m4"), &schema, None)?
.aggregate(
@@ -1433,7 +1433,7 @@ mod tests {
.build()?;

let expected = "\
Aggregate: groupBy=[[]], aggr=[[MAX(m4.tag.one) AS tag.one]]\
Aggregate: groupBy=[[]], aggr=[[max(m4.tag.one) AS tag.one]]\
\n TableScan: m4 projection=[tag.one]";

assert_optimized_plan_equal(plan, expected)
@@ -1768,11 +1768,11 @@ mod tests {
.aggregate(vec![col("c")], vec![max(col("a"))])?
.build()?;

assert_fields_eq(&plan, vec!["c", "MAX(test.a)"]);
assert_fields_eq(&plan, vec!["c", "max(test.a)"]);

let plan = optimize(plan).expect("failed to optimize plan");
let expected = "\
Aggregate: groupBy=[[test.c]], aggr=[[MAX(test.a)]]\
Aggregate: groupBy=[[test.c]], aggr=[[max(test.a)]]\
\n Filter: test.c > Int32(1)\
\n Projection: test.c, test.a\
\n TableScan: test projection=[a, c]";
@@ -1865,11 +1865,11 @@ mod tests {
.project(vec![col("c"), col("a"), col("MAX(test.b)")])?
.build()?;

assert_fields_eq(&plan, vec!["c", "a", "MAX(test.b)"]);
assert_fields_eq(&plan, vec!["c", "a", "max(test.b)"]);

let expected = "Projection: test.c, test.a, MAX(test.b)\
let expected = "Projection: test.c, test.a, max(test.b)\
\n Filter: test.c > Int32(1)\
\n Aggregate: groupBy=[[test.a, test.c]], aggr=[[MAX(test.b)]]\
\n Aggregate: groupBy=[[test.a, test.c]], aggr=[[max(test.b)]]\
\n TableScan: test projection=[a, b, c]";

assert_optimized_plan_equal(plan, expected)
@@ -1937,10 +1937,10 @@ mod tests {
.project(vec![col1, col2])?
.build()?;

let expected = "Projection: MAX(test.a) PARTITION BY [test.b] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING, MAX(test.b) ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING\
\n WindowAggr: windowExpr=[[MAX(test.b) ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING]]\
\n Projection: test.b, MAX(test.a) PARTITION BY [test.b] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING\
\n WindowAggr: windowExpr=[[MAX(test.a) PARTITION BY [test.b] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING]]\
let expected = "Projection: max(test.a) PARTITION BY [test.b] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING, max(test.b) ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING\
\n WindowAggr: windowExpr=[[max(test.b) ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING]]\
\n Projection: test.b, max(test.a) PARTITION BY [test.b] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING\
\n WindowAggr: windowExpr=[[max(test.a) PARTITION BY [test.b] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING]]\
\n TableScan: test projection=[a, b]";

assert_optimized_plan_equal(plan, expected)
6 changes: 3 additions & 3 deletions datafusion/optimizer/src/push_down_limit.rs
Original file line number Diff line number Diff line change
@@ -375,7 +375,7 @@ mod test {

// Limit should *not* push down aggregate node
let expected = "Limit: skip=0, fetch=1000\
\n Aggregate: groupBy=[[test.a]], aggr=[[MAX(test.b)]]\
\n Aggregate: groupBy=[[test.a]], aggr=[[max(test.b)]]\
\n TableScan: test";

assert_optimized_plan_equal(plan, expected)
@@ -447,7 +447,7 @@ mod test {

// Limit should use deeper LIMIT 1000, but Limit 10 shouldn't push down aggregation
let expected = "Limit: skip=0, fetch=10\
\n Aggregate: groupBy=[[test.a]], aggr=[[MAX(test.b)]]\
\n Aggregate: groupBy=[[test.a]], aggr=[[max(test.b)]]\
\n Limit: skip=0, fetch=1000\
\n TableScan: test, fetch=1000";

@@ -548,7 +548,7 @@ mod test {

// Limit should *not* push down aggregate node
let expected = "Limit: skip=10, fetch=1000\
\n Aggregate: groupBy=[[test.a]], aggr=[[MAX(test.b)]]\
\n Aggregate: groupBy=[[test.a]], aggr=[[max(test.b)]]\
\n TableScan: test";

assert_optimized_plan_equal(plan, expected)
154 changes: 77 additions & 77 deletions datafusion/optimizer/src/scalar_subquery_to_join.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -401,7 +401,7 @@ mod tests {
.build()?;

let expected = "\
Aggregate: groupBy=[[test.a, test.c]], aggr=[[MAX(test.b) AS MAX(test.b = Boolean(true)), MIN(test.b)]]\
Aggregate: groupBy=[[test.a, test.c]], aggr=[[max(test.b) AS MAX(test.b = Boolean(true)), MIN(test.b)]]\
\n Projection: test.a, test.c, test.b\
\n TableScan: test";

22 changes: 11 additions & 11 deletions datafusion/optimizer/src/single_distinct_to_groupby.rs
Original file line number Diff line number Diff line change
@@ -325,7 +325,7 @@ mod tests {

// Do nothing
let expected =
"Aggregate: groupBy=[[]], aggr=[[MAX(test.b)]] [MAX(test.b):UInt32;N]\
"Aggregate: groupBy=[[]], aggr=[[max(test.b)]] [max(test.b):UInt32;N]\
\n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";

assert_optimized_plan_equal(plan, expected)
@@ -468,8 +468,8 @@ mod tests {
)?
.build()?;
// Should work
let expected = "Projection: test.a, count(alias1) AS count(DISTINCT test.b), MAX(alias1) AS MAX(DISTINCT test.b) [a:UInt32, count(DISTINCT test.b):Int64, MAX(DISTINCT test.b):UInt32;N]\
\n Aggregate: groupBy=[[test.a]], aggr=[[count(alias1), MAX(alias1)]] [a:UInt32, count(alias1):Int64, MAX(alias1):UInt32;N]\
let expected = "Projection: test.a, count(alias1) AS count(DISTINCT test.b), max(alias1) AS max(DISTINCT test.b) [a:UInt32, count(DISTINCT test.b):Int64, max(DISTINCT test.b):UInt32;N]\
\n Aggregate: groupBy=[[test.a]], aggr=[[count(alias1), max(alias1)]] [a:UInt32, count(alias1):Int64, max(alias1):UInt32;N]\
\n Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[]] [a:UInt32, alias1:UInt32]\
\n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";

@@ -526,8 +526,8 @@ mod tests {
)?
.build()?;
// Should work
let expected = "Projection: test.a, sum(alias2) AS sum(test.c), count(alias1) AS count(DISTINCT test.b), MAX(alias1) AS MAX(DISTINCT test.b) [a:UInt32, sum(test.c):UInt64;N, count(DISTINCT test.b):Int64, MAX(DISTINCT test.b):UInt32;N]\
\n Aggregate: groupBy=[[test.a]], aggr=[[sum(alias2), count(alias1), MAX(alias1)]] [a:UInt32, sum(alias2):UInt64;N, count(alias1):Int64, MAX(alias1):UInt32;N]\
let expected = "Projection: test.a, sum(alias2) AS sum(test.c), count(alias1) AS count(DISTINCT test.b), max(alias1) AS max(DISTINCT test.b) [a:UInt32, sum(test.c):UInt64;N, count(DISTINCT test.b):Int64, max(DISTINCT test.b):UInt32;N]\
\n Aggregate: groupBy=[[test.a]], aggr=[[sum(alias2), count(alias1), max(alias1)]] [a:UInt32, sum(alias2):UInt64;N, count(alias1):Int64, max(alias1):UInt32;N]\
\n Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[sum(test.c) AS alias2]] [a:UInt32, alias1:UInt32, alias2:UInt64;N]\
\n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";

@@ -545,9 +545,9 @@ mod tests {
)?
.build()?;
// Should work
let expected = "Projection: test.a, sum(alias2) AS sum(test.c), MAX(alias3) AS MAX(test.c), count(alias1) AS count(DISTINCT test.b) [a:UInt32, sum(test.c):UInt64;N, MAX(test.c):UInt32;N, count(DISTINCT test.b):Int64]\
\n Aggregate: groupBy=[[test.a]], aggr=[[sum(alias2), MAX(alias3), count(alias1)]] [a:UInt32, sum(alias2):UInt64;N, MAX(alias3):UInt32;N, count(alias1):Int64]\
\n Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[sum(test.c) AS alias2, MAX(test.c) AS alias3]] [a:UInt32, alias1:UInt32, alias2:UInt64;N, alias3:UInt32;N]\
let expected = "Projection: test.a, sum(alias2) AS sum(test.c), max(alias3) AS max(test.c), count(alias1) AS count(DISTINCT test.b) [a:UInt32, sum(test.c):UInt64;N, max(test.c):UInt32;N, count(DISTINCT test.b):Int64]\
\n Aggregate: groupBy=[[test.a]], aggr=[[sum(alias2), max(alias3), count(alias1)]] [a:UInt32, sum(alias2):UInt64;N, max(alias3):UInt32;N, count(alias1):Int64]\
\n Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[sum(test.c) AS alias2, max(test.c) AS alias3]] [a:UInt32, alias1:UInt32, alias2:UInt64;N, alias3:UInt32;N]\
\n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";

assert_optimized_plan_equal(plan, expected)
@@ -564,9 +564,9 @@ mod tests {
)?
.build()?;
// Should work
let expected = "Projection: test.c, MIN(alias2) AS MIN(test.a), count(alias1) AS count(DISTINCT test.b) [c:UInt32, MIN(test.a):UInt32;N, count(DISTINCT test.b):Int64]\
\n Aggregate: groupBy=[[test.c]], aggr=[[MIN(alias2), count(alias1)]] [c:UInt32, MIN(alias2):UInt32;N, count(alias1):Int64]\
\n Aggregate: groupBy=[[test.c, test.b AS alias1]], aggr=[[MIN(test.a) AS alias2]] [c:UInt32, alias1:UInt32, alias2:UInt32;N]\
let expected = "Projection: test.c, min(alias2) AS min(test.a), count(alias1) AS count(DISTINCT test.b) [c:UInt32, min(test.a):UInt32;N, count(DISTINCT test.b):Int64]\
\n Aggregate: groupBy=[[test.c]], aggr=[[min(alias2), count(alias1)]] [c:UInt32, min(alias2):UInt32;N, count(alias1):Int64]\
\n Aggregate: groupBy=[[test.c, test.b AS alias1]], aggr=[[min(test.a) AS alias2]] [c:UInt32, alias1:UInt32, alias2:UInt32;N]\
\n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";

assert_optimized_plan_equal(plan, expected)
1 change: 0 additions & 1 deletion datafusion/physical-expr/src/aggregate/mod.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
pub(crate) mod groups_accumulator;
pub(crate) mod stats;

pub mod moving_min_max;
pub mod utils {
pub use datafusion_physical_expr_common::aggregate::utils::{
adjust_output_array, down_cast_any_ref, get_accum_scalar_values_as_arrays,
335 changes: 0 additions & 335 deletions datafusion/physical-expr/src/aggregate/moving_min_max.rs

This file was deleted.

66 changes: 33 additions & 33 deletions datafusion/sql/tests/sql_integration.rs
Original file line number Diff line number Diff line change
@@ -1050,20 +1050,20 @@ fn select_aggregate_with_having_that_reuses_aggregate() {
FROM person
HAVING MAX(age) < 30";
let expected = "Projection: MAX(person.age)\
\n Filter: MAX(person.age) < Int64(30)\
\n Aggregate: groupBy=[[]], aggr=[[MAX(person.age)]]\
\n Filter: max(person.age) < Int64(30)\
\n Aggregate: groupBy=[[]], aggr=[[max(person.age)]]\
\n TableScan: person";
quick_test(sql, expected);
}

#[test]
fn select_aggregate_with_having_with_aggregate_not_in_select() {
let sql = "SELECT MAX(age)
let sql = "SELECT max(age)
FROM person
HAVING MAX(first_name) > 'M'";
let expected = "Projection: MAX(person.age)\
\n Filter: MAX(person.first_name) > Utf8(\"M\")\
\n Aggregate: groupBy=[[]], aggr=[[MAX(person.age), MAX(person.first_name)]]\
HAVING max(first_name) > 'M'";
let expected = "Projection: max(person.age)\
\n Filter: max(person.first_name) > Utf8(\"M\")\
\n Aggregate: groupBy=[[]], aggr=[[max(person.age), max(person.first_name)]]\
\n TableScan: person";
quick_test(sql, expected);
}
@@ -1086,21 +1086,21 @@ fn select_aggregate_aliased_with_having_referencing_aggregate_by_its_alias() {
FROM person
HAVING max_age < 30";
// FIXME: add test for having in execution
let expected = "Projection: MAX(person.age) AS max_age\
\n Filter: MAX(person.age) < Int64(30)\
\n Aggregate: groupBy=[[]], aggr=[[MAX(person.age)]]\
let expected = "Projection: max(person.age) AS max_age\
\n Filter: max(person.age) < Int64(30)\
\n Aggregate: groupBy=[[]], aggr=[[max(person.age)]]\
\n TableScan: person";
quick_test(sql, expected);
}

#[test]
fn select_aggregate_aliased_with_having_that_reuses_aggregate_but_not_by_its_alias() {
let sql = "SELECT MAX(age) as max_age
let sql = "SELECT max(age) as max_age
FROM person
HAVING MAX(age) < 30";
let expected = "Projection: MAX(person.age) AS max_age\
\n Filter: MAX(person.age) < Int64(30)\
\n Aggregate: groupBy=[[]], aggr=[[MAX(person.age)]]\
HAVING max(age) < 30";
let expected = "Projection: max(person.age) AS max_age\
\n Filter: max(person.age) < Int64(30)\
\n Aggregate: groupBy=[[]], aggr=[[max(person.age)]]\
\n TableScan: person";
quick_test(sql, expected);
}
@@ -1111,23 +1111,23 @@ fn select_aggregate_with_group_by_with_having() {
FROM person
GROUP BY first_name
HAVING first_name = 'M'";
let expected = "Projection: person.first_name, MAX(person.age)\
let expected = "Projection: person.first_name, max(person.age)\
\n Filter: person.first_name = Utf8(\"M\")\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[MAX(person.age)]]\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[max(person.age)]]\
\n TableScan: person";
quick_test(sql, expected);
}

#[test]
fn select_aggregate_with_group_by_with_having_and_where() {
let sql = "SELECT first_name, MAX(age)
let sql = "SELECT first_name, max(age)
FROM person
WHERE id > 5
GROUP BY first_name
HAVING MAX(age) < 100";
let expected = "Projection: person.first_name, MAX(person.age)\
\n Filter: MAX(person.age) < Int64(100)\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[MAX(person.age)]]\
let expected = "Projection: person.first_name, max(person.age)\
\n Filter: max(person.age) < Int64(100)\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[max(person.age)]]\
\n Filter: person.id > Int64(5)\
\n TableScan: person";
quick_test(sql, expected);
@@ -1140,9 +1140,9 @@ fn select_aggregate_with_group_by_with_having_and_where_filtering_on_aggregate_c
WHERE id > 5 AND age > 18
GROUP BY first_name
HAVING MAX(age) < 100";
let expected = "Projection: person.first_name, MAX(person.age)\
\n Filter: MAX(person.age) < Int64(100)\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[MAX(person.age)]]\
let expected = "Projection: person.first_name, max(person.age)\
\n Filter: max(person.age) < Int64(100)\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[max(person.age)]]\
\n Filter: person.id > Int64(5) AND person.age > Int64(18)\
\n TableScan: person";
quick_test(sql, expected);
@@ -1154,9 +1154,9 @@ fn select_aggregate_with_group_by_with_having_using_column_by_alias() {
FROM person
GROUP BY first_name
HAVING MAX(age) > 2 AND fn = 'M'";
let expected = "Projection: person.first_name AS fn, MAX(person.age)\
\n Filter: MAX(person.age) > Int64(2) AND person.first_name = Utf8(\"M\")\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[MAX(person.age)]]\
let expected = "Projection: person.first_name AS fn, max(person.age)\
\n Filter: max(person.age) > Int64(2) AND person.first_name = Utf8(\"M\")\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[max(person.age)]]\
\n TableScan: person";
quick_test(sql, expected);
}
@@ -1169,8 +1169,8 @@ fn select_aggregate_with_group_by_with_having_using_columns_with_and_without_the
GROUP BY first_name
HAVING MAX(age) > 2 AND max_age < 5 AND first_name = 'M' AND fn = 'N'";
let expected = "Projection: person.first_name AS fn, MAX(person.age) AS max_age\
\n Filter: MAX(person.age) > Int64(2) AND MAX(person.age) < Int64(5) AND person.first_name = Utf8(\"M\") AND person.first_name = Utf8(\"N\")\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[MAX(person.age)]]\
\n Filter: max(person.age) > Int64(2) AND MAX(person.age) < Int64(5) AND person.first_name = Utf8(\"M\") AND person.first_name = Utf8(\"N\")\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[max(person.age)]]\
\n TableScan: person";
quick_test(sql, expected);
}
@@ -1181,9 +1181,9 @@ fn select_aggregate_with_group_by_with_having_that_reuses_aggregate() {
FROM person
GROUP BY first_name
HAVING MAX(age) > 100";
let expected = "Projection: person.first_name, MAX(person.age)\
\n Filter: MAX(person.age) > Int64(100)\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[MAX(person.age)]]\
let expected = "Projection: person.first_name, max(person.age)\
\n Filter: max(person.age) > Int64(100)\
\n Aggregate: groupBy=[[person.first_name]], aggr=[[max(person.age)]]\
\n TableScan: person";
quick_test(sql, expected);
}
@@ -1196,7 +1196,7 @@ fn select_aggregate_with_group_by_with_having_referencing_column_not_in_group_by
HAVING MAX(age) > 10 AND last_name = 'M'";
let err = logical_plan(sql).expect_err("query should have failed");
assert_eq!(
"Error during planning: HAVING clause references non-aggregate values: Expression person.last_name could not be resolved from available columns: person.first_name, MAX(person.age)",
"Error during planning: HAVING clause references non-aggregate values: Expression person.last_name could not be resolved from available columns: person.first_name, max(person.age)",
err.strip_backtrace()
);
}
18 changes: 9 additions & 9 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
@@ -4622,16 +4622,16 @@ query TT
EXPLAIN SELECT max(c1), c2, c3 FROM aggregate_test_100 group by c2, c3 limit 5;
----
logical_plan
01)Projection: MAX(aggregate_test_100.c1), aggregate_test_100.c2, aggregate_test_100.c3
01)Projection: max(aggregate_test_100.c1), aggregate_test_100.c2, aggregate_test_100.c3
02)--Limit: skip=0, fetch=5
03)----Aggregate: groupBy=[[aggregate_test_100.c2, aggregate_test_100.c3]], aggr=[[MAX(aggregate_test_100.c1)]]
03)----Aggregate: groupBy=[[aggregate_test_100.c2, aggregate_test_100.c3]], aggr=[[max(aggregate_test_100.c1)]]
04)------TableScan: aggregate_test_100 projection=[c1, c2, c3]
physical_plan
01)ProjectionExec: expr=[MAX(aggregate_test_100.c1)@2 as MAX(aggregate_test_100.c1), c2@0 as c2, c3@1 as c3]
01)ProjectionExec: expr=[max(aggregate_test_100.c1)@2 as max(aggregate_test_100.c1), c2@0 as c2, c3@1 as c3]
02)--GlobalLimitExec: skip=0, fetch=5
03)----AggregateExec: mode=Final, gby=[c2@0 as c2, c3@1 as c3], aggr=[MAX(aggregate_test_100.c1)]
03)----AggregateExec: mode=Final, gby=[c2@0 as c2, c3@1 as c3], aggr=[max(aggregate_test_100.c1)]
04)------CoalescePartitionsExec
05)--------AggregateExec: mode=Partial, gby=[c2@1 as c2, c3@2 as c3], aggr=[MAX(aggregate_test_100.c1)]
05)--------AggregateExec: mode=Partial, gby=[c2@1 as c2, c3@2 as c3], aggr=[max(aggregate_test_100.c1)]
06)----------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
07)------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c1, c2, c3], has_header=true

@@ -5262,20 +5262,20 @@ query TT
EXPLAIN SELECT MIN(col0) FROM empty;
----
logical_plan
01)Aggregate: groupBy=[[]], aggr=[[MIN(empty.col0)]]
01)Aggregate: groupBy=[[]], aggr=[[min(empty.col0)]]
02)--TableScan: empty projection=[col0]
physical_plan
01)ProjectionExec: expr=[NULL as MIN(empty.col0)]
01)ProjectionExec: expr=[NULL as min(empty.col0)]
02)--PlaceholderRowExec

query TT
EXPLAIN SELECT MAX(col0) FROM empty;
----
logical_plan
01)Aggregate: groupBy=[[]], aggr=[[MAX(empty.col0)]]
01)Aggregate: groupBy=[[]], aggr=[[max(empty.col0)]]
02)--TableScan: empty projection=[col0]
physical_plan
01)ProjectionExec: expr=[NULL as MAX(empty.col0)]
01)ProjectionExec: expr=[NULL as max(empty.col0)]
02)--PlaceholderRowExec

statement ok
66 changes: 33 additions & 33 deletions datafusion/sqllogictest/test_files/aggregates_topk.slt
Original file line number Diff line number Diff line change
@@ -41,18 +41,18 @@ explain select trace_id, MAX(timestamp) from traces group by trace_id order by M
----
logical_plan
01)Limit: skip=0, fetch=4
02)--Sort: MAX(traces.timestamp) DESC NULLS FIRST, fetch=4
03)----Aggregate: groupBy=[[traces.trace_id]], aggr=[[MAX(traces.timestamp)]]
02)--Sort: max(traces.timestamp) DESC NULLS FIRST, fetch=4
03)----Aggregate: groupBy=[[traces.trace_id]], aggr=[[max(traces.timestamp)]]
04)------TableScan: traces projection=[trace_id, timestamp]
physical_plan
01)GlobalLimitExec: skip=0, fetch=4
02)--SortPreservingMergeExec: [MAX(traces.timestamp)@1 DESC], fetch=4
03)----SortExec: TopK(fetch=4), expr=[MAX(traces.timestamp)@1 DESC], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[trace_id@0 as trace_id], aggr=[MAX(traces.timestamp)]
02)--SortPreservingMergeExec: [max(traces.timestamp)@1 DESC], fetch=4
03)----SortExec: TopK(fetch=4), expr=[max(traces.timestamp)@1 DESC], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[trace_id@0 as trace_id], aggr=[max(traces.timestamp)]
05)--------CoalesceBatchesExec: target_batch_size=8192
06)----------RepartitionExec: partitioning=Hash([trace_id@0], 4), input_partitions=4
07)------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
08)--------------AggregateExec: mode=Partial, gby=[trace_id@0 as trace_id], aggr=[MAX(traces.timestamp)]
08)--------------AggregateExec: mode=Partial, gby=[trace_id@0 as trace_id], aggr=[max(traces.timestamp)]
09)----------------MemoryExec: partitions=1, partition_sizes=[1]


@@ -96,56 +96,56 @@ explain select trace_id, MAX(timestamp) from traces group by trace_id order by M
----
logical_plan
01)Limit: skip=0, fetch=4
02)--Sort: MAX(traces.timestamp) DESC NULLS FIRST, fetch=4
03)----Aggregate: groupBy=[[traces.trace_id]], aggr=[[MAX(traces.timestamp)]]
02)--Sort: max(traces.timestamp) DESC NULLS FIRST, fetch=4
03)----Aggregate: groupBy=[[traces.trace_id]], aggr=[[max(traces.timestamp)]]
04)------TableScan: traces projection=[trace_id, timestamp]
physical_plan
01)GlobalLimitExec: skip=0, fetch=4
02)--SortPreservingMergeExec: [MAX(traces.timestamp)@1 DESC], fetch=4
03)----SortExec: TopK(fetch=4), expr=[MAX(traces.timestamp)@1 DESC], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[trace_id@0 as trace_id], aggr=[MAX(traces.timestamp)], lim=[4]
02)--SortPreservingMergeExec: [max(traces.timestamp)@1 DESC], fetch=4
03)----SortExec: TopK(fetch=4), expr=[max(traces.timestamp)@1 DESC], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[trace_id@0 as trace_id], aggr=[max(traces.timestamp)], lim=[4]
05)--------CoalesceBatchesExec: target_batch_size=8192
06)----------RepartitionExec: partitioning=Hash([trace_id@0], 4), input_partitions=4
07)------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
08)--------------AggregateExec: mode=Partial, gby=[trace_id@0 as trace_id], aggr=[MAX(traces.timestamp)], lim=[4]
08)--------------AggregateExec: mode=Partial, gby=[trace_id@0 as trace_id], aggr=[max(traces.timestamp)], lim=[4]
09)----------------MemoryExec: partitions=1, partition_sizes=[1]

query TT
explain select trace_id, MIN(timestamp) from traces group by trace_id order by MIN(timestamp) desc limit 4;
----
logical_plan
01)Limit: skip=0, fetch=4
02)--Sort: MIN(traces.timestamp) DESC NULLS FIRST, fetch=4
03)----Aggregate: groupBy=[[traces.trace_id]], aggr=[[MIN(traces.timestamp)]]
02)--Sort: min(traces.timestamp) DESC NULLS FIRST, fetch=4
03)----Aggregate: groupBy=[[traces.trace_id]], aggr=[[min(traces.timestamp)]]
04)------TableScan: traces projection=[trace_id, timestamp]
physical_plan
01)GlobalLimitExec: skip=0, fetch=4
02)--SortPreservingMergeExec: [MIN(traces.timestamp)@1 DESC], fetch=4
03)----SortExec: TopK(fetch=4), expr=[MIN(traces.timestamp)@1 DESC], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[trace_id@0 as trace_id], aggr=[MIN(traces.timestamp)]
02)--SortPreservingMergeExec: [min(traces.timestamp)@1 DESC], fetch=4
03)----SortExec: TopK(fetch=4), expr=[min(traces.timestamp)@1 DESC], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[trace_id@0 as trace_id], aggr=[min(traces.timestamp)]
05)--------CoalesceBatchesExec: target_batch_size=8192
06)----------RepartitionExec: partitioning=Hash([trace_id@0], 4), input_partitions=4
07)------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
08)--------------AggregateExec: mode=Partial, gby=[trace_id@0 as trace_id], aggr=[MIN(traces.timestamp)]
08)--------------AggregateExec: mode=Partial, gby=[trace_id@0 as trace_id], aggr=[min(traces.timestamp)]
09)----------------MemoryExec: partitions=1, partition_sizes=[1]

query TT
explain select trace_id, MAX(timestamp) from traces group by trace_id order by MAX(timestamp) asc limit 4;
----
logical_plan
01)Limit: skip=0, fetch=4
02)--Sort: MAX(traces.timestamp) ASC NULLS LAST, fetch=4
03)----Aggregate: groupBy=[[traces.trace_id]], aggr=[[MAX(traces.timestamp)]]
02)--Sort: max(traces.timestamp) ASC NULLS LAST, fetch=4
03)----Aggregate: groupBy=[[traces.trace_id]], aggr=[[max(traces.timestamp)]]
04)------TableScan: traces projection=[trace_id, timestamp]
physical_plan
01)GlobalLimitExec: skip=0, fetch=4
02)--SortPreservingMergeExec: [MAX(traces.timestamp)@1 ASC NULLS LAST], fetch=4
03)----SortExec: TopK(fetch=4), expr=[MAX(traces.timestamp)@1 ASC NULLS LAST], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[trace_id@0 as trace_id], aggr=[MAX(traces.timestamp)]
02)--SortPreservingMergeExec: [max(traces.timestamp)@1 ASC NULLS LAST], fetch=4
03)----SortExec: TopK(fetch=4), expr=[max(traces.timestamp)@1 ASC NULLS LAST], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[trace_id@0 as trace_id], aggr=[max(traces.timestamp)]
05)--------CoalesceBatchesExec: target_batch_size=8192
06)----------RepartitionExec: partitioning=Hash([trace_id@0], 4), input_partitions=4
07)------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
08)--------------AggregateExec: mode=Partial, gby=[trace_id@0 as trace_id], aggr=[MAX(traces.timestamp)]
08)--------------AggregateExec: mode=Partial, gby=[trace_id@0 as trace_id], aggr=[max(traces.timestamp)]
09)----------------MemoryExec: partitions=1, partition_sizes=[1]

query TT
@@ -154,59 +154,59 @@ explain select trace_id, MAX(timestamp) from traces group by trace_id order by t
logical_plan
01)Limit: skip=0, fetch=4
02)--Sort: traces.trace_id ASC NULLS LAST, fetch=4
03)----Aggregate: groupBy=[[traces.trace_id]], aggr=[[MAX(traces.timestamp)]]
03)----Aggregate: groupBy=[[traces.trace_id]], aggr=[[max(traces.timestamp)]]
04)------TableScan: traces projection=[trace_id, timestamp]
physical_plan
01)GlobalLimitExec: skip=0, fetch=4
02)--SortPreservingMergeExec: [trace_id@0 ASC NULLS LAST], fetch=4
03)----SortExec: TopK(fetch=4), expr=[trace_id@0 ASC NULLS LAST], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[trace_id@0 as trace_id], aggr=[MAX(traces.timestamp)]
04)------AggregateExec: mode=FinalPartitioned, gby=[trace_id@0 as trace_id], aggr=[max(traces.timestamp)]
05)--------CoalesceBatchesExec: target_batch_size=8192
06)----------RepartitionExec: partitioning=Hash([trace_id@0], 4), input_partitions=4
07)------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
08)--------------AggregateExec: mode=Partial, gby=[trace_id@0 as trace_id], aggr=[MAX(traces.timestamp)]
08)--------------AggregateExec: mode=Partial, gby=[trace_id@0 as trace_id], aggr=[max(traces.timestamp)]
09)----------------MemoryExec: partitions=1, partition_sizes=[1]

query TI
select trace_id, MAX(timestamp) from traces group by trace_id order by MAX(timestamp) desc limit 4;
select trace_id, max(timestamp) from traces group by trace_id order by MAX(timestamp) desc limit 4;
----
c 4
b 3
a 1
NULL 0

query TI
select trace_id, MIN(timestamp) from traces group by trace_id order by MIN(timestamp) asc limit 4;
select trace_id, min(timestamp) from traces group by trace_id order by MIN(timestamp) asc limit 4;
----
b -2
a -1
NULL 0
c 2

query TI
select trace_id, MAX(timestamp) from traces group by trace_id order by MAX(timestamp) desc limit 3;
select trace_id, max(timestamp) from traces group by trace_id order by MAX(timestamp) desc limit 3;
----
c 4
b 3
a 1

query TI
select trace_id, MIN(timestamp) from traces group by trace_id order by MIN(timestamp) asc limit 3;
select trace_id, min(timestamp) from traces group by trace_id order by MIN(timestamp) asc limit 3;
----
b -2
a -1
NULL 0

query TII
select trace_id, other, MIN(timestamp) from traces group by trace_id, other order by MIN(timestamp) asc limit 4;
select trace_id, other, min(timestamp) from traces group by trace_id, other order by MIN(timestamp) asc limit 4;
----
b 0 -2
a -1 -1
NULL 0 0
a 1 1

query TII
select trace_id, MIN(other), MIN(timestamp) from traces group by trace_id order by MIN(timestamp), MIN(other) limit 4;
select trace_id, min(other), MIN(timestamp) from traces group by trace_id order by MIN(timestamp), MIN(other) limit 4;
----
b 0 -2
a -1 -1
8 changes: 4 additions & 4 deletions datafusion/sqllogictest/test_files/expr.slt
Original file line number Diff line number Diff line change
@@ -2606,12 +2606,12 @@ query TT
explain select min(a) filter (where a > 1) as x from t;
----
logical_plan
01)Projection: MIN(t.a) FILTER (WHERE t.a > Int64(1)) AS x
02)--Aggregate: groupBy=[[]], aggr=[[MIN(t.a) FILTER (WHERE t.a > Float32(1)) AS MIN(t.a) FILTER (WHERE t.a > Int64(1))]]
01)Projection: min(t.a) FILTER (WHERE t.a > Int64(1)) AS x
02)--Aggregate: groupBy=[[]], aggr=[[min(t.a) FILTER (WHERE t.a > Float32(1)) AS min(t.a) FILTER (WHERE t.a > Int64(1))]]
03)----TableScan: t projection=[a]
physical_plan
01)ProjectionExec: expr=[MIN(t.a) FILTER (WHERE t.a > Int64(1))@0 as x]
02)--AggregateExec: mode=Single, gby=[], aggr=[MIN(t.a) FILTER (WHERE t.a > Int64(1))]
01)ProjectionExec: expr=[min(t.a) FILTER (WHERE t.a > Int64(1))@0 as x]
02)--AggregateExec: mode=Single, gby=[], aggr=[min(t.a) FILTER (WHERE t.a > Int64(1))]
03)----MemoryExec: partitions=1, partition_sizes=[1]


44 changes: 22 additions & 22 deletions datafusion/sqllogictest/test_files/group_by.slt
Original file line number Diff line number Diff line change
@@ -4169,33 +4169,33 @@ query TT
EXPLAIN SELECT SUM(DISTINCT CAST(x AS DOUBLE)), MAX(DISTINCT x) FROM t1 GROUP BY y;
----
logical_plan
01)Projection: sum(DISTINCT t1.x), MAX(DISTINCT t1.x)
02)--Aggregate: groupBy=[[t1.y]], aggr=[[sum(DISTINCT CAST(t1.x AS Float64)), MAX(DISTINCT t1.x)]]
01)Projection: sum(DISTINCT t1.x), max(DISTINCT t1.x)
02)--Aggregate: groupBy=[[t1.y]], aggr=[[sum(DISTINCT CAST(t1.x AS Float64)), max(DISTINCT t1.x)]]
03)----TableScan: t1 projection=[x, y]
physical_plan
01)ProjectionExec: expr=[sum(DISTINCT t1.x)@1 as sum(DISTINCT t1.x), MAX(DISTINCT t1.x)@2 as MAX(DISTINCT t1.x)]
02)--AggregateExec: mode=FinalPartitioned, gby=[y@0 as y], aggr=[sum(DISTINCT t1.x), MAX(DISTINCT t1.x)]
01)ProjectionExec: expr=[sum(DISTINCT t1.x)@1 as sum(DISTINCT t1.x), max(DISTINCT t1.x)@2 as max(DISTINCT t1.x)]
02)--AggregateExec: mode=FinalPartitioned, gby=[y@0 as y], aggr=[sum(DISTINCT t1.x), max(DISTINCT t1.x)]
03)----CoalesceBatchesExec: target_batch_size=2
04)------RepartitionExec: partitioning=Hash([y@0], 8), input_partitions=8
05)--------RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1
06)----------AggregateExec: mode=Partial, gby=[y@1 as y], aggr=[sum(DISTINCT t1.x), MAX(DISTINCT t1.x)]
06)----------AggregateExec: mode=Partial, gby=[y@1 as y], aggr=[sum(DISTINCT t1.x), max(DISTINCT t1.x)]
07)------------MemoryExec: partitions=1, partition_sizes=[1]

query TT
EXPLAIN SELECT SUM(DISTINCT CAST(x AS DOUBLE)), MAX(DISTINCT CAST(x AS DOUBLE)) FROM t1 GROUP BY y;
----
logical_plan
01)Projection: sum(alias1) AS sum(DISTINCT t1.x), MAX(alias1) AS MAX(DISTINCT t1.x)
02)--Aggregate: groupBy=[[t1.y]], aggr=[[sum(alias1), MAX(alias1)]]
01)Projection: sum(alias1) AS sum(DISTINCT t1.x), max(alias1) AS max(DISTINCT t1.x)
02)--Aggregate: groupBy=[[t1.y]], aggr=[[sum(alias1), max(alias1)]]
03)----Aggregate: groupBy=[[t1.y, __common_expr_1 AS t1.x AS alias1]], aggr=[[]]
04)------Projection: CAST(t1.x AS Float64) AS __common_expr_1, t1.y
05)--------TableScan: t1 projection=[x, y]
physical_plan
01)ProjectionExec: expr=[sum(alias1)@1 as sum(DISTINCT t1.x), MAX(alias1)@2 as MAX(DISTINCT t1.x)]
02)--AggregateExec: mode=FinalPartitioned, gby=[y@0 as y], aggr=[sum(alias1), MAX(alias1)]
01)ProjectionExec: expr=[sum(alias1)@1 as sum(DISTINCT t1.x), max(alias1)@2 as max(DISTINCT t1.x)]
02)--AggregateExec: mode=FinalPartitioned, gby=[y@0 as y], aggr=[sum(alias1), max(alias1)]
03)----CoalesceBatchesExec: target_batch_size=2
04)------RepartitionExec: partitioning=Hash([y@0], 8), input_partitions=8
05)--------AggregateExec: mode=Partial, gby=[y@0 as y], aggr=[sum(alias1), MAX(alias1)]
05)--------AggregateExec: mode=Partial, gby=[y@0 as y], aggr=[sum(alias1), max(alias1)]
06)----------AggregateExec: mode=FinalPartitioned, gby=[y@0 as y, alias1@1 as alias1], aggr=[]
07)------------CoalesceBatchesExec: target_batch_size=2
08)--------------RepartitionExec: partitioning=Hash([y@0, alias1@1], 8), input_partitions=8
@@ -4396,18 +4396,18 @@ EXPLAIN SELECT c1, count(distinct c2), min(distinct c2), sum(c3), max(c4) FROM a
----
logical_plan
01)Sort: aggregate_test_100.c1 ASC NULLS LAST
02)--Projection: aggregate_test_100.c1, count(alias1) AS count(DISTINCT aggregate_test_100.c2), MIN(alias1) AS MIN(DISTINCT aggregate_test_100.c2), sum(alias2) AS sum(aggregate_test_100.c3), MAX(alias3) AS MAX(aggregate_test_100.c4)
03)----Aggregate: groupBy=[[aggregate_test_100.c1]], aggr=[[count(alias1), MIN(alias1), sum(alias2), MAX(alias3)]]
04)------Aggregate: groupBy=[[aggregate_test_100.c1, aggregate_test_100.c2 AS alias1]], aggr=[[sum(CAST(aggregate_test_100.c3 AS Int64)) AS alias2, MAX(aggregate_test_100.c4) AS alias3]]
02)--Projection: aggregate_test_100.c1, count(alias1) AS count(DISTINCT aggregate_test_100.c2), min(alias1) AS min(DISTINCT aggregate_test_100.c2), sum(alias2) AS sum(aggregate_test_100.c3), max(alias3) AS max(aggregate_test_100.c4)
03)----Aggregate: groupBy=[[aggregate_test_100.c1]], aggr=[[count(alias1), min(alias1), sum(alias2), max(alias3)]]
04)------Aggregate: groupBy=[[aggregate_test_100.c1, aggregate_test_100.c2 AS alias1]], aggr=[[sum(CAST(aggregate_test_100.c3 AS Int64)) AS alias2, max(aggregate_test_100.c4) AS alias3]]
05)--------TableScan: aggregate_test_100 projection=[c1, c2, c3, c4]
physical_plan
01)SortPreservingMergeExec: [c1@0 ASC NULLS LAST]
02)--SortExec: expr=[c1@0 ASC NULLS LAST], preserve_partitioning=[true]
03)----ProjectionExec: expr=[c1@0 as c1, count(alias1)@1 as count(DISTINCT aggregate_test_100.c2), MIN(alias1)@2 as MIN(DISTINCT aggregate_test_100.c2), sum(alias2)@3 as sum(aggregate_test_100.c3), MAX(alias3)@4 as MAX(aggregate_test_100.c4)]
04)------AggregateExec: mode=FinalPartitioned, gby=[c1@0 as c1], aggr=[count(alias1), MIN(alias1), sum(alias2), MAX(alias3)]
03)----ProjectionExec: expr=[c1@0 as c1, count(alias1)@1 as count(DISTINCT aggregate_test_100.c2), min(alias1)@2 as min(DISTINCT aggregate_test_100.c2), sum(alias2)@3 as sum(aggregate_test_100.c3), max(alias3)@4 as max(aggregate_test_100.c4)]
04)------AggregateExec: mode=FinalPartitioned, gby=[c1@0 as c1], aggr=[count(alias1), min(alias1), sum(alias2), max(alias3)]
05)--------CoalesceBatchesExec: target_batch_size=2
06)----------RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8
07)------------AggregateExec: mode=Partial, gby=[c1@0 as c1], aggr=[count(alias1), MIN(alias1), sum(alias2), MAX(alias3)]
07)------------AggregateExec: mode=Partial, gby=[c1@0 as c1], aggr=[count(alias1), min(alias1), sum(alias2), max(alias3)]
08)--------------AggregateExec: mode=FinalPartitioned, gby=[c1@0 as c1, alias1@1 as alias1], aggr=[alias2, alias3]
09)----------------CoalesceBatchesExec: target_batch_size=2
10)------------------RepartitionExec: partitioning=Hash([c1@0, alias1@1], 8), input_partitions=8
@@ -4576,17 +4576,17 @@ LIMIT 4;
----
logical_plan
01)Limit: skip=0, fetch=4
02)--Sort: MAX(timestamp_table.t1) DESC NULLS FIRST, fetch=4
03)----Aggregate: groupBy=[[timestamp_table.c2]], aggr=[[MAX(timestamp_table.t1)]]
02)--Sort: max(timestamp_table.t1) DESC NULLS FIRST, fetch=4
03)----Aggregate: groupBy=[[timestamp_table.c2]], aggr=[[max(timestamp_table.t1)]]
04)------TableScan: timestamp_table projection=[t1, c2]
physical_plan
01)GlobalLimitExec: skip=0, fetch=4
02)--SortPreservingMergeExec: [MAX(timestamp_table.t1)@1 DESC], fetch=4
03)----SortExec: TopK(fetch=4), expr=[MAX(timestamp_table.t1)@1 DESC], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[c2@0 as c2], aggr=[MAX(timestamp_table.t1)], lim=[4]
02)--SortPreservingMergeExec: [max(timestamp_table.t1)@1 DESC], fetch=4
03)----SortExec: TopK(fetch=4), expr=[max(timestamp_table.t1)@1 DESC], preserve_partitioning=[true]
04)------AggregateExec: mode=FinalPartitioned, gby=[c2@0 as c2], aggr=[max(timestamp_table.t1)], lim=[4]
05)--------CoalesceBatchesExec: target_batch_size=2
06)----------RepartitionExec: partitioning=Hash([c2@0], 8), input_partitions=8
07)------------AggregateExec: mode=Partial, gby=[c2@1 as c2], aggr=[MAX(timestamp_table.t1)], lim=[4]
07)------------AggregateExec: mode=Partial, gby=[c2@1 as c2], aggr=[max(timestamp_table.t1)], lim=[4]
08)--------------RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=4
09)----------------CsvExec: file_groups={4 groups: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/group_by/timestamp_table/0.csv], [WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/group_by/timestamp_table/1.csv], [WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/group_by/timestamp_table/2.csv], [WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/group_by/timestamp_table/3.csv]]}, projection=[t1, c2], has_header=true

8 changes: 4 additions & 4 deletions datafusion/sqllogictest/test_files/union.slt
Original file line number Diff line number Diff line change
@@ -588,8 +588,8 @@ logical_plan
06)----------EmptyRelation
07)--Projection: b.x AS count, b.y AS n
08)----SubqueryAlias: b
09)------Projection: Int64(1) AS x, MAX(Int64(10)) AS y
10)--------Aggregate: groupBy=[[]], aggr=[[MAX(Int64(10))]]
09)------Projection: Int64(1) AS x, max(Int64(10)) AS y
10)--------Aggregate: groupBy=[[]], aggr=[[max(Int64(10))]]
11)----------EmptyRelation
physical_plan
01)UnionExec
@@ -600,8 +600,8 @@ physical_plan
06)----------AggregateExec: mode=Partial, gby=[n@0 as n], aggr=[count(*)], ordering_mode=Sorted
07)------------ProjectionExec: expr=[5 as n]
08)--------------PlaceholderRowExec
09)--ProjectionExec: expr=[1 as count, MAX(Int64(10))@0 as n]
10)----AggregateExec: mode=Single, gby=[], aggr=[MAX(Int64(10))]
09)--ProjectionExec: expr=[1 as count, max(Int64(10))@0 as n]
10)----AggregateExec: mode=Single, gby=[], aggr=[max(Int64(10))]
11)------PlaceholderRowExec


4 changes: 2 additions & 2 deletions datafusion/sqllogictest/test_files/update.slt
Original file line number Diff line number Diff line change
@@ -53,8 +53,8 @@ logical_plan
01)Dml: op=[Update] table=[t1]
02)--Projection: t1.a AS a, (<subquery>) AS b, t1.c AS c, t1.d AS d
03)----Subquery:
04)------Projection: MAX(t2.b)
05)--------Aggregate: groupBy=[[]], aggr=[[MAX(t2.b)]]
04)------Projection: max(t2.b)
05)--------Aggregate: groupBy=[[]], aggr=[[max(t2.b)]]
06)----------Filter: outer_ref(t1.a) = t2.a
07)------------TableScan: t2
08)----TableScan: t1
42 changes: 21 additions & 21 deletions datafusion/sqllogictest/test_files/window.slt

Large diffs are not rendered by default.

0 comments on commit cdcda3f

Please sign in to comment.