diff --git a/CHANGELOG.md b/CHANGELOG.md index c41fa0b27..85f6c87c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixes +- Stop `dbt docs generate` from emitting a `RuntimeWarning` per schema for catalog metadata columns that are absent from the results (thanks @emrekabalcii!) ([#1749](https://github.com/databricks/dbt-databricks/pull/1749) resolves [#1748](https://github.com/databricks/dbt-databricks/issues/1748)) - Unset tags on columns that a `table` model or incremental full refresh removes, so replacing a relation no longer fails with `CANNOT_DROP_TAGGED_COLUMN` when a removed column carries a governed tag ([#1707](https://github.com/databricks/dbt-databricks/pull/1707) resolves [#1684](https://github.com/databricks/dbt-databricks/issues/1684)) - Load wide seeds faster by resolving the placeholder and `parquet` cast types once per seed instead of once per cell ([#1722](https://github.com/databricks/dbt-databricks/pull/1722)) - Stop materialized views with a Compatibility Mode location from being dropped and lost when `use_safer_relation_operations` or a `partition_by` change would recreate them at the same location. Unchanged partitions now use `CREATE OR REPLACE`, and location or partition changes fail before anything is dropped ([#1727](https://github.com/databricks/dbt-databricks/pull/1727)) diff --git a/dbt/adapters/databricks/impl.py b/dbt/adapters/databricks/impl.py index f6e3c6aa1..6d69e8f6d 100644 --- a/dbt/adapters/databricks/impl.py +++ b/dbt/adapters/databricks/impl.py @@ -902,11 +902,11 @@ def _get_schema_for_catalog(self, catalog: str, schema: str, identifier: str) -> ) for relation, information in self._list_relations_with_information(schema_relation): columns.extend(self._get_columns_for_catalog(relation, information)) - # An empty input produces a 0-column table; force-typing absent columns - # would emit one RuntimeWarning per name. Skip the override in that case. - column_types = ( - build_type_tester(self.CATALOG_TEXT_ONLY_COLUMNS) if columns else DEFAULT_TYPE_TESTER - ) + # Rows omit None-valued keys, so a forced column can be absent from the table, and + # agate emits one RuntimeWarning per absent name. Only force the columns present. + present = {key for row in columns for key in row} + text_only = [col for col in self.CATALOG_TEXT_ONLY_COLUMNS if col in present] + column_types = build_type_tester(text_only) if text_only else DEFAULT_TYPE_TESTER return Table.from_object(columns, column_types=column_types) def _get_columns_for_catalog( # type: ignore[override] diff --git a/tests/unit/test_adapter.py b/tests/unit/test_adapter.py index fc81a9d26..18fe98628 100644 --- a/tests/unit/test_adapter.py +++ b/tests/unit/test_adapter.py @@ -570,6 +570,28 @@ def test_get_schema_for_catalog__no_columns_emits_no_warnings(self, _): table = adapter._get_schema_for_catalog("database", "schema", "name") assert len(table.rows) == 0 + @patch("dbt.adapters.databricks.api_client.DatabricksApiClient") + def test_get_schema_for_catalog__omitted_none_columns_emit_no_warnings(self, _): + # `to_column_dict` omits None-valued keys, so a schema with no owner or comments + # yields rows without `table_owner`, `table_comment` and `comment`. + row = { + k: v + for k, v in _catalog_row("12345").items() + if k not in ("table_owner", "table_comment", "comment") + } + with patch.object(DatabricksAdapter, "_list_relations_with_information") as list_info: + list_info.return_value = [(Mock(), "info")] + with patch.object(DatabricksAdapter, "_get_columns_for_catalog") as get_columns: + get_columns.return_value = [row] + adapter = DatabricksAdapter(Mock(flags={}), get_context("spawn")) + with warnings.catch_warnings(): + warnings.simplefilter("error", RuntimeWarning) + table = adapter._get_schema_for_catalog("cat", "schema", "name") + + assert "comment" not in table.column_names + types = dict(zip(table.column_names, table.column_types)) + assert isinstance(types["column_name"], agate.data_types.text.Text) + def test_simple_catalog_relation(self): self.maxDiff = None rel_type = DatabricksRelation.get_relation_type.Table