{"record":{"id":"3ab8eb1b1c906c6a","repo":"apache/iceberg","slug":"nosuchtableexception-ident-3ab8eb","errorCode":null,"errorMessage":"NoSuchTableException: <ident>","messagePattern":"NoSuchTableException: <ident>","errorType":"exception","errorClass":"org.apache.spark.sql.catalyst.analysis.NoSuchTableException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java","lineNumber":257,"sourceCode":"    }\n  }\n\n  @Override\n  public StagedTable stageReplace(\n      Identifier ident, StructType schema, Transform[] transforms, Map<String, String> properties)\n      throws NoSuchTableException {\n    Schema icebergSchema = SparkSchemaUtil.convert(schema);\n    try {\n      Catalog.TableBuilder builder = newBuilder(ident, icebergSchema);\n      Transaction transaction =\n          builder\n              .withPartitionSpec(Spark3Util.toPartitionSpec(icebergSchema, transforms))\n              .withLocation(properties.get(\"location\"))\n              .withProperties(Spark3Util.rebuildCreateProperties(properties))\n              .replaceTransaction();\n      return new StagedSparkTable(transaction);\n    } catch (org.apache.iceberg.exceptions.NoSuchTableException e) {\n      throw new NoSuchTableException(ident);\n    }\n  }\n\n  @Override\n  public StagedTable stageCreateOrReplace(\n      Identifier ident, StructType schema, Transform[] transforms, Map<String, String> properties) {\n    Schema icebergSchema = SparkSchemaUtil.convert(schema);\n    Catalog.TableBuilder builder = newBuilder(ident, icebergSchema);\n    Transaction transaction =\n        builder\n            .withPartitionSpec(Spark3Util.toPartitionSpec(icebergSchema, transforms))\n            .withLocation(properties.get(\"location\"))\n            .withProperties(Spark3Util.rebuildCreateProperties(properties))\n            .createOrReplaceTransaction();\n    return new StagedSparkTable(transaction);\n  }\n\n  @Override","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java#L239-L275","documentation":"stageReplace (backing REPLACE TABLE / staged replace transactions) requires the target table to already exist. If the Iceberg catalog reports NoSuchTableException, Spark translates it into Spark's NoSuchTableException with the identifier.","triggerScenarios":"Executing REPLACE TABLE or CREATE OR REPLACE via the staged-replace path when the identifier does not exist in the catalog; typo in table name or wrong namespace/catalog qualification.","commonSituations":"REPLACE TABLE run against a name that was dropped concurrently; misspelled table names; using a different default catalog than where the table lives.","solutions":["Verify the table exists (SHOW TABLES IN catalog.db) and correct the identifier.","Use CREATE TABLE if the table genuinely should be created new.","Fully qualify catalog.namespace.table to ensure resolution against the intended catalog.","Catch NoSuchTableException and branch to create-vs-replace logic."],"exampleFix":"-- before\nREPLACE TABLE catalog.db.t AS SELECT ...; -- throws if t missing\n-- after\nCREATE TABLE IF NOT EXISTS catalog.db.t AS SELECT ...;","handlingStrategy":"try-catch","validationCode":"-- Spark SQL precheck\nSHOW TABLES IN catalog.db LIKE 't';","typeGuard":null,"tryCatchPattern":"try {\n  spark.sql(\"REPLACE TABLE catalog.db.t AS SELECT ...\");\n} catch (NoSuchTableException e) {\n  spark.sql(\"CREATE TABLE IF NOT EXISTS catalog.db.t AS SELECT ...\");\n}","preventionTips":["Verify table existence before REPLACE; fall back to CREATE when absent","Fully qualify identifiers to avoid resolving against the wrong catalog","Watch for concurrent DROPs between your existence check and replace","Catch NoSuchTableException explicitly for create-or-replace flows"],"tags":["spark","ddl","replace-table","no-such-table"],"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-23T08:17:48.524Z"}