@@ -622,24 +622,41 @@ pub fn object_name_to_table_reference(
622622 idents_to_table_reference ( idents, enable_normalization)
623623}
624624
625+ struct IdentTaker ( Vec < Ident > ) ;
626+ /// Take the next identifier from the back of idents, panic'ing if
627+ /// there are none left
628+ impl IdentTaker {
629+ fn take ( & mut self , enable_normalization : bool ) -> String {
630+ let ident = self . 0 . pop ( ) . expect ( "no more identifiers" ) ;
631+ IdentNormalizer :: new ( enable_normalization) . normalize ( ident)
632+ }
633+ }
634+
635+ // impl Display for a nicer error message
636+ impl std:: fmt:: Display for IdentTaker {
637+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
638+ let mut first = true ;
639+ for ident in self . 0 . iter ( ) {
640+ if !first {
641+ write ! ( f, "." ) ?;
642+ }
643+ write ! ( f, "{}" , ident) ?;
644+ first = false ;
645+ }
646+
647+ Ok ( ( ) )
648+ }
649+ }
650+
625651/// Create a [`TableReference`] after normalizing the specified identifier
626652pub ( crate ) fn idents_to_table_reference (
627653 idents : Vec < Ident > ,
628654 enable_normalization : bool ,
629655) -> Result < TableReference > {
630- struct IdentTaker ( Vec < Ident > ) ;
631- /// Take the next identifier from the back of idents, panic'ing if
632- /// there are none left
633- impl IdentTaker {
634- fn take ( & mut self , enable_normalization : bool ) -> String {
635- let ident = self . 0 . pop ( ) . expect ( "no more identifiers" ) ;
636- IdentNormalizer :: new ( enable_normalization) . normalize ( ident)
637- }
638- }
639-
640656 let mut taker = IdentTaker ( idents) ;
657+ let num_idents = taker. 0 . len ( ) ;
641658
642- match taker . 0 . len ( ) {
659+ match num_idents {
643660 1 => {
644661 let table = taker. take ( enable_normalization) ;
645662 Ok ( TableReference :: bare ( table) )
@@ -655,7 +672,11 @@ pub(crate) fn idents_to_table_reference(
655672 let catalog = taker. take ( enable_normalization) ;
656673 Ok ( TableReference :: full ( catalog, schema, table) )
657674 }
658- _ => plan_err ! ( "Unsupported compound identifier '{:?}'" , taker. 0 ) ,
675+ _ => plan_err ! (
676+ "Unsupported compound identifier '{}'. Expected 1, 2 or 3 parts, got {}" ,
677+ taker,
678+ num_idents
679+ ) ,
659680 }
660681}
661682
0 commit comments