{"record":{"id":"a3de0685586d823f","repo":"apache/iceberg","slug":"nosuchtableexception-ident-a3de06","errorCode":null,"errorMessage":"NoSuchTableException(ident)","messagePattern":"NoSuchTableException\\(ident\\)","errorType":"exception","errorClass":"NoSuchTableException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java","lineNumber":235,"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":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java#L217-L253","documentation":"Thrown by SparkSessionCatalog.stageReplace when a REPLACE TABLE (via Spark session catalog) attempts to drop the existing table and the drop fails because the table does not exist. The catalog requires the target table to already exist for a replace operation; the underlying delegate catalog's dropTable(ident) returned false.","triggerScenarios":"Calling REPLACE TABLE ... USING iceberg (or catalogIdentifier replaceTable staged path) through the Spark session catalog when the identifier does not resolve to an existing table in the delegate session catalog.","commonSituations":"Typos in table name or namespace; table exists in a different catalog (e.g. default session catalog vs iceberg catalog) than the one being replaced; table was dropped concurrently by another job.","solutions":["Verify the table exists in the intended catalog: SHOW TABLES IN <catalog>.<namespace> and check the fully qualified identifier.","Use CREATE TABLE instead of REPLACE TABLE if the table is not supposed to exist yet.","Qualify the identifier with the correct catalog name so Spark routes the replace to the catalog that owns the table."],"exampleFix":"// before\nREPLACE TABLE prod.db.metrics USING iceberg AS SELECT ...\n// after (table does not exist yet)\nCREATE TABLE prod.db.metrics USING iceberg AS SELECT ...","handlingStrategy":"validation","validationCode":"// Spark SQL\nassert spark.catalog.tableExists(\"prod\", \"db\", \"metrics\") : \"table must exist before REPLACE TABLE\";","typeGuard":null,"tryCatchPattern":"try { spark.sql(\"REPLACE TABLE prod.db.metrics USING iceberg AS SELECT ...\") } catch (AnalysisException e) { if (e.getMessage().contains(\"no such table\")) { /* create instead of replace */ } else throw e; }","preventionTips":["Always qualify table identifiers with the owning catalog name.","Check tableExists before issuing REPLACE TABLE.","Use CREATE TABLE OR REPLACE semantics appropriate to your Spark version to avoid drop-then-create."],"tags":["spark","catalog","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-14T16:17:12.679Z"}