Skip to content

Commit 9842d19

Browse files
committed
chore: more cleanup of error messages
1 parent 810246d commit 9842d19

File tree

5 files changed

+50
-18
lines changed

5 files changed

+50
-18
lines changed

datafusion/optimizer/src/analyzer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl Analyzer {
145145
{
146146
// verify the logical plan required invariants at the start, before analyzer
147147
plan.check_invariants(InvariantLevel::Always)
148-
.map_err(|e| e.context("assert_lp_invariants_before_analyzers"))?;
148+
.map_err(|e| e.context("Invalid input plan passed to Analyzer"))?;
149149

150150
let start_time = Instant::now();
151151
let mut new_plan = plan;
@@ -178,7 +178,7 @@ impl Analyzer {
178178
// verify at the end, after the last LP analyzer pass, that the plan is executable.
179179
new_plan
180180
.check_invariants(InvariantLevel::Executable)
181-
.map_err(|e| e.context("Invalid plan after Analyzer"))?;
181+
.map_err(|e| e.context("Invalid (non-executable) plan after Analyzer"))?;
182182

183183
log_plan("Final analyzed plan", &new_plan);
184184
debug!("Analyzer took {} ms", start_time.elapsed().as_millis());

datafusion/optimizer/src/decorrelate_predicate_subquery.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ mod tests {
835835
.build()?;
836836

837837
// Maybe okay if the table only has a single column?
838-
let expected = "Invalid plan after Analyzer\
838+
let expected = "Invalid (non-executable) plan after Analyzer\
839839
\ncaused by\
840840
\nError during planning: InSubquery should only return one column, but found 4";
841841
assert_analyzer_check_err(vec![], plan, expected);
@@ -930,7 +930,7 @@ mod tests {
930930
.project(vec![col("customer.c_custkey")])?
931931
.build()?;
932932

933-
let expected = "Invalid plan after Analyzer\
933+
let expected = "Invalid (non-executable) plan after Analyzer\
934934
\ncaused by\
935935
\nError during planning: InSubquery should only return one column";
936936
assert_analyzer_check_err(vec![], plan, expected);

datafusion/optimizer/src/optimizer.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl Optimizer {
358358
{
359359
// verify LP is valid, before the first LP optimizer pass.
360360
plan.check_invariants(InvariantLevel::Executable)
361-
.map_err(|e| e.context("Invalid plan before LP Optimizers"))?;
361+
.map_err(|e| e.context("Invalid input plan before LP Optimizers"))?;
362362

363363
let start_time = Instant::now();
364364
let options = config.options();
@@ -394,12 +394,12 @@ impl Optimizer {
394394
.and_then(|tnr| {
395395
// run checks optimizer invariant checks, per optimizer rule applied
396396
assert_valid_optimization(&tnr.data, &starting_schema)
397-
.map_err(|e| e.context(format!("check_optimizer_specific_invariants after optimizer rule: {}", rule.name())))?;
397+
.map_err(|e| e.context(format!("Check optimizer-specific invariants after optimizer rule: {}", rule.name())))?;
398398

399399
// run LP invariant checks only in debug mode for performance reasons
400400
#[cfg(debug_assertions)]
401401
tnr.data.check_invariants(InvariantLevel::Executable)
402-
.map_err(|e| e.context(format!("check_plan_is_executable after optimizer rule: {}", rule.name())))?;
402+
.map_err(|e| e.context(format!("Invalid (non-executable) plan after Optimizer rule: {}", rule.name())))?;
403403

404404
Ok(tnr)
405405
});
@@ -462,13 +462,15 @@ impl Optimizer {
462462

463463
// verify that the optimizer passes only mutated what was permitted.
464464
assert_valid_optimization(&new_plan, &starting_schema).map_err(|e| {
465-
e.context("check_optimizer_specific_invariants after all passes")
465+
e.context("Check optimizer-specific invariants after all passes")
466466
})?;
467467

468468
// verify LP is valid, after the last optimizer pass.
469469
new_plan
470470
.check_invariants(InvariantLevel::Executable)
471-
.map_err(|e| e.context("Invalid plan after LP Optimizers"))?;
471+
.map_err(|e| {
472+
e.context("Invalid (non-executable) plan after LP Optimizers")
473+
})?;
472474

473475
log_plan("Final optimized plan", &new_plan);
474476
debug!("Optimizer took {} ms", start_time.elapsed().as_millis());
@@ -545,7 +547,7 @@ mod tests {
545547
assert_eq!(
546548
"Optimizer rule 'get table_scan rule' failed\n\
547549
caused by\n\
548-
check_optimizer_specific_invariants after optimizer rule: get table_scan rule\n\
550+
Check optimizer-specific invariants after optimizer rule: get table_scan rule\n\
549551
caused by\n\
550552
Internal error: Failed due to a difference in schemas, \
551553
original schema: DFSchema { inner: Schema { \

datafusion/optimizer/src/scalar_subquery_to_join.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ mod tests {
731731
.project(vec![col("customer.c_custkey")])?
732732
.build()?;
733733

734-
let expected = "Invalid plan after Analyzer\
734+
let expected = "Invalid (non-executable) plan after Analyzer\
735735
\ncaused by\
736736
\nError during planning: Scalar subquery should only return one column";
737737
assert_analyzer_check_err(vec![], plan, expected);
@@ -793,7 +793,7 @@ mod tests {
793793
.project(vec![col("customer.c_custkey")])?
794794
.build()?;
795795

796-
let expected = "Invalid plan after Analyzer\
796+
let expected = "Invalid (non-executable) plan after Analyzer\
797797
\ncaused by\
798798
\nError during planning: Scalar subquery should only return one column";
799799
assert_analyzer_check_err(vec![], plan, expected);

datafusion/sqllogictest/test_files/subquery.slt

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,17 +433,32 @@ logical_plan
433433
08)----------TableScan: t1 projection=[t1_int]
434434

435435
#invalid_scalar_subquery
436-
statement error DataFusion error: Invalid plan after Analyzer\ncaused by\nError during planning: Scalar subquery should only return one column, but found 2: t2.t2_id, t2.t2_name
436+
statement error
437437
SELECT t1_id, t1_name, t1_int, (select t2_id, t2_name FROM t2 WHERE t2.t2_id = t1.t1_int) FROM t1
438+
----
439+
DataFusion error: Invalid (non-executable) plan after Analyzer
440+
caused by
441+
Error during planning: Scalar subquery should only return one column, but found 2: t2.t2_id, t2.t2_name
442+
438443

439444
#subquery_not_allowed
440445
#In/Exist Subquery is not allowed in ORDER BY clause.
441-
statement error DataFusion error: Invalid plan after Analyzer\ncaused by\nError during planning: In/Exist subquery can only be used in Projection, Filter, TableScan, Window functions, Aggregate and Join plan nodes, but was used in \[Sort: t1.t1_int IN \(<subquery>\) ASC NULLS LAST\]
446+
statement error
442447
SELECT t1_id, t1_name, t1_int FROM t1 order by t1_int in (SELECT t2_int FROM t2 WHERE t1.t1_id > t1.t1_int)
448+
----
449+
DataFusion error: Invalid (non-executable) plan after Analyzer
450+
caused by
451+
Error during planning: In/Exist subquery can only be used in Projection, Filter, TableScan, Window functions, Aggregate and Join plan nodes, but was used in [Sort: t1.t1_int IN (<subquery>) ASC NULLS LAST]
452+
443453

444454
#non_aggregated_correlated_scalar_subquery
445-
statement error DataFusion error: Invalid plan after Analyzer\ncaused by\nError during planning: Correlated scalar subquery must be aggregated to return at most one row
455+
statement error
446456
SELECT t1_id, (SELECT t2_int FROM t2 WHERE t2.t2_int = t1.t1_int) as t2_int from t1
457+
----
458+
DataFusion error: Invalid (non-executable) plan after Analyzer
459+
caused by
460+
Error during planning: Correlated scalar subquery must be aggregated to return at most one row
461+
447462

448463
#non_aggregated_correlated_scalar_subquery_unique
449464
query II rowsort
@@ -456,12 +471,22 @@ SELECT t1_id, (SELECT t3_int FROM t3 WHERE t3.t3_id = t1.t1_id) as t3_int from t
456471

457472

458473
#non_aggregated_correlated_scalar_subquery
459-
statement error DataFusion error: Invalid plan after Analyzer\ncaused by\nError during planning: Correlated scalar subquery must be aggregated to return at most one row
474+
statement error
460475
SELECT t1_id, (SELECT t2_int FROM t2 WHERE t2.t2_int = t1_int group by t2_int) as t2_int from t1
476+
----
477+
DataFusion error: Invalid (non-executable) plan after Analyzer
478+
caused by
479+
Error during planning: Correlated scalar subquery must be aggregated to return at most one row
480+
461481

462482
#non_aggregated_correlated_scalar_subquery_with_limit
463-
statement error DataFusion error: Invalid plan after Analyzer\ncaused by\nError during planning: Correlated scalar subquery must be aggregated to return at most one row
483+
statement error
464484
SELECT t1_id, (SELECT t2_int FROM t2 WHERE t2.t2_int = t1.t1_int limit 2) as t2_int from t1
485+
----
486+
DataFusion error: Invalid (non-executable) plan after Analyzer
487+
caused by
488+
Error during planning: Correlated scalar subquery must be aggregated to return at most one row
489+
465490

466491
#non_aggregated_correlated_scalar_subquery_with_single_row
467492
query TT
@@ -523,8 +548,13 @@ logical_plan
523548
07)--TableScan: t1 projection=[t1_id]
524549

525550
#aggregated_correlated_scalar_subquery_with_extra_group_by_columns
526-
statement error DataFusion error: Invalid plan after Analyzer\ncaused by\nError during planning: A GROUP BY clause in a scalar correlated subquery cannot contain non-correlated columns
551+
statement error
527552
SELECT t1_id, (SELECT sum(t2_int) FROM t2 WHERE t2.t2_id = t1.t1_id group by t2_name) as t2_sum from t1
553+
----
554+
DataFusion error: Invalid (non-executable) plan after Analyzer
555+
caused by
556+
Error during planning: A GROUP BY clause in a scalar correlated subquery cannot contain non-correlated columns
557+
528558

529559
#support_agg_correlated_columns
530560
query TT

0 commit comments

Comments
 (0)