{"record":{"id":"f5d04d075c6bcf26","repo":"apache/iceberg","slug":"unable-to-get-partition-spec-for-table-s-f5d04d","errorCode":null,"errorMessage":"Unable to get partition spec for table: %s","messagePattern":"Unable to get partition spec for table: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkTableUtil.java","lineNumber":408,"sourceCode":"      } else {\n        List<SparkPartition> sourceTablePartitions =\n            getPartitions(spark, sourceTableIdent, partitionFilter);\n        if (sourceTablePartitions.isEmpty()) {\n          targetTable.newAppend().commit();\n        } else {\n          importSparkPartitions(\n              spark,\n              sourceTablePartitions,\n              targetTable,\n              spec,\n              stagingDir,\n              checkDuplicateFiles,\n              ignoreMissingFiles,\n              service);\n        }\n      }\n    } catch (AnalysisException e) {\n      throw SparkExceptionUtil.toUncheckedException(\n          e, \"Unable to get partition spec for table: %s\", sourceTableIdentWithDB);\n    }\n  }\n\n  /**\n   * Import files from an existing Spark table to an Iceberg table.\n   *\n   * <p>The import uses the Spark session to get table metadata. It assumes no operation is going on\n   * the original and target table and thus is not thread-safe.\n   *\n   * @param spark a Spark session\n   * @param sourceTableIdent an identifier of the source Spark table\n   * @param targetTable an Iceberg table where to import the data\n   * @param stagingDir a staging directory to store temporary manifest files\n   */\n  public static void importSparkTable(\n      SparkSession spark, TableIdentifier sourceTableIdent, Table targetTable, String stagingDir) {\n    importSparkTable(","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkTableUtil.java#L390-L426","documentation":"Thrown by SparkTableUtil.importSparkTable when resolving the source table's partition spec fails with a Spark AnalysisException — typically because the source table cannot be analyzed (does not exist, unresolved, or has a schema/catalog problem). The exception is rewrapped with this message naming the source table. It means the import could not even inspect the source table's structure.","triggerScenarios":"Calling SparkTableUtil.importSparkTable(spark, sourceTableIdent, targetTable, ...) where spark.sessionState.catalog / table lookup raises AnalysisException: source view unresolvable, source table missing from metastore, corrupted metastore entries, or unsupported source formats failing analysis.","commonSituations":"Importing from a temp view or a streaming source that cannot be analyzed; Hive metastore out of sync (table in catalog cache but deleted on disk); source is a Spark SQL view referencing dropped tables; Spark version drift where the source format plugin is missing.","solutions":["Run the source table query directly (SELECT * FROM src LIMIT 1 or DESCRIBE TABLE) to see the underlying AnalysisException and fix its root cause.","Confirm the source is a real catalog table (not a view/temp view) and that it exists in the intended catalog and database.","Refresh the catalog cache (REFRESH TABLE / spark.catalog.refreshTable) or restart the session if the metastore state changed underneath Spark.","If migrating, ensure the source format support (e.g. Hive, Parquet, ORC) is available in the Spark session."],"exampleFix":"// before\nSparkTableUtil.importSparkTable(spark, TableIdentifier.apply(\"events\", \"mydb\"), icebergTable);\n// after: verify analyzability first\nspark.sql(\"DESCRIBE TABLE mydb.events\"); // fails with the real root cause if broken\nSparkTableUtil.importSparkTable(spark, TableIdentifier.apply(\"events\", \"mydb\"), icebergTable);","handlingStrategy":"validation","validationCode":"try {\n  spark.sql(\"DESCRIBE TABLE \" + sourceTableIdentWithDB);\n} catch (Exception e) {\n  throw new IllegalArgumentException(\"Source not analyzable: \" + sourceTableIdentWithDB, e);\n}\nSparkTableUtil.importSparkTable(spark, ident, targetTable);","typeGuard":null,"tryCatchPattern":"try {\n  SparkTableUtil.importSparkTable(spark, ident, target);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to get partition spec for table\")) {\n    // inspect cause AnalysisException; verify source is a real analyzable table\n  } else throw e;\n}","preventionTips":["Run DESCRIBE TABLE on every source before scripted imports","Do not pass temp views or streaming sources to importSparkTable","Refresh the catalog cache after external metastore changes","Ensure source format support (Hive/Parquet/ORC) is present in the session"],"tags":["spark","analysis","table-migration"],"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"}