{"record":{"id":"4ac7782b60d8c741","repo":"apache/iceberg","slug":"cannot-find-source-table-s-4ac778","errorCode":null,"errorMessage":"Cannot find source table %s","messagePattern":"Cannot find source table (.+?)","errorType":"exception","errorClass":"NoSuchTableException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/actions/MigrateTableSparkAction.java","lineNumber":239,"sourceCode":"  @Override\n  protected TableCatalog checkSourceCatalog(CatalogPlugin catalog) {\n    // currently the import code relies on being able to look up the table in the session catalog\n    Preconditions.checkArgument(\n        catalog instanceof SparkSessionCatalog,\n        \"Cannot migrate a table from a non-Iceberg Spark Session Catalog. Found %s of class %s as the source catalog.\",\n        catalog.name(),\n        catalog.getClass().getName());\n\n    return (TableCatalog) catalog;\n  }\n\n  private void renameAndBackupSourceTable() {\n    try {\n      LOG.info(\"Renaming {} as {} for backup\", sourceTableIdent(), backupIdent);\n      destCatalog().renameTable(sourceTableIdent(), backupIdent);\n\n    } catch (org.apache.spark.sql.catalyst.analysis.NoSuchTableException e) {\n      throw new NoSuchTableException(\"Cannot find source table %s\", sourceTableIdent());\n\n    } catch (org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException e) {\n      throw new AlreadyExistsException(\n          \"Cannot rename %s as %s for backup. The backup table already exists.\",\n          sourceTableIdent(), backupIdent);\n    }\n  }\n\n  private void restoreSourceTable() {\n    try {\n      LOG.info(\"Restoring {} from {}\", sourceTableIdent(), backupIdent);\n      destCatalog().renameTable(backupIdent, sourceTableIdent());\n\n    } catch (org.apache.spark.sql.catalyst.analysis.NoSuchTableException e) {\n      LOG.error(\n          \"Cannot restore the original table, the backup table {} cannot be found\", backupIdent, e);\n\n    } catch (org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException e) {","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/actions/MigrateTableSparkAction.java#L221-L257","documentation":"MigrateTableSparkAction's renameAndBackupSourceTable fails when renaming the original table to its backup identifier because Spark reports the source table no longer exists (NoSuchTableException), wrapped as an Iceberg NoSuchTableException.","triggerScenarios":"doExecute -> renameAndBackupSourceTable: destCatalog().renameTable(sourceTableIdent, backupIdent) when the source table has disappeared (or the identifier resolves differently) between load and rename — e.g. a concurrent drop, or the source table was already renamed to the backup name in a prior failed run.","commonSituations":"Re-running a failed migration where the source was already renamed as backup; another job/user dropped the table mid-migration; wrong catalog/table identifier casing.","solutions":["Check whether the backup table (e.g. db.tbl_BACKUP__) exists; if so restore it or drop it before re-running","Confirm the source table still exists with SHOW TABLES / DESCRIBE TABLE in the source catalog","Verify you are targeting the correct catalog (spark.sql.catalog settings) and the exact identifier","Re-run the migration only after the source table is present and no backup name collision exists"],"exampleFix":"// after a failed run where db.tbl_BACKUP__ exists\nspark.sql(\"ALTER TABLE db.tbl_BACKUP__ RENAME TO db.tbl\"); // restore source\nSparkActions.get(spark).migrateTable(\"db.tbl\").execute();","handlingStrategy":"validation","validationCode":"if (!spark.catalog().tableExists(sourceIdent)) { throw new IllegalStateException(\"source table missing\"); }\nif (spark.catalog().tableExists(backupIdent)) { restoreOrDropBackupFirst(); }","typeGuard":null,"tryCatchPattern":"try { action.execute(); } catch (NoSuchTableException e) { /* verify/restore source and backup state, then re-run */ }","preventionTips":["Verify source exists before migration","Handle leftover _BACKUP__ tables from failed runs","Avoid concurrent drops during migration","Use consistent catalog config"],"tags":["spark","migrate-table","rename","table-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}