{"record":{"id":"d9ef9db81d37c19a","repo":"apache/iceberg","slug":"cannot-find-source-table-s-d9ef9d","errorCode":null,"errorMessage":"Cannot find source table %s","messagePattern":"Cannot find source table (.+?)","errorType":"exception","errorClass":"org.apache.iceberg.exceptions.NoSuchTableException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/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.2/spark/src/main/java/org/apache/iceberg/spark/actions/MigrateTableSparkAction.java#L221-L257","documentation":"MigrateTableSparkAction first renames the source table to a backup identifier before creating the new Iceberg table in its place. If destCatalog().renameTable throws Spark's NoSuchTableException (the source vanished between load and rename), it is converted into Iceberg's NoSuchTableException with this message.","triggerScenarios":"Calling MIGRATE and the source table is dropped by another session between action initialization and renameAndBackupSourceTable; wrong source identifier resolution in the destination catalog.","commonSituations":"Concurrent drop/overwrite of the source table; case-sensitive identifier mismatch causing renameTable to resolve a different catalog; a failed earlier migrate run left inconsistent catalog state.","solutions":["Verify the source table still exists: SHOW TABLES / DESCRIBE the identifier","Re-run the MIGRATE procedure once no concurrent jobs touch the source table","Check that the identifier resolves against the intended catalog (spark_catalog for the legacy source)"],"exampleFix":"// before\nCALL iceberg.system.migrate('db.src_tbl') -- src_tbl dropped concurrently\n// after\nSHOW TABLES IN db; -- confirm src_tbl exists\nCALL iceberg.system.migrate('db.src_tbl');","handlingStrategy":"try-catch","validationCode":"// Confirm the source exists and is quiescent before migrating\nspark.sql(\"DESCRIBE TABLE db.src_tbl\");","typeGuard":null,"tryCatchPattern":"try { migrateAction.execute(); } catch (NoSuchTableException e) { /* source disappeared: verify identifier, re-create or re-run when stable */ }","preventionTips":["Ensure no concurrent jobs drop or rename the source table during migration","Verify the identifier and catalog resolution before running MIGRATE","Re-run MIGRATE after transient concurrency issues; the action restores state on failure"],"tags":["spark","table-migration","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"}