File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,21 +40,17 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
4040 let cte_name_span =
4141 Span :: try_from_sqlparser_span ( cte. alias . name . span ) ;
4242 if planner_context. contains_cte ( & cte_name) {
43- let first_span = planner_context. get_cte_span ( & cte_name) ;
44- let mut diagnostic = Diagnostic :: new_error (
45- format ! (
46- "WITH query name {cte_name:?} specified more than once"
47- ) ,
48- cte_name_span,
43+ let msg = format ! (
44+ "WITH query name {cte_name:?} specified more than once"
4945 ) ;
50- if let Some ( first_span) = first_span {
46+ let mut diagnostic =
47+ Diagnostic :: new_error ( & msg, cte_name_span) ;
48+ if let Some ( first_span) = planner_context. get_cte_span ( & cte_name) {
5149 diagnostic =
5250 diagnostic. with_note ( "previously defined here" , Some ( first_span) ) ;
5351 }
54- return plan_err ! (
55- "WITH query name {cte_name:?} specified more than once"
56- )
57- . map_err ( |e| e. with_diagnostic ( diagnostic) ) ;
52+ return plan_err ! ( "{msg}" )
53+ . map_err ( |e| e. with_diagnostic ( diagnostic) ) ;
5854 }
5955
6056 // Create a logical plan for the CTE
Original file line number Diff line number Diff line change @@ -738,27 +738,25 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
738738 planner_context. set_outer_from_schema ( left_schema)
739739 } ;
740740 for input in from {
741- let current_span =
742- Span :: try_from_sqlparser_span ( input. relation . span ( ) ) ;
743741 let current_name = extract_table_name ( & input) ;
744742
745- if let Some ( ( ref name, _ ) ) = current_name {
746- alias_spans. entry ( name. clone ( ) ) . or_insert ( current_span ) ;
743+ if let Some ( ( ref name, ref span ) ) = current_name {
744+ alias_spans. entry ( name. clone ( ) ) . or_insert ( * span ) ;
747745 }
748746
749747 let right =
750748 self . plan_table_with_joins ( input, planner_context) ?;
751749
752750 left = left. cross_join ( right) . map_err ( |e| {
753- if let Some ( ( ref name, _ ) ) = current_name {
751+ if let Some ( ( ref name, ref current_span ) ) = current_name {
754752 if let Some ( prior_span) =
755753 alias_spans. get ( name) . copied ( ) . flatten ( )
756754 {
757- let mut diagnostic = Diagnostic :: new_error (
755+ let diagnostic = Diagnostic :: new_error (
758756 "duplicate table alias in FROM clause" ,
759- current_span,
760- ) ;
761- diagnostic = diagnostic . with_note (
757+ * current_span,
758+ )
759+ . with_note (
762760 "first defined here" ,
763761 Some ( prior_span) ,
764762 ) ;
You can’t perform that action at this time.
0 commit comments