Skip to content

Fix: Python models emitting parquet format for managed Iceberg (#1591)#1593

Merged
sd-db merged 5 commits into
databricks:mainfrom
Divya-Kovvuru-0802:fix/1591-python-managed-iceberg-format
Jul 20, 2026
Merged

Fix: Python models emitting parquet format for managed Iceberg (#1591)#1593
sd-db merged 5 commits into
databricks:mainfrom
Divya-Kovvuru-0802:fix/1591-python-managed-iceberg-format

Conversation

@Divya-Kovvuru-0802

Copy link
Copy Markdown
Contributor

Resolves #1591

Description

Python models configured with table_format='iceberg' and the use_managed_iceberg behavior flag failed to materialize with:

INVALID_PARAMETER_VALUE.MANAGED_TABLE_FORMAT: Only Delta is supported for managed tables. Provided datasource format is PARQUET.

Root cause: adapter.resolve_file_format returns the "parquet" sentinel for managed Iceberg. That sentinel is only meaningful to the SQL path, where file_format_clause overrides it to using iceberg. The PySpark writer in python.sql had no such override and emitted .format("parquet") verbatim into the generated saveAsTable(...) call, which Unity Catalog rejects for managed tables.

The equivalent SQL model (table_format='iceberg' + use_managed_iceberg) succeeds, and a Python model without table_format='iceberg' (default Delta) also succeeds — only the Python + managed-Iceberg combination failed.

Fix: Add a py_resolve_writer_format() macro that mirrors the SQL override — it returns 'iceberg' when table_format='iceberg' and use_managed_iceberg is enabled, and otherwise defers to resolve_file_format (unchanged behavior for delta and all other formats). It is used in both writer paths: py_get_writer_options (non-incremental / table) and create_python_intermediate_table (incremental staging).

resolve_file_format itself is intentionally left unchanged, so the 15 SQL-path consumers of the sentinel are unaffected.

Verification

Verified end-to-end against a DBR 18.2 all-purpose cluster on Unity Catalog (dbt-core 1.11.12, dbt-databricks from this branch):

Scenario Before After
SQL model, managed Iceberg (control) ✅ pass ✅ pass (unchanged)
Python table model, managed Iceberg MANAGED_TABLE_FORMAT ✅ creates MANAGED table, UniForm Iceberg enabled
Python incremental model — initial build
Python incremental model — merge (staging table) .format("iceberg") for __dbt_tmp, merge succeeds

Confirmed the resulting table is table_type=MANAGED with delta.enablemanagedicebergtable=true and delta.universalFormat.enabledFormats=iceberg — matching the working SQL path.

Unit tests: tests/unit/macros/adapters/test_python_macros.py (2 new cases: managed-iceberg → iceberg, iceberg-without-flag → delta); full macro suite (237) passes.

Checklist

  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.
  • [Optional] I have run /dbt-databricks-pr-ready (AI agent skill in .claude/skills/) and addressed its merge-readiness feedback

This pull request and its description were written by Isaac.

Python models configured with table_format='iceberg' and the
use_managed_iceberg behavior flag failed to materialize with:

  INVALID_PARAMETER_VALUE.MANAGED_TABLE_FORMAT: Only Delta is supported
  for managed tables. Provided datasource format is PARQUET.

adapter.resolve_file_format returns the "parquet" sentinel for managed
Iceberg. That sentinel is only meaningful to the SQL path, where
file_format_clause overrides it to `using iceberg`. The PySpark writer
had no such override and emitted `.format("parquet")` verbatim into the
generated saveAsTable call, which Unity Catalog rejects for managed
tables.

Add a py_resolve_writer_format() macro that mirrors the SQL override:
it returns 'iceberg' when table_format='iceberg' and use_managed_iceberg
is enabled, and otherwise defers to resolve_file_format (unchanged
behavior for delta and all other formats). Use it in both the
py_get_writer_options and create_python_intermediate_table (incremental
staging) writer paths.

Verified end-to-end against a DBR 18.2 cluster: non-incremental and
incremental (build + merge) managed Iceberg Python models now create
MANAGED tables with UniForm Iceberg enabled; the equivalent SQL path is
unchanged.

Resolves databricks#1591

Signed-off-by: Divya Siruvuri <divyasiruvuri@gmail.com>
Comment thread dbt/include/databricks/macros/adapters/python.sql
Comment thread dbt/include/databricks/macros/adapters/python.sql Outdated

@sd-db sd-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a functional test for live verification, overall PR looks good. Have added some minor commits, should be good to merge once resolved.

@sd-db sd-db changed the title Fix Python models emitting parquet format for managed Iceberg (#1591) Fix: Python models emitting parquet format for managed Iceberg (#1591) Jul 17, 2026
@github-actions

Copy link
Copy Markdown

Coverage report

This PR does not seem to contain any modification to coverable code.

@sd-db
sd-db merged commit fc1b0ab into databricks:main Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python models fail with MANAGED_TABLE_FORMAT error when use_managed_iceberg=true

2 participants