{"record":{"id":"2bbb271ef0d34d47","repo":"apache/iceberg","slug":"table-does-not-exist-ident","errorCode":null,"errorMessage":"Table does not exist: ident","messagePattern":"Table does not exist: ident","errorType":"exception","errorClass":"NoSuchTableException","httpStatus":404,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java","lineNumber":234,"sourceCode":"\n  @Override\n  public StagedTable stageReplace(\n      Identifier ident, StructType schema, Transform[] partitions, Map<String, String> properties)\n      throws NoSuchNamespaceException, NoSuchTableException {\n    String provider = properties.get(\"provider\");\n    TableCatalog catalog;\n    if (useIceberg(provider)) {\n      if (asStagingCatalog != null) {\n        return asStagingCatalog.stageReplace(ident, schema, partitions, properties);\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, schema, partitions, properties);\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, schema, partitions, properties);\n    }\n  }\n\n  @Override\n  public StagedTable stageCreateOrReplace(\n      Identifier ident, StructType schema, Transform[] partitions, Map<String, String> properties)\n      throws NoSuchNamespaceException {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java#L216-L252","documentation":"Thrown by SparkSessionCatalog.stageReplace (used by CREATE OR REPLACE TABLE) when the underlying session catalog's dropTable(ident) returns false, i.e. the table to be replaced does not exist. Iceberg treats REPLACE as requiring an existing table in this path, so the operation aborts before creating the new table.","triggerScenarios":"Executing CREATE OR REPLACE TABLE via SparkSessionCatalog where the delegate session catalog's dropTable(ident) returns false — table absent in the session catalog; or the identifier resolves to a V1 session table path where drop is unsupported/failed.","commonSituations":"CREATE OR REPLACE TABLE on a table name that only exists in the main Iceberg catalog but the SQL routed to the session catalog (or vice versa); typos in table name; using REPLACE for migration when the table was never created; partition-transform confusion causing identifier mismatch.","solutions":["Create the table first if it doesn't exist (CREATE TABLE), or use CREATE TABLE IF NOT EXISTS semantics.","Check the identifier/catalog routing: ensure the table exists in the catalog the statement targets (qualify with catalog name in SQL).","List tables in the namespace (SHOW TABLES) to confirm exact name and namespace.","If a stale catalog cache is involved, refresh the Spark catalog or restart the session."],"exampleFix":"// before\nspark.sql(\"CREATE OR REPLACE TABLE local.db.events AS SELECT ...\");\n// after\nif (!spark.catalog().tableExists(\"local.db.events\")) {\n  spark.sql(\"CREATE TABLE local.db.events AS SELECT ...\");\n} else {\n  spark.sql(\"CREATE OR REPLACE TABLE local.db.events AS SELECT ...\");\n}","handlingStrategy":"validation","validationCode":"if (!spark.catalog().tableExists(identString)) { /* create instead of replace */ }","typeGuard":null,"tryCatchPattern":"try { spark.sql(\"CREATE OR REPLACE TABLE ...\"); } catch (NoSuchTableException e) { spark.sql(\"CREATE TABLE ...\"); }","preventionTips":["Confirm table existence with SHOW TABLES before REPLACE","Qualify identifiers with the intended catalog name","Distinguish create vs replace in pipeline SQL generation"],"tags":["spark","table","not-found","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"}