{"record":{"id":"a8e309fea061c438","repo":"apache/iceberg","slug":"invalid-session-catalog-sparksessioncatalog-a8e309","errorCode":null,"errorMessage":"Invalid session catalog: ${sparkSessionCatalog}","messagePattern":"Invalid session catalog: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java","lineNumber":438,"sourceCode":"      return;\n    }\n\n    Preconditions.checkArgument(\n        catalogHmsUri.equals(envHmsUri),\n        \"Inconsistent Hive metastore URIs: %s (Spark session) != %s (spark_catalog)\",\n        envHmsUri,\n        catalogHmsUri);\n  }\n\n  @Override\n  @SuppressWarnings(\"unchecked\")\n  public void setDelegateCatalog(CatalogPlugin sparkSessionCatalog) {\n    if (sparkSessionCatalog instanceof TableCatalog\n        && sparkSessionCatalog instanceof FunctionCatalog\n        && sparkSessionCatalog instanceof SupportsNamespaces) {\n      this.sessionCatalog = (T) sparkSessionCatalog;\n    } else {\n      throw new IllegalArgumentException(\"Invalid session catalog: \" + sparkSessionCatalog);\n    }\n  }\n\n  @Override\n  public String name() {\n    return catalogName;\n  }\n\n  private boolean useIceberg(String provider) {\n    if (provider == null || \"iceberg\".equalsIgnoreCase(provider)) {\n      return true;\n    } else if (createParquetAsIceberg && \"parquet\".equalsIgnoreCase(provider)) {\n      return true;\n    } else if (createAvroAsIceberg && \"avro\".equalsIgnoreCase(provider)) {\n      return true;\n    } else if (createOrcAsIceberg && \"orc\".equalsIgnoreCase(provider)) {\n      return true;\n    }","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java#L420-L456","documentation":"setDelegateCatalog requires the plugin supplied as the Spark session catalog to be simultaneously a TableCatalog, FunctionCatalog, and SupportsNamespaces. If the configured SparkSessionCatalog plugin lacks any of these interfaces, an IllegalArgumentException 'Invalid session catalog' is thrown, since Iceberg's session-catalog delegation cannot function without all three capabilities.","triggerScenarios":"Setting spark.sql.catalog.<name> to SparkSessionCatalog and calling setDelegateCatalog with a CatalogPlugin that is not a full table+function+namespace catalog (e.g. a view-only or function-only plugin).","commonSituations":"Custom or third-party CatalogPlugin implementations lacking SupportsNamespaces; Spark version changes altering the plugin interface; passing the Iceberg catalog itself as its own delegate by mistake.","solutions":["Configure a delegate that implements TableCatalog, FunctionCatalog, and SupportsNamespaces (e.g. Spark's built-in session catalog)","Check the plugin class's implemented interfaces before assigning it as delegate","Downgrade expectations: use plain SparkCatalog if no valid session delegate is available"],"exampleFix":"// before\ncatalog.setDelegateCatalog(functionOnlyPlugin);\n// after\nif (plugin instanceof TableCatalog && plugin instanceof FunctionCatalog && plugin instanceof SupportsNamespaces) {\n  catalog.setDelegateCatalog(plugin);\n}","handlingStrategy":"type-guard","validationCode":"// before wiring the delegate\nif (!(plugin instanceof TableCatalog) || !(plugin instanceof FunctionCatalog)\n    || !(plugin instanceof SupportsNamespaces)) {\n  throw new IllegalArgumentException(\"Delegate must implement TableCatalog, FunctionCatalog, SupportsNamespaces\");\n}","typeGuard":"boolean validDelegate(CatalogPlugin p) {\n  return p instanceof TableCatalog && p instanceof FunctionCatalog && p instanceof SupportsNamespaces;\n}","tryCatchPattern":"try {\n  sessionCatalog.setDelegateCatalog(plugin);\n} catch (IllegalArgumentException e) {\n  // use Spark's built-in session catalog as delegate\n  sessionCatalog.setDelegateCatalog(spark.sessionState().catalogManager().catalog(\"spark_catalog\").asTableCatalog());\n}","preventionTips":["Only pass Spark's built-in spark_catalog or equivalent full-featured plugins as delegates","Unit-test catalog plugin wiring after Spark upgrades","Read the plugin's implemented interfaces before configuring it"],"tags":["spark","catalog","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}