dbt-labs / dbt-labs/dbt

[Databricks] Migrate `adapter.yaml_quote_backtick_values` to Jinja

Open
#16,283 0 comments 0 reactions 0 assignees View on GitHub
adapter:databricks area:adapters triage
Dominant language
Rust
Stars
13.8k
Forks
2.6k
Avg merge
21h 31m
Merged PRs (30d)
56

Description

Recently, we merged a PR that added a new adapter method, `yaml_quote_backtick_values`. This method is only supported for the Databricks adapter. Generally, we want to avoid adding adapter methods unless necessary.

# On Adapter Methods
Our adapter methods are defined and added to the `adapter` object in this file:
https://github.com/dbt-labs/dbt-core/blob/49b9ad23b0a0a12c46e8ff8b1676390f149bc763/crates/dbt-adapter/src/adapter/mod.rs#L3864

Adapter methods are usually a good idea to add when:
- they apply broadly to all adapters
- they require some kind of communication with the warehouse
- they are too complicated to implement in Jinja

A good example of a good adapter method is `get_columns_in_relation`, which is supported for all the adapters and queries the warehouse.

Over time, our list of adapter methods has grown significantly, and many of the methods are ones that do not have to be a part of the `adapter` object.

# Implementation
Let's make `adapter.yaml_quote_backtick_values` a Jinja helper instead of an adapter method. The implementation is doable in Jinja since it just uses a regex to add quotes:
https://github.com/dbt-labs/dbt-core/blob/49b9ad23b0a0a12c46e8ff8b1676390f149bc763/crates/dbt-adapter/src/relation/databricks/metric_view.rs#L11-L20

We can add a `helpers.sql` to the `metric_view` macro [folder](https://github.com/dbt-labs/dbt-core/tree/49b9ad23b0a0a12c46e8ff8b1676390f149bc763/crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/metric_view). The method is only called in two places: [alter.sql](https://github.com/dbt-labs/dbt-core/blob/49b9ad23b0a0a12c46e8ff8b1676390f149bc763/crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/metric_view/alter.sql#L34) and [create.sql](https://github.com/dbt-labs/dbt-core/blob/main/crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/metric_view/create.sql). We can replace them with calls to a Jinja-only helper that uses the `re` [module](https://docs.getdbt.com/reference/dbt-jinja-functions/modules?version=2#re).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.