@@ -49,6 +49,7 @@ use mz_sql::catalog::{
4949 BuiltinsConfig , CatalogError as SqlCatalogError , CatalogItemType , RoleMembership , RoleVars ,
5050} ;
5151use mz_sql:: func:: OP_IMPLS ;
52+ use mz_sql:: names:: CommentObjectId ;
5253use mz_sql:: rbac;
5354use mz_sql:: session:: user:: { MZ_SYSTEM_ROLE_ID , SYSTEM_USER } ;
5455use mz_sql:: session:: vars:: { SessionVars , SystemVars , VarError , VarInput } ;
@@ -727,10 +728,13 @@ fn add_new_remove_old_builtin_items_migration(
727728 }
728729 } ) ;
729730 let new_builtin_ids = txn. allocate_system_item_ids ( usize_to_u64 ( new_builtins. len ( ) ) ) ?;
730- let new_builtins = new_builtins. into_iter ( ) . zip ( new_builtin_ids. clone ( ) ) ;
731+ let new_builtins: Vec < _ > = new_builtins
732+ . into_iter ( )
733+ . zip ( new_builtin_ids. clone ( ) )
734+ . collect ( ) ;
731735
732736 // Look for migrated builtins.
733- for ( builtin, system_object_mapping, fingerprint) in existing_builtins {
737+ for ( builtin, system_object_mapping, fingerprint) in existing_builtins. iter ( ) . cloned ( ) {
734738 if system_object_mapping. unique_identifier . fingerprint != fingerprint {
735739 // `mz_storage_usage_by_shard` cannot be migrated for multiple reasons. Firstly,
736740 // it was cause the table to be truncated because the contents are not also
@@ -760,7 +764,7 @@ fn add_new_remove_old_builtin_items_migration(
760764 }
761765
762766 // Add new builtin items to catalog.
763- for ( ( builtin, fingerprint) , ( catalog_id, global_id) ) in new_builtins {
767+ for ( ( builtin, fingerprint) , ( catalog_id, global_id) ) in new_builtins. iter ( ) . cloned ( ) {
764768 new_builtin_mappings. push ( SystemObjectMapping {
765769 description : SystemObjectDescription {
766770 schema_name : builtin. schema ( ) . to_string ( ) ,
@@ -812,6 +816,85 @@ fn add_new_remove_old_builtin_items_migration(
812816 }
813817 txn. set_system_object_mappings ( new_builtin_mappings) ?;
814818
819+ // Update comments of all builtin objects
820+ let builtins_with_catalog_ids = existing_builtins
821+ . iter ( )
822+ . map ( |( b, m, _) | ( * b, m. unique_identifier . catalog_id ) )
823+ . chain (
824+ new_builtins
825+ . into_iter ( )
826+ . map ( |( ( b, _) , ( catalog_id, _) ) | ( b, catalog_id) ) ,
827+ ) ;
828+ for ( builtin, catalog_id) in builtins_with_catalog_ids {
829+ match builtin {
830+ Builtin :: Source ( source) => {
831+ match source. column_comments {
832+ Some ( ref column_comments) => {
833+ assert_eq ! ( column_comments. len( ) , source. desc. len( ) ) ;
834+ for ( col, & comment) in column_comments. iter ( ) . enumerate ( ) {
835+ txn. update_comment (
836+ CommentObjectId :: Source ( catalog_id) ,
837+ // Column indices are 1 based
838+ Some ( col + 1 ) ,
839+ Some ( comment. to_owned ( ) ) ,
840+ ) ?;
841+ }
842+ }
843+ None => {
844+ txn. drop_comments ( & BTreeSet :: from_iter ( [ CommentObjectId :: Source (
845+ catalog_id,
846+ ) ] ) ) ?;
847+ }
848+ }
849+ }
850+ Builtin :: View ( view) => {
851+ match view. column_comments {
852+ Some ( ref column_comments) => {
853+ for ( col, & comment) in column_comments. iter ( ) . enumerate ( ) {
854+ txn. update_comment (
855+ CommentObjectId :: View ( catalog_id) ,
856+ // Column indices are 1 based
857+ Some ( col + 1 ) ,
858+ Some ( comment. to_owned ( ) ) ,
859+ ) ?;
860+ }
861+ }
862+ None => {
863+ txn. drop_comments ( & BTreeSet :: from_iter ( [ CommentObjectId :: View (
864+ catalog_id,
865+ ) ] ) ) ?;
866+ }
867+ }
868+ }
869+ Builtin :: Table ( table) => {
870+ match table. column_comments {
871+ Some ( ref column_comments) => {
872+ assert_eq ! ( column_comments. len( ) , table. desc. len( ) ) ;
873+ for ( col, & comment) in column_comments. iter ( ) . enumerate ( ) {
874+ txn. update_comment (
875+ CommentObjectId :: Table ( catalog_id) ,
876+ // Column indices are 1 based
877+ Some ( col + 1 ) ,
878+ Some ( comment. to_owned ( ) ) ,
879+ ) ?;
880+ }
881+ }
882+ None => {
883+ txn. drop_comments ( & BTreeSet :: from_iter ( [ CommentObjectId :: Table (
884+ catalog_id,
885+ ) ] ) ) ?;
886+ }
887+ }
888+ }
889+ Builtin :: Log ( _)
890+ | Builtin :: Type ( _)
891+ | Builtin :: Func ( _)
892+ | Builtin :: ContinualTask ( _)
893+ | Builtin :: Index ( _)
894+ | Builtin :: Connection ( _) => { }
895+ }
896+ }
897+
815898 // Anything left in `system_object_mappings` must have been deleted and should be removed from
816899 // the catalog.
817900 let mut deleted_system_objects = BTreeSet :: new ( ) ;
0 commit comments