{"record":{"id":"cfc5ac5e8e5f7b5f","repo":"apache/iceberg","slug":"cannot-find-source-table-s-cfc5ac","errorCode":null,"errorMessage":"Cannot find source table %s","messagePattern":"Cannot find source table (.+?)","errorType":"exception","errorClass":"NoSuchTableException","httpStatus":null,"severity":"error","filePath":"spark/v3.5/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/v3.5/spark/src/main/java/org/apache/iceberg/spark/actions/MigrateTableSparkAction.java#L221-L257","documentation":"MigrateTableSparkAction backs up the source table by renaming it (destCatalog().renameTable(sourceTableIdent(), backupIdent)). Spark's catalog threw NoSuchTableException, so the action rethrows it as Iceberg's NoSuchTableException 'Cannot find source table %s' — the table you asked to migrate does not exist in the destination catalog.","triggerScenarios":"CALL spark_catalog.system.migrate(...) or SparkActions.get(spark).migrateTable(ident) where the source identifier is misspelled, the table lives in a different catalog/database, or the catalog lookup fails before the migration starts.","commonSituations":"Wrong three-part identifier, running against the wrong Spark session/catalog config, case sensitivity mismatch (spark.sql.caseSensitive), or the table being dropped by another process just before migration.","solutions":["Verify the table exists: run SHOW TABLES IN <catalog>.<db> or spark.catalog.tableExists(\"catalog.db.table\") with the exact identifier used in migrate().","Check the identifier's case and case-sensitivity setting (spark.sql.caseSensitive) and quoting.","Confirm the Spark session is configured for the catalog you expect (spark.sql.catalog.<name> entries) and that you are not silently hitting spark_default.","Re-run the migration after creating/restoring the missing source table."],"exampleFix":"// before\nspark.sql(\"CALL prod_catalog.system.migrate(table => 'events')\");\n// after\nspark.sql(\"CALL prod_catalog.system.migrate(table => 'analytics.events')\"); // fully-qualified, verified via SHOW TABLES","handlingStrategy":"validation","validationCode":"// Scala / SQL pre-check before migrate\nval ident = \"prod_catalog.analytics.events\"\nif (!spark.catalog.tableExists(ident))\n  throw new IllegalArgumentException(s\"Source table $ident does not exist\")","typeGuard":null,"tryCatchPattern":"try {\n  SparkActions.get(spark).migrateTable(ident).execute();\n} catch (org.apache.iceberg.exceptions.NoSuchTableException e) {\n  LOG.error(\"Verify identifier '{}' exists in the target catalog\", ident, e);\n}","preventionTips":["Always use fully-qualified three-part identifiers in CALL migrate/rewrite procedures.","Run SHOW TABLES IN <catalog>.<db> immediately before migrating.","Check spark.sql.catalog.* configuration matches the catalog name used in the identifier."],"tags":["spark","migrate-table","no-such-table","catalog"],"backgroundTag":"entity-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}