{"record":{"id":"2c66d6cddc006a60","repo":"apache/iceberg","slug":"table-does-not-exist","errorCode":null,"errorMessage":"Table does not exist: ","messagePattern":"Table does not exist: ","errorType":"exception","errorClass":"NoSuchTableException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java","lineNumber":266,"sourceCode":"  }\n\n  @Override\n  public StagedTable stageReplace(Identifier ident, TableInfo tableInfo)\n      throws NoSuchNamespaceException, NoSuchTableException {\n    String provider = tableInfo.properties().get(\"provider\");\n    TableCatalog catalog;\n    if (useIceberg(provider)) {\n      if (asStagingCatalog != null) {\n        return asStagingCatalog.stageReplace(ident, tableInfo);\n      }\n      catalog = icebergCatalog;\n    } else {\n      catalog = getSessionCatalog();\n    }\n\n    // attempt to drop the table and fail if it doesn't exist\n    if (!catalog.dropTable(ident)) {\n      throw new NoSuchTableException(ident);\n    }\n\n    try {\n      // create the table with the session catalog, then wrap it in a staged table that will delete\n      // to roll back\n      Table table = catalog.createTable(ident, tableInfo);\n      return new RollbackStagedTable(catalog, ident, table);\n\n    } catch (TableAlreadyExistsException e) {\n      // the table was deleted, but now already exists again. retry the replace.\n      return stageReplace(ident, tableInfo);\n    }\n  }\n\n  /**\n   * @deprecated since 1.12.0, use {@link #stageCreateOrReplace(Identifier, TableInfo)} instead.\n   */\n  @Deprecated","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java#L248-L284","documentation":"In SparkSessionCatalog.stageReplace, a CREATE OR REPLACE requires dropping the existing table first; if catalog.dropTable returns false the table was not found and NoSuchTableException is thrown. This surfaces when you replace a table that does not exist in a context that requires it to exist.","triggerScenarios":"Executing CREATE OR REPLACE TABLE in the Spark session catalog path where the target table does not exist and dropTable(ident) returns false; race condition where another job dropped the table between existence check and stageReplace.","commonSituations":"REPLACE on a table name with a typo or wrong namespace; table exists in another catalog but not in the one being used; concurrent jobs where one drops the table while another replaces it.","solutions":["Verify the fully qualified table name (catalog.namespace.table) exists with SHOW TABLES before REPLACE","Use CREATE OR REPLACE semantics on the correct Iceberg catalog; or create the table first with CREATE TABLE","Catch NoSuchTableException and fall back to CREATE TABLE AS SELECT instead of REPLACE"],"exampleFix":"// before\nspark.sql(\"CREATE OR REPLACE TABLE spark_catalog.db.tbl AS SELECT ...\");\n// after\nspark.sql(\"CREATE TABLE IF NOT EXISTS iceberg.db.tbl AS SELECT ... OR REPLACE if exists\");","handlingStrategy":"validation","validationCode":"// verify existence before CREATE OR REPLACE\nif (!catalog.tableExists(ident)) {\n  // create instead of replace\n  catalog.createTable(ident, schema, spec);\n}","typeGuard":null,"tryCatchPattern":"try {\n  spark.sql(\"CREATE OR REPLACE TABLE ...\");\n} catch (NoSuchTableException e) {\n  spark.sql(\"CREATE TABLE ... AS SELECT ...\");\n}","preventionTips":["Run SHOW TABLES to confirm the fully qualified name before REPLACE","Qualify catalog.namespace.table explicitly to avoid cross-catalog resolution surprises","Handle concurrent drop/replace races by retrying or falling back to CREATE"],"tags":["spark","catalog","no-such-table","replace"],"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-14T16:17:12.679Z"}