{"record":{"id":"9edcf4a7e4e63ce8","repo":"apache/iceberg","slug":"unknown-table-s-table-not-found-in-catalog-9edcf4","errorCode":null,"errorMessage":"Unknown table: %s. Table not found in catalog.","messagePattern":"Unknown table: (.+?)\\. Table not found in catalog\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkTableUtil.java","lineNumber":160,"sourceCode":"      Option<scala.collection.immutable.Map<String, String>> scalaPartitionFilter;\n      if (partitionFilter != null && !partitionFilter.isEmpty()) {\n        Builder<Tuple2<String, String>, scala.collection.immutable.Map<String, String>> builder =\n            Map$.MODULE$.newBuilder();\n        partitionFilter.forEach((key, value) -> builder.$plus$eq(Tuple2.apply(key, value)));\n        scalaPartitionFilter = Option.apply(builder.result());\n      } else {\n        scalaPartitionFilter = Option.empty();\n      }\n      Seq<CatalogTablePartition> partitions =\n          catalog.listPartitions(tableIdent, scalaPartitionFilter).toIndexedSeq();\n      return JavaConverters.seqAsJavaListConverter(partitions).asJava().stream()\n          .map(catalogPartition -> toSparkPartition(catalogPartition, catalogTable))\n          .collect(Collectors.toList());\n    } catch (NoSuchDatabaseException e) {\n      throw SparkExceptionUtil.toUncheckedException(\n          e, \"Unknown table: %s. Database not found in catalog.\", tableIdent);\n    } catch (NoSuchTableException e) {\n      throw SparkExceptionUtil.toUncheckedException(\n          e, \"Unknown table: %s. Table not found in catalog.\", tableIdent);\n    }\n  }\n\n  private static List<DataFile> listPartition(\n      SparkPartition partition,\n      PartitionSpec spec,\n      SerializableConfiguration conf,\n      MetricsConfig metricsConfig,\n      NameMapping mapping,\n      boolean ignoreMissingFiles,\n      ExecutorService service) {\n    try {\n      return TableMigrationUtil.listPartition(\n          partition.values,\n          partition.uri,\n          partition.format,\n          spec,","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkTableUtil.java#L142-L178","documentation":"SparkTableUtil.getPartitions wraps Spark catalog's NoSuchTableException into an unchecked Iceberg exception. It is thrown when the table identifier itself (database exists, table missing, or both unresolvable) cannot be found while listing partitions. SparkTableUtil rethrows because partition listing requires a live catalog table.","triggerScenarios":"Calling SparkTableUtil.getPartitions(sparkSession, tableIdent, partitionFilter) where catalog.listPartitions throws NoSuchTableException because the TableIdentifier does not resolve to an existing Spark table.","commonSituations":"Table name typo; table dropped or renamed before the import; pointing at an Iceberg table already migrated (it no longer exists in the session catalog as a Spark table); case-sensitivity issues with spark.sql.caseSensitive.","solutions":["Check table existence first with spark.catalog().tableExists(db, table) and correct the TableIdentifier.","Qualify the identifier with the correct database/catalog (catalog.db.table) instead of relying on the current database.","Catch the unchecked exception whose cause is NoSuchTableException and treat it as user-input validation failure."],"exampleFix":"// before\nSparkTableUtil.getPartitions(spark, new TableIdentifier(\"orders\", Some.apply(\"sales\")), null);\n// after\nif (!spark.catalog().tableExists(\"sales\", \"orders\")) { throw new IllegalArgumentException(\"sales.orders not found\"); }\nSparkTableUtil.getPartitions(spark, new TableIdentifier(\"orders\", Some.apply(\"sales\")), null);","handlingStrategy":"validation","validationCode":"TableIdentifier ident = ...;\nif (!spark.catalog().tableExists(ident.database().get(), ident.table())) {\n  throw new IllegalArgumentException(\"Table not found: \" + ident);\n}","typeGuard":null,"tryCatchPattern":"try { SparkTableUtil.getPartitions(spark, ident, null); } catch (RuntimeException e) { if (e.getCause() instanceof NoSuchTableException) { /* handle missing table */ } else throw e; }","preventionTips":["Check tableExists before import/listing","Qualify identifiers with explicit database","Watch for tables already migrated to Iceberg"],"tags":["spark","catalog","table-not-found","unchecked-exception"],"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"}