@@ -165,32 +165,40 @@ public synchronized void renameSchema(ConnectorSession session, String source, S
165165 }
166166 schemas .add (target );
167167
168- for (Map .Entry <SchemaTableName , Long > table : tableIds .entrySet ()) {
168+ Map <SchemaTableName , Long > newTableIds = new HashMap <>();
169+ for (Iterator <Map .Entry <SchemaTableName , Long >> iterator = tableIds .entrySet ().iterator (); iterator .hasNext (); ) {
170+ Map .Entry <SchemaTableName , Long > table = iterator .next ();
169171 if (table .getKey ().getSchemaName ().equals (source )) {
170- tableIds .remove (table . getKey () );
171- tableIds .put (new SchemaTableName (target , table .getKey ().getTableName ()), table .getValue ());
172+ iterator .remove ();
173+ newTableIds .put (new SchemaTableName (target , table .getKey ().getTableName ()), table .getValue ());
172174 }
173175 }
176+ tableIds .putAll (newTableIds );
174177
175- for (TableInfo table : tables .values ()) {
176- if (table .schemaName ().equals (source )) {
177- tables .put (table .id (), new TableInfo (table .id (), target , table .tableName (), table .columns (), false , table .dataFragments (), table .comment ()));
178- }
179- }
178+ tables .replaceAll ((tableId , table ) ->
179+ table .schemaName ().equals (source )
180+ ? new TableInfo (tableId , target , table .tableName (), table .columns (), table .truncated (), table .dataFragments (), table .comment ())
181+ : table );
180182
181- for (Map .Entry <SchemaTableName , ConnectorViewDefinition > view : views .entrySet ()) {
183+ Map <SchemaTableName , ConnectorViewDefinition > newViews = new HashMap <>();
184+ for (Iterator <Map .Entry <SchemaTableName , ConnectorViewDefinition >> iterator = views .entrySet ().iterator (); iterator .hasNext (); ) {
185+ Map .Entry <SchemaTableName , ConnectorViewDefinition > view = iterator .next ();
182186 if (view .getKey ().getSchemaName ().equals (source )) {
183- views .remove (view . getKey () );
184- views .put (new SchemaTableName (target , view .getKey ().getTableName ()), view .getValue ());
187+ iterator .remove ();
188+ newViews .put (new SchemaTableName (target , view .getKey ().getTableName ()), view .getValue ());
185189 }
186190 }
191+ views .putAll (newViews );
187192
188- for (Map .Entry <SchemaFunctionName , Map <String , LanguageFunction >> function : functions .entrySet ()) {
193+ Map <SchemaFunctionName , Map <String , LanguageFunction >> newFunctions = new HashMap <>();
194+ for (Iterator <Map .Entry <SchemaFunctionName , Map <String , LanguageFunction >>> iterator = functions .entrySet ().iterator (); iterator .hasNext (); ) {
195+ Map .Entry <SchemaFunctionName , Map <String , LanguageFunction >> function = iterator .next ();
189196 if (function .getKey ().getSchemaName ().equals (source )) {
190- functions .remove (function . getKey () );
191- functions .put (new SchemaFunctionName (target , function .getKey ().getFunctionName ()), function .getValue ());
197+ iterator .remove ();
198+ newFunctions .put (new SchemaFunctionName (target , function .getKey ().getFunctionName ()), function .getValue ());
192199 }
193200 }
201+ functions .putAll (newFunctions );
194202 }
195203
196204 @ GuardedBy ("this" )
0 commit comments