Skip to content

Commit 10f6946

Browse files
committed
cargo fmt
1 parent fbdbc61 commit 10f6946

4 files changed

Lines changed: 23 additions & 33 deletions

File tree

datafusion/sql/src/cte.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,16 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
3737
for cte in with.cte_tables {
3838
// A `WITH` block can't use the same name more than once
3939
let cte_name = self.ident_normalizer.normalize(cte.alias.name.clone());
40-
let cte_name_span =
41-
Span::try_from_sqlparser_span(cte.alias.name.span);
40+
let cte_name_span = Span::try_from_sqlparser_span(cte.alias.name.span);
4241
if planner_context.contains_cte(&cte_name) {
43-
let msg = format!(
44-
"WITH query name {cte_name:?} specified more than once"
45-
);
46-
let mut diagnostic =
47-
Diagnostic::new_error(&msg, cte_name_span);
42+
let msg =
43+
format!("WITH query name {cte_name:?} specified more than once");
44+
let mut diagnostic = Diagnostic::new_error(&msg, cte_name_span);
4845
if let Some(first_span) = planner_context.get_cte_span(&cte_name) {
4946
diagnostic =
5047
diagnostic.with_note("previously defined here", Some(first_span));
5148
}
52-
return plan_err!("{msg}")
53-
.map_err(|e| e.with_diagnostic(diagnostic));
49+
return plan_err!("{msg}").map_err(|e| e.with_diagnostic(diagnostic));
5450
}
5551

5652
// Create a logical plan for the CTE

datafusion/sql/src/planner.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use datafusion_common::TableReference;
2727
use datafusion_common::config::SqlParserOptions;
2828
use datafusion_common::datatype::{DataTypeExt, FieldExt};
2929
use datafusion_common::error::add_possible_columns_to_diag;
30-
use datafusion_common::{DFSchema, DataFusionError, Result, Span, not_impl_err, plan_err};
30+
use datafusion_common::{
31+
DFSchema, DataFusionError, Result, Span, not_impl_err, plan_err,
32+
};
3133
use datafusion_common::{
3234
DFSchemaRef, Diagnostic, SchemaError, field_not_found, internal_err,
3335
plan_datafusion_err,

datafusion/sql/src/select.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use crate::utils::{
2929

3030
use datafusion_common::error::DataFusionErrorBuilder;
3131
use datafusion_common::tree_node::{TreeNode, TreeNodeRecursion};
32-
use datafusion_common::{Column, DFSchema, Diagnostic, Result, Span, not_impl_err, plan_err};
32+
use datafusion_common::{
33+
Column, DFSchema, Diagnostic, Result, Span, not_impl_err, plan_err,
34+
};
3335
use datafusion_common::{RecursionUnnestOption, UnnestOptions};
3436
use datafusion_expr::expr::{Alias, PlannedReplaceSelectItem, WildcardOptions};
3537
use datafusion_expr::expr_rewriter::{
@@ -694,33 +696,29 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
694696
_ => {
695697
let extract_table_name =
696698
|t: &TableWithJoins| -> Option<(String, Option<Span>)> {
697-
let span =
698-
Span::try_from_sqlparser_span(t.relation.span());
699+
let span = Span::try_from_sqlparser_span(t.relation.span());
699700
match &t.relation {
700701
TableFactor::Table { alias: Some(a), .. } => {
701-
let name = self
702-
.ident_normalizer
703-
.normalize(a.name.clone());
702+
let name =
703+
self.ident_normalizer.normalize(a.name.clone());
704704
Some((name, span))
705705
}
706-
TableFactor::Table { name, alias: None, .. } => {
706+
TableFactor::Table {
707+
name, alias: None, ..
708+
} => {
707709
let table_name = name
708710
.0
709711
.iter()
710712
.filter_map(|p| p.as_ident())
711-
.map(|id| {
712-
self.ident_normalizer
713-
.normalize(id.clone())
714-
})
713+
.map(|id| self.ident_normalizer.normalize(id.clone()))
715714
.last()?;
716715
Some((table_name, span))
717716
}
718717
_ => None,
719718
}
720719
};
721720

722-
let mut alias_spans: HashMap<String, Option<Span>> =
723-
HashMap::new();
721+
let mut alias_spans: HashMap<String, Option<Span>> = HashMap::new();
724722

725723
let mut from = from.into_iter();
726724
let first = from.next().unwrap();
@@ -744,8 +742,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
744742
alias_spans.entry(name.clone()).or_insert(*span);
745743
}
746744

747-
let right =
748-
self.plan_table_with_joins(input, planner_context)?;
745+
let right = self.plan_table_with_joins(input, planner_context)?;
749746

750747
left = left.cross_join(right).map_err(|e| {
751748
if let Some((ref name, ref current_span)) = current_name {
@@ -756,10 +753,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
756753
"duplicate table alias in FROM clause",
757754
*current_span,
758755
)
759-
.with_note(
760-
"first defined here",
761-
Some(prior_span),
762-
);
756+
.with_note("first defined here", Some(prior_span));
763757
return e.with_diagnostic(diagnostic);
764758
}
765759
}

datafusion/sql/tests/cases/diagnostic.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,7 @@ fn test_syntax_error() -> Result<()> {
393393

394394
#[test]
395395
fn test_duplicate_cte_name() -> Result<()> {
396-
let query =
397-
"WITH /*a*/cte/*a*/ AS (SELECT 1 AS col), /*b*/cte/*b*/ AS (SELECT 2 AS col) SELECT 1";
396+
let query = "WITH /*a*/cte/*a*/ AS (SELECT 1 AS col), /*b*/cte/*b*/ AS (SELECT 2 AS col) SELECT 1";
398397
let spans = get_spans(query);
399398
let diag = do_query(query);
400399
assert_snapshot!(diag.message, @r#"WITH query name "cte" specified more than once"#);
@@ -420,8 +419,7 @@ fn test_duplicate_table_alias() -> Result<()> {
420419

421420
#[test]
422421
fn test_duplicate_table_alias_not_first() -> Result<()> {
423-
let query =
424-
"SELECT * FROM person a, /*b*/test_decimal b/*b*/, /*c*/person b/*c*/";
422+
let query = "SELECT * FROM person a, /*b*/test_decimal b/*b*/, /*c*/person b/*c*/";
425423
let spans = get_spans(query);
426424
let diag = do_query(query);
427425
assert_snapshot!(diag.message, @"duplicate table alias in FROM clause");

0 commit comments

Comments
 (0)