{"record":{"id":"cc3d4ad4d8b3c150","repo":"apache/iceberg","slug":"cannot-convert-identifier-s-to-namespace","errorCode":null,"errorMessage":"Cannot convert identifier '%s' to Namespace","messagePattern":"Cannot convert identifier '(.+?)' to Namespace","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"snowflake/src/main/java/org/apache/iceberg/snowflake/NamespaceHelpers.java","lineNumber":86,"sourceCode":"        namespaceScope);\n    return SnowflakeIdentifier.ofTable(\n        namespaceScope.databaseName(), namespaceScope.schemaName(), identifier.name());\n  }\n\n  /**\n   * Converts a SnowflakeIdentifier of type ROOT, DATABASE, or SCHEMA into an equivalent Iceberg\n   * Namespace; throws IllegalArgumentException if not an appropriate type.\n   */\n  public static Namespace toIcebergNamespace(SnowflakeIdentifier identifier) {\n    switch (identifier.type()) {\n      case ROOT:\n        return Namespace.empty();\n      case DATABASE:\n        return Namespace.of(identifier.databaseName());\n      case SCHEMA:\n        return Namespace.of(identifier.databaseName(), identifier.schemaName());\n      default:\n        throw new IllegalArgumentException(\n            String.format(\"Cannot convert identifier '%s' to Namespace\", identifier));\n    }\n  }\n\n  /**\n   * Converts a SnowflakeIdentifier to an equivalent Iceberg TableIdentifier; the identifier must be\n   * of type TABLE.\n   */\n  public static TableIdentifier toIcebergTableIdentifier(SnowflakeIdentifier identifier) {\n    Preconditions.checkArgument(\n        identifier.type() == SnowflakeIdentifier.Type.TABLE,\n        \"SnowflakeIdentifier must be type TABLE, got '%s'\",\n        identifier);\n    return TableIdentifier.of(\n        identifier.databaseName(), identifier.schemaName(), identifier.tableName());\n  }\n}\n","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/snowflake/src/main/java/org/apache/iceberg/snowflake/NamespaceHelpers.java#L68-L104","documentation":"NamespaceHelpers.toIcebergNamespace converts a SnowflakeIdentifier into an Iceberg Namespace. Only ROOT, DATABASE, and SCHEMA identifier types have namespace equivalents; a TABLE (or any other) identifier type reaches the default branch and throws IllegalArgumentException. The caller passed the wrong kind of SnowflakeIdentifier.","triggerScenarios":"Passing a SnowflakeIdentifier.ofTable(...) (or another non-namespace type) to code that converts identifiers to namespaces, e.g. when mapping listNamespaces results from custom SnowflakeClient implementations.","commonSituations":"Custom SnowflakeClient implementations returning TABLE-typed identifiers where DATABASE/SCHEMA results are expected; refactored code mixing toIcebergNamespace with toIcebergTableIdentifier; glue code converting identifiers of the wrong type.","solutions":["Only pass DATABASE or SCHEMA type SnowflakeIdentifiers to toIcebergNamespace","Use NamespaceHelpers.toIcebergTableIdentifier for TABLE-typed identifiers","Check identifier.type() and branch to the appropriate conversion helper before converting"],"exampleFix":"// before\nNamespace ns = NamespaceHelpers.toIcebergNamespace(tableId);\n// after\nNamespace ns = tableId.isTable()\n    ? null\n    : NamespaceHelpers.toIcebergNamespace(tableId);\nTableIdentifier tbl = NamespaceHelpers.toIcebergTableIdentifier(tableId);","handlingStrategy":"type-guard","validationCode":"if (id.type() != SnowflakeIdentifierType.DATABASE\n    && id.type() != SnowflakeIdentifierType.SCHEMA) {\n  throw new IllegalArgumentException(\"Not a namespace identifier: \" + id);\n}","typeGuard":"boolean isNamespaceIdentifier(SnowflakeIdentifier id) {\n  return id.type() == SnowflakeIdentifierType.DATABASE\n      || id.type() == SnowflakeIdentifierType.SCHEMA;\n}","tryCatchPattern":"try {\n  Namespace ns = NamespaceHelpers.toIcebergNamespace(id);\n} catch (IllegalArgumentException e) {\n  // use toIcebergTableIdentifier for TABLE identifiers instead\n}","preventionTips":["Match conversion helper to identifier type (toIcebergNamespace vs toIcebergTableIdentifier)","Check identifier.type() before converting","Keep custom SnowflakeClient implementations returning the documented identifier types","Add tests covering every SnowflakeIdentifierType"],"tags":["snowflake","identifier","conversion","validation"],"backgroundTag":"type-mismatch","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"}