@@ -738,26 +738,25 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
738738 for input in from {
739739 let current_name = extract_table_name ( & input) ;
740740
741- if let Some ( ( ref name, ref span) ) = current_name {
742- alias_spans. entry ( name. clone ( ) ) . or_insert ( * span) ;
741+ if let Some ( ( ref name, current_span) ) = current_name {
742+ if let Some ( prior_span) = alias_spans. get ( name) {
743+ let mut diagnostic = Diagnostic :: new_error (
744+ "duplicate table alias in FROM clause" ,
745+ current_span,
746+ ) ;
747+ if let Some ( span) = * prior_span {
748+ diagnostic = diagnostic
749+ . with_note ( "first defined here" , Some ( span) ) ;
750+ }
751+ return plan_err ! ( "duplicate table alias in FROM clause" )
752+ . map_err ( |e| e. with_diagnostic ( diagnostic) ) ;
753+ }
754+ alias_spans. insert ( name. clone ( ) , current_span) ;
743755 }
744756
745757 let right = self . plan_table_with_joins ( input, planner_context) ?;
746758
747- left = left. cross_join ( right) . map_err ( |e| {
748- if let Some ( ( ref name, ref current_span) ) = current_name
749- && let Some ( prior_span) =
750- alias_spans. get ( name) . copied ( ) . flatten ( )
751- {
752- let diagnostic = Diagnostic :: new_error (
753- "duplicate table alias in FROM clause" ,
754- * current_span,
755- )
756- . with_note ( "first defined here" , Some ( prior_span) ) ;
757- return e. with_diagnostic ( diagnostic) ;
758- }
759- e
760- } ) ?;
759+ left = left. cross_join ( right) ?;
761760 let left_schema = Some ( Arc :: clone ( left. schema ( ) ) ) ;
762761 planner_context. set_outer_from_schema ( left_schema) ;
763762 }
0 commit comments