diff --git a/.changes/1.0.0.md b/.changes/1.0.0.md
index b6cc44a9f..d381d635c 100644
--- a/.changes/1.0.0.md
+++ b/.changes/1.0.0.md
@@ -1,4 +1,4 @@
-## dbt-adapter 1.0.0 - April 01, 2024
+## dbt-adapters 1.0.0 - April 01, 2024
### Fixes
diff --git a/.changes/1.1.0.md b/.changes/1.1.0.md
index c43ef9aa9..9e7db78ed 100644
--- a/.changes/1.1.0.md
+++ b/.changes/1.1.0.md
@@ -1,4 +1,4 @@
-## dbt-adapter 1.1.0 - May 01, 2024
+## dbt-adapters 1.1.0 - May 01, 2024
### Features
diff --git a/.changes/1.1.1.md b/.changes/1.1.1.md
index 0a28c3ad0..a1c38c88d 100644
--- a/.changes/1.1.1.md
+++ b/.changes/1.1.1.md
@@ -1,4 +1,4 @@
-## dbt-adapter 1.1.1 - May 07, 2024
+## dbt-adapters 1.1.1 - May 07, 2024
### Features
diff --git a/.changes/1.2.1.md b/.changes/1.2.1.md
index f838b7692..2aac56744 100644
--- a/.changes/1.2.1.md
+++ b/.changes/1.2.1.md
@@ -1,4 +1,4 @@
-## dbt-adapter 1.2.1 - May 21, 2024
+## dbt-adapters 1.2.1 - May 21, 2024
### Features
diff --git a/.changes/1.3.0.md b/.changes/1.3.0.md
new file mode 100644
index 000000000..dae1f819a
--- /dev/null
+++ b/.changes/1.3.0.md
@@ -0,0 +1,5 @@
+## dbt-adapters 1.3.0 - June 18, 2024
+
+### Features
+
+* Add get_catalog_for_single_relation macro and capability to enable adapters to optimize catalog generation
diff --git a/.changes/1.3.1.md b/.changes/1.3.1.md
new file mode 100644
index 000000000..b8ec73740
--- /dev/null
+++ b/.changes/1.3.1.md
@@ -0,0 +1 @@
+## dbt-adapters 1.3.1 - June 20, 2024
diff --git a/.changes/1.3.2.md b/.changes/1.3.2.md
new file mode 100644
index 000000000..bdc7f593f
--- /dev/null
+++ b/.changes/1.3.2.md
@@ -0,0 +1,6 @@
+## dbt-adapters 1.3.2 - July 02, 2024
+
+### Under the Hood
+
+* Fix query timer resolution
+* Add optional release_connection parameter to connection_named method
diff --git a/.changes/1.3.3.md b/.changes/1.3.3.md
new file mode 100644
index 000000000..22ab18e30
--- /dev/null
+++ b/.changes/1.3.3.md
@@ -0,0 +1,9 @@
+## dbt-adapters 1.3.3 - July 09, 2024
+
+### Fixes
+
+* Fix scenario where using the `--empty` flag causes metadata queries to contain limit clauses
+
+### Under the Hood
+
+* --limit flag no longer subshells the query. This resolves the dbt Cloud experience issue where limit prevents ordering elements..
diff --git a/.changes/1.8.0.md b/.changes/1.8.0.md
index bbe54825e..e781a9856 100644
--- a/.changes/1.8.0.md
+++ b/.changes/1.8.0.md
@@ -1,4 +1,4 @@
-## dbt-adapter 1.8.0 - May 09, 2024
+## dbt-adapters 1.8.0 - May 09, 2024
### Features
diff --git a/.changes/1.9.0.md b/.changes/1.9.0.md
new file mode 100644
index 000000000..2f016563b
--- /dev/null
+++ b/.changes/1.9.0.md
@@ -0,0 +1 @@
+## dbt-adapters 1.9.0 - June 18, 2024
diff --git a/.changes/1.9.1.md b/.changes/1.9.1.md
new file mode 100644
index 000000000..900e6b755
--- /dev/null
+++ b/.changes/1.9.1.md
@@ -0,0 +1 @@
+## dbt-adapters 1.9.1 - June 20, 2024
diff --git a/.changes/1.9.2.md b/.changes/1.9.2.md
new file mode 100644
index 000000000..26505f203
--- /dev/null
+++ b/.changes/1.9.2.md
@@ -0,0 +1 @@
+## dbt-adapters 1.9.2 - July 09, 2024
diff --git a/.changie.yaml b/.changie.yaml
index 9f78b81e1..afbafb227 100644
--- a/.changie.yaml
+++ b/.changie.yaml
@@ -4,7 +4,7 @@ headerPath: header.tpl.md
changelogPath: CHANGELOG.md
versionExt: md
envPrefix: CHANGIE_
-versionFormat: '## dbt-adapter {{.Version}} - {{.Time.Format "January 02, 2006"}}'
+versionFormat: '## dbt-adapters {{.Version}} - {{.Time.Format "January 02, 2006"}}'
kindFormat: '### {{.Kind}}'
changeFormat: '* {{.Body}}'
kinds:
diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml
index 3bd90bf71..27cb521e8 100644
--- a/.github/ISSUE_TEMPLATE/bug-report.yml
+++ b/.github/ISSUE_TEMPLATE/bug-report.yml
@@ -1,5 +1,5 @@
name: 🐞 Bug
-description: Report a bug or an issue you've found with dbt-adapter
+description: Report a bug or an issue you've found with dbt-adapters
title: "[Bug]
"
labels: ["bug", "triage"]
body:
@@ -62,11 +62,11 @@ body:
examples:
- **OS**: Ubuntu 20.04
- **Python**: 3.11.6 (`python3 --version`)
- - **dbt-adapter**: 1.0.0
+ - **dbt-adapters**: 1.0.0
value: |
- OS:
- Python:
- - dbt-adapter:
+ - dbt-adapters:
render: markdown
validations:
required: false
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
index 2e23e0fd6..a89889afa 100644
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -7,5 +7,5 @@ contact_links:
url: mailto:support@getdbt.com
about: Are you using dbt Cloud? Contact our support team for help!
- name: Participate in Discussions
- url: https://github.com/dbt-labs/dbt-adapter/discussions
- about: Do you have a Big Idea for dbt-adapter? Read open discussions, or start a new one
+ url: https://github.com/dbt-labs/dbt-adapters/discussions
+ about: Do you have a Big Idea for dbt-adapters? Read open discussions, or start a new one
diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml
index 25b28aae1..22960c2d6 100644
--- a/.github/ISSUE_TEMPLATE/feature-request.yml
+++ b/.github/ISSUE_TEMPLATE/feature-request.yml
@@ -1,5 +1,5 @@
name: ✨ Feature
-description: Propose a straightforward extension of dbt-adapter functionality
+description: Propose a straightforward extension of dbt-adapters functionality
title: "[Feature] "
labels: ["enhancement", "triage"]
body:
@@ -14,15 +14,15 @@ body:
We want to make sure that features are distinct and discoverable,
so that other members of the community can find them and offer their thoughts.
- Issues are the right place to request straightforward extensions of existing dbt-adapter functionality.
- For "big ideas" about future capabilities of dbt-adapter, we ask that you open a
- [discussion](https://github.com/dbt-labs/dbt-adapter/discussions/new?category=ideas) in the "Ideas" category instead.
+ Issues are the right place to request straightforward extensions of existing dbt-adapters functionality.
+ For "big ideas" about future capabilities of dbt-adapters, we ask that you open a
+ [discussion](https://github.com/dbt-labs/dbt-adapters/discussions/new?category=ideas) in the "Ideas" category instead.
options:
- label: I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
required: true
- label: I have searched the existing issues, and I could not find an existing issue for this feature
required: true
- - label: I am requesting a straightforward extension of existing dbt-adapter functionality, rather than a Big Idea better suited to a discussion
+ - label: I am requesting a straightforward extension of existing dbt-adapters functionality, rather than a Big Idea better suited to a discussion
required: true
- type: textarea
attributes:
diff --git a/.github/ISSUE_TEMPLATE/regression-report.yml b/.github/ISSUE_TEMPLATE/regression-report.yml
index 017755077..6831ede2f 100644
--- a/.github/ISSUE_TEMPLATE/regression-report.yml
+++ b/.github/ISSUE_TEMPLATE/regression-report.yml
@@ -1,5 +1,5 @@
name: ☣️ Regression
-description: Report a regression you've observed in a newer version of dbt-adapter
+description: Report a regression you've observed in a newer version of dbt-adapters
title: "[Regression] "
labels: ["regression", "triage"]
body:
@@ -57,13 +57,13 @@ body:
examples:
- **OS**: Ubuntu 20.04
- **Python**: 3.11.6 (`python3 --version`)
- - **dbt-adapter (working version)**: 1.1.0
- - **dbt-adapter (regression version)**: 1.2.0
+ - **dbt-adapters (working version)**: 1.1.0
+ - **dbt-adapters (regression version)**: 1.2.0
value: |
- OS:
- Python:
- - dbt-adapter (working version):
- - dbt-adapter (regression version):
+ - dbt-adapters (working version):
+ - dbt-adapters (regression version):
render: markdown
validations:
required: true
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index 4fc2fcf8e..3879b6538 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -29,7 +29,7 @@ resolves #
### Checklist
-- [ ] I have read [the contributing guide](https://github.com/dbt-labs/dbt-adapter/blob/main/CONTRIBUTING.md) and understand what's expected of me
+- [ ] I have read [the contributing guide](https://github.com/dbt-labs/dbt-adapters/blob/main/CONTRIBUTING.md) and understand what's expected of me
- [ ] 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
- [ ] This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX
diff --git a/.github/workflows/docs-issue.yml b/.github/workflows/docs-issue.yml
new file mode 100644
index 000000000..f49cf517c
--- /dev/null
+++ b/.github/workflows/docs-issue.yml
@@ -0,0 +1,41 @@
+# **what?**
+# Open an issue in docs.getdbt.com when an issue is labeled `user docs` and closed as completed
+
+# **why?**
+# To reduce barriers for keeping docs up to date
+
+# **when?**
+# When an issue is labeled `user docs` and is closed as completed. Can be labeled before or after the issue is closed.
+
+
+name: Open issues in docs.getdbt.com repo when an issue is labeled
+run-name: "Open an issue in docs.getdbt.com for issue #${{ github.event.issue.number }}"
+
+on:
+ issues:
+ types: [labeled, closed]
+
+defaults:
+ run:
+ shell: bash
+
+permissions:
+ issues: write # comments on issues
+
+jobs:
+ open_issues:
+ # we only want to run this when the issue is closed as completed and the label `user docs` has been assigned.
+ # If this logic does not exist in this workflow, it runs the
+ # risk of duplicaton of issues being created due to merge and label both triggering this workflow to run and neither having
+ # generating the comment before the other runs. This lives here instead of the shared workflow because this is where we
+ # decide if it should run or not.
+ if: |
+ (github.event.issue.state == 'closed' && github.event.issue.state_reason == 'completed') && (
+ (github.event.action == 'closed' && contains(github.event.issue.labels.*.name, 'user docs')) ||
+ (github.event.action == 'labeled' && github.event.label.name == 'user docs'))
+ uses: dbt-labs/actions/.github/workflows/open-issue-in-repo.yml@main
+ with:
+ issue_repository: "dbt-labs/docs.getdbt.com"
+ issue_title: "Docs Changes Needed from ${{ github.event.repository.name }} Issue #${{ github.event.issue.number }}"
+ issue_body: "At a minimum, update body to include a link to the page on docs.getdbt.com requiring updates and what part(s) of the page you would like to see updated."
+ secrets: inherit
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 1135adb84..828350ddc 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -151,7 +151,7 @@ jobs:
github-release:
name: "GitHub Release"
- # ToDo: update GH release to handle adding dbt-tests-adapter and dbt-adapter assets to the same release
+ # ToDo: update GH release to handle adding dbt-tests-adapter and dbt-adapters assets to the same release
if: ${{ !failure() && !cancelled() && inputs.package == 'dbt-adapters' }}
needs: [release-inputs, build-and-test, bump-version-generate-changelog]
uses: dbt-labs/dbt-adapters/.github/workflows/github-release.yml@main
diff --git a/.gitignore b/.gitignore
index a14d6d0db..31258db20 100644
--- a/.gitignore
+++ b/.gitignore
@@ -154,3 +154,13 @@ cython_debug/
# PyCharm
.idea/
+
+# MacOS
+.DS_Store
+
+# vscode
+.vscode/
+.venv/
+
+# Vim
+*.swp
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aaa477cf7..1a2f1833b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,7 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).
-## dbt-adapter 1.8.0 - May 09, 2024
+## dbt-adapters 1.9.2 - July 09, 2024
+
+## dbt-adapters 1.9.1 - June 20, 2024
+
+## dbt-adapters 1.9.0 - June 18, 2024
+
+## dbt-adapters 1.8.0 - May 09, 2024
### Features
@@ -15,7 +21,32 @@ and is generated by [Changie](https://github.com/miniscruff/changie).
* Update Clone test to reflect core change removing `deferred` attribute from nodes
-## dbt-adapter 1.2.1 - May 21, 2024
+## dbt-adapters 1.3.3 - July 09, 2024
+
+### Fixes
+
+* Fix scenario where using the `--empty` flag causes metadata queries to contain limit clauses
+
+### Under the Hood
+
+* --limit flag no longer subshells the query. This resolves the dbt Cloud experience issue where limit prevents ordering elements..
+
+## dbt-adapters 1.3.2 - July 02, 2024
+
+### Under the Hood
+
+* Fix query timer resolution
+* Add optional release_connection parameter to connection_named method
+
+## dbt-adapters 1.3.1 - June 20, 2024
+
+## dbt-adapters 1.3.0 - June 18, 2024
+
+### Features
+
+* Add get_catalog_for_single_relation macro and capability to enable adapters to optimize catalog generation
+
+## dbt-adapters 1.2.1 - May 21, 2024
### Features
@@ -26,13 +57,13 @@ and is generated by [Changie](https://github.com/miniscruff/changie).
* Add query recording for adapters which use SQLConnectionManager
* Improve memory efficiency of process_results()
-## dbt-adapter 1.1.1 - May 07, 2024
+## dbt-adapters 1.1.1 - May 07, 2024
### Features
* Enable serialization contexts
-## dbt-adapter 1.1.0 - May 01, 2024
+## dbt-adapters 1.1.0 - May 01, 2024
### Features
@@ -62,7 +93,7 @@ and is generated by [Changie](https://github.com/miniscruff/changie).
* add support for py3.12
-## dbt-adapter 1.0.0 - April 01, 2024
+## dbt-adapters 1.0.0 - April 01, 2024
### Fixes
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c87ea23d0..28f13f6ce 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -163,7 +163,7 @@ Remember to commit and push the file that's created.
### Signing the CLA
-> **_NOTE:_** All contributors to `dbt-adapter` must sign the
+> **_NOTE:_** All contributors to `dbt-adapters` must sign the
> [Contributor License Agreement](https://docs.getdbt.com/docs/contributor-license-agreements)(CLA).
Maintainers will be unable to merge contributions until the contributor signs the CLA.
diff --git a/dbt-tests-adapter/dbt/tests/__about__.py b/dbt-tests-adapter/dbt/tests/__about__.py
index 6aaa73b80..1b022739e 100644
--- a/dbt-tests-adapter/dbt/tests/__about__.py
+++ b/dbt-tests-adapter/dbt/tests/__about__.py
@@ -1 +1 @@
-version = "1.8.0"
+version = "1.9.2"
diff --git a/dbt-tests-adapter/dbt/tests/adapter/basic/test_get_catalog_for_single_relation.py b/dbt-tests-adapter/dbt/tests/adapter/basic/test_get_catalog_for_single_relation.py
new file mode 100644
index 000000000..78055cc59
--- /dev/null
+++ b/dbt-tests-adapter/dbt/tests/adapter/basic/test_get_catalog_for_single_relation.py
@@ -0,0 +1,87 @@
+import pytest
+
+from dbt.tests.util import run_dbt, get_connection
+
+models__my_table_model_sql = """
+select * from {{ ref('my_seed') }}
+"""
+
+
+models__my_view_model_sql = """
+{{
+ config(
+ materialized='view',
+ )
+}}
+
+select * from {{ ref('my_seed') }}
+"""
+
+seed__my_seed_csv = """id,first_name,email,ip_address,updated_at
+1,Larry,lking0@miitbeian.gov.cn,69.135.206.194,2008-09-12 19:08:31
+"""
+
+
+class BaseGetCatalogForSingleRelation:
+ @pytest.fixture(scope="class")
+ def project_config_update(self):
+ return {"name": "get_catalog_for_single_relation"}
+
+ @pytest.fixture(scope="class")
+ def seeds(self):
+ return {
+ "my_seed.csv": seed__my_seed_csv,
+ }
+
+ @pytest.fixture(scope="class")
+ def models(self):
+ return {
+ "my_view_model.sql": models__my_view_model_sql,
+ "my_table_model.sql": models__my_table_model_sql,
+ }
+
+ @pytest.fixture(scope="class")
+ def expected_catalog_my_seed(self, project):
+ raise NotImplementedError(
+ "To use this test, please implement `get_catalog_for_single_relation`, inherited from `SQLAdapter`."
+ )
+
+ @pytest.fixture(scope="class")
+ def expected_catalog_my_model(self, project):
+ raise NotImplementedError(
+ "To use this test, please implement `get_catalog_for_single_relation`, inherited from `SQLAdapter`."
+ )
+
+ def get_relation_for_identifier(self, project, identifier):
+ return project.adapter.get_relation(
+ database=project.database,
+ schema=project.test_schema,
+ identifier=identifier,
+ )
+
+ def test_get_catalog_for_single_relation(
+ self, project, expected_catalog_my_seed, expected_catalog_my_view_model
+ ):
+ results = run_dbt(["seed"])
+ assert len(results) == 1
+
+ my_seed_relation = self.get_relation_for_identifier(project, "my_seed")
+
+ with get_connection(project.adapter):
+ actual_catalog_my_seed = project.adapter.get_catalog_for_single_relation(
+ my_seed_relation
+ )
+
+ assert actual_catalog_my_seed == expected_catalog_my_seed
+
+ results = run_dbt(["run"])
+ assert len(results) == 2
+
+ my_view_model_relation = self.get_relation_for_identifier(project, "my_view_model")
+
+ with get_connection(project.adapter):
+ actual_catalog_my_view_model = project.adapter.get_catalog_for_single_relation(
+ my_view_model_relation
+ )
+
+ assert actual_catalog_my_view_model == expected_catalog_my_view_model
diff --git a/dbt-tests-adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py b/dbt-tests-adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py
index c00491aab..3f3d36c59 100644
--- a/dbt-tests-adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py
+++ b/dbt-tests-adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py
@@ -1,5 +1,6 @@
import pytest
+from dbt_common.exceptions import DbtRuntimeError
from dbt.tests.adapter.dbt_show import fixtures
from dbt.tests.util import run_dbt
@@ -47,9 +48,25 @@ def test_sql_header(self, project):
run_dbt(["show", "--select", "sql_header", "--vars", "timezone: Asia/Kolkata"])
+class BaseShowDoesNotHandleDoubleLimit:
+ """see issue: https://github.com/dbt-labs/dbt-adapters/issues/207"""
+
+ DATABASE_ERROR_MESSAGE = 'syntax error at or near "limit"'
+
+ def test_double_limit_throws_syntax_error(self, project):
+ with pytest.raises(DbtRuntimeError) as e:
+ run_dbt(["show", "--limit", "1", "--inline", "select 1 limit 1"])
+
+ assert self.DATABASE_ERROR_MESSAGE in str(e)
+
+
class TestPostgresShowSqlHeader(BaseShowSqlHeader):
pass
class TestPostgresShowLimit(BaseShowLimit):
pass
+
+
+class TestShowDoesNotHandleDoubleLimit(BaseShowDoesNotHandleDoubleLimit):
+ pass
diff --git a/dbt-tests-adapter/dbt/tests/adapter/empty/_models.py b/dbt-tests-adapter/dbt/tests/adapter/empty/_models.py
new file mode 100644
index 000000000..f5e684f7f
--- /dev/null
+++ b/dbt-tests-adapter/dbt/tests/adapter/empty/_models.py
@@ -0,0 +1,111 @@
+model_input_sql = """
+select 1 as id
+"""
+
+ephemeral_model_input_sql = """
+{{ config(materialized='ephemeral') }}
+select 2 as id
+"""
+
+raw_source_csv = """id
+3
+"""
+
+
+model_sql = """
+select *
+from {{ ref('model_input') }}
+union all
+select *
+from {{ ref('ephemeral_model_input') }}
+union all
+select *
+from {{ source('seed_sources', 'raw_source') }}
+"""
+
+
+model_inline_sql = """
+select * from {{ source('seed_sources', 'raw_source') }} as raw_source
+"""
+
+schema_sources_yml = """
+sources:
+ - name: seed_sources
+ schema: "{{ target.schema }}"
+ tables:
+ - name: raw_source
+"""
+
+
+SEED = """
+my_id,my_value
+1,a
+2,b
+3,c
+""".strip()
+
+
+SCHEMA = """
+version: 2
+
+seeds:
+ - name: my_seed
+ description: "This is my_seed"
+ columns:
+ - name: id
+ description: "This is my_seed.my_id"
+"""
+
+CONTROL = """
+select * from {{ ref("my_seed") }}
+"""
+
+
+GET_COLUMNS_IN_RELATION = """
+{{ config(materialized="table") }}
+{% set columns = adapter.get_columns_in_relation(ref("my_seed")) %}
+select * from {{ ref("my_seed") }}
+"""
+
+
+ALTER_COLUMN_TYPE = """
+{{ config(materialized="table") }}
+{{ alter_column_type(ref("my_seed"), "MY_VALUE", "varchar") }}
+select * from {{ ref("my_seed") }}
+"""
+
+
+ALTER_RELATION_COMMENT = """
+{{ config(
+ materialized="table",
+ persist_docs={"relations": True},
+) }}
+select * from {{ ref("my_seed") }}
+"""
+
+
+ALTER_COLUMN_COMMENT = """
+{{ config(
+ materialized="table",
+ persist_docs={"columns": True},
+) }}
+select * from {{ ref("my_seed") }}
+"""
+
+
+ALTER_RELATION_ADD_REMOVE_COLUMNS = """
+{{ config(materialized="table") }}
+{% set my_seed = adapter.Relation.create(this.database, this.schema, "my_seed", "table") %}
+{% set my_column = api.Column("my_column", "varchar") %}
+{% do alter_relation_add_remove_columns(my_seed, [my_column], none) %}
+{% do alter_relation_add_remove_columns(my_seed, none, [my_column]) %}
+select * from {{ ref("my_seed") }}
+"""
+
+
+TRUNCATE_RELATION = """
+{{ config(materialized="table") }}
+{% set my_seed = adapter.Relation.create(this.database, this.schema, "my_seed", "table") %}
+{{ truncate_relation(my_seed) }}
+select * from {{ ref("my_seed") }}
+"""
diff --git a/dbt-tests-adapter/dbt/tests/adapter/empty/test_empty.py b/dbt-tests-adapter/dbt/tests/adapter/empty/test_empty.py
index 2249d98d5..de15bd5b0 100644
--- a/dbt-tests-adapter/dbt/tests/adapter/empty/test_empty.py
+++ b/dbt-tests-adapter/dbt/tests/adapter/empty/test_empty.py
@@ -1,57 +1,23 @@
-import pytest
-
from dbt.tests.util import relation_from_name, run_dbt
+import pytest
-
-model_input_sql = """
-select 1 as id
-"""
-
-ephemeral_model_input_sql = """
-{{ config(materialized='ephemeral') }}
-select 2 as id
-"""
-
-raw_source_csv = """id
-3
-"""
-
-
-model_sql = """
-select *
-from {{ ref('model_input') }}
-union all
-select *
-from {{ ref('ephemeral_model_input') }}
-union all
-select *
-from {{ source('seed_sources', 'raw_source') }}
-"""
-
-
-schema_sources_yml = """
-sources:
- - name: seed_sources
- schema: "{{ target.schema }}"
- tables:
- - name: raw_source
-"""
+from dbt.tests.adapter.empty import _models
class BaseTestEmpty:
@pytest.fixture(scope="class")
def seeds(self):
return {
- "raw_source.csv": raw_source_csv,
+ "raw_source.csv": _models.raw_source_csv,
}
@pytest.fixture(scope="class")
def models(self):
return {
- "model_input.sql": model_input_sql,
- "ephemeral_model_input.sql": ephemeral_model_input_sql,
- "model.sql": model_sql,
- "sources.yml": schema_sources_yml,
+ "model_input.sql": _models.model_input_sql,
+ "ephemeral_model_input.sql": _models.ephemeral_model_input_sql,
+ "model.sql": _models.model_sql,
+ "sources.yml": _models.schema_sources_yml,
}
def assert_row_count(self, project, relation_name: str, expected_row_count: int):
@@ -75,13 +41,9 @@ def test_run_with_empty(self, project):
class BaseTestEmptyInlineSourceRef(BaseTestEmpty):
@pytest.fixture(scope="class")
def models(self):
- model_sql = """
- select * from {{ source('seed_sources', 'raw_source') }} as raw_source
- """
-
return {
- "model.sql": model_sql,
- "sources.yml": schema_sources_yml,
+ "model.sql": _models.model_inline_sql,
+ "sources.yml": _models.schema_sources_yml,
}
def test_run_with_empty(self, project):
@@ -92,4 +54,47 @@ def test_run_with_empty(self, project):
class TestEmpty(BaseTestEmpty):
+ """
+ Though we don't create these classes anymore, we need to keep this one in case an adapter wanted to import the test as-is to automatically run it.
+ We should consider adding a deprecation warning that suggests moving this into the concrete adapter and importing `BaseTestEmpty` instead.
+ """
+
pass
+
+
+class MetadataWithEmptyFlag:
+ @pytest.fixture(scope="class")
+ def seeds(self):
+ return {"my_seed.csv": _models.SEED}
+
+ @pytest.fixture(scope="class")
+ def models(self):
+ return {
+ "schema.yml": _models.SCHEMA,
+ "control.sql": _models.CONTROL,
+ "get_columns_in_relation.sql": _models.GET_COLUMNS_IN_RELATION,
+ "alter_column_type.sql": _models.ALTER_COLUMN_TYPE,
+ "alter_relation_comment.sql": _models.ALTER_RELATION_COMMENT,
+ "alter_column_comment.sql": _models.ALTER_COLUMN_COMMENT,
+ "alter_relation_add_remove_columns.sql": _models.ALTER_RELATION_ADD_REMOVE_COLUMNS,
+ "truncate_relation.sql": _models.TRUNCATE_RELATION,
+ }
+
+ @pytest.fixture(scope="class", autouse=True)
+ def setup(self, project):
+ run_dbt(["seed"])
+
+ @pytest.mark.parametrize(
+ "model",
+ [
+ "control",
+ "get_columns_in_relation",
+ "alter_column_type",
+ "alter_relation_comment",
+ "alter_column_comment",
+ "alter_relation_add_remove_columns",
+ "truncate_relation",
+ ],
+ )
+ def test_run(self, project, model):
+ run_dbt(["run", "--empty", "--select", model])
diff --git a/dbt/adapters/__about__.py b/dbt/adapters/__about__.py
index eb1d9a0ff..cfa2db681 100644
--- a/dbt/adapters/__about__.py
+++ b/dbt/adapters/__about__.py
@@ -1 +1 @@
-version = "1.2.1"
+version = "1.3.3"
diff --git a/dbt/adapters/base/impl.py b/dbt/adapters/base/impl.py
index f58f8aba0..ec5901379 100644
--- a/dbt/adapters/base/impl.py
+++ b/dbt/adapters/base/impl.py
@@ -1,10 +1,10 @@
import abc
+import time
from concurrent.futures import as_completed, Future
from contextlib import contextmanager
from datetime import datetime
from enum import Enum
from multiprocessing.context import SpawnContext
-import time
from typing import (
Any,
Callable,
@@ -23,12 +23,15 @@
TYPE_CHECKING,
)
+import pytz
from dbt_common.clients.jinja import CallableMacroGenerator
from dbt_common.contracts.constraints import (
ColumnLevelConstraint,
ConstraintType,
ModelLevelConstraint,
)
+from dbt_common.contracts.metadata import CatalogTable
+from dbt_common.events.functions import fire_event, warn_or_error
from dbt_common.exceptions import (
DbtInternalError,
DbtRuntimeError,
@@ -38,14 +41,12 @@
NotImplementedError,
UnexpectedNullError,
)
-from dbt_common.events.functions import fire_event, warn_or_error
from dbt_common.utils import (
AttrDict,
cast_to_str,
executor,
filter_null_values,
)
-import pytz
from dbt.adapters.base.column import Column as BaseColumn
from dbt.adapters.base.connections import (
@@ -222,6 +223,7 @@ class BaseAdapter(metaclass=AdapterMeta):
- truncate_relation
- rename_relation
- get_columns_in_relation
+ - get_catalog_for_single_relation
- get_column_schema_from_query
- expand_column_types
- list_relations_without_caching
@@ -317,14 +319,18 @@ def nice_connection_name(self) -> str:
return conn.name
@contextmanager
- def connection_named(self, name: str, query_header_context: Any = None) -> Iterator[None]:
+ def connection_named(
+ self, name: str, query_header_context: Any = None, should_release_connection=True
+ ) -> Iterator[None]:
try:
if self.connections.query_header is not None:
self.connections.query_header.set(name, query_header_context)
self.acquire_connection(name)
yield
finally:
- self.release_connection()
+ if should_release_connection:
+ self.release_connection()
+
if self.connections.query_header is not None:
self.connections.query_header.reset()
@@ -627,6 +633,12 @@ def get_columns_in_relation(self, relation: BaseRelation) -> List[BaseColumn]:
"""Get a list of the columns in the given Relation."""
raise NotImplementedError("`get_columns_in_relation` is not implemented for this adapter!")
+ def get_catalog_for_single_relation(self, relation: BaseRelation) -> Optional[CatalogTable]:
+ """Get catalog information including table-level and column-level metadata for a single relation."""
+ raise NotImplementedError(
+ "`get_catalog_for_single_relation` is not implemented for this adapter!"
+ )
+
@available.deprecated("get_columns_in_relation", lambda *a, **k: [])
def get_columns_in_table(self, schema: str, identifier: str) -> List[BaseColumn]:
"""DEPRECATED: Get a list of the columns in the given table."""
diff --git a/dbt/adapters/capability.py b/dbt/adapters/capability.py
index 305604c71..2bd491123 100644
--- a/dbt/adapters/capability.py
+++ b/dbt/adapters/capability.py
@@ -14,7 +14,12 @@ class Capability(str, Enum):
"""Indicates support for determining the time of the last table modification by querying database metadata."""
TableLastModifiedMetadataBatch = "TableLastModifiedMetadataBatch"
- """Indicates support for performantly determining the time of the last table modification by querying database metadata in batch."""
+ """Indicates support for performantly determining the time of the last table modification by querying database
+ metadata in batch."""
+
+ GetCatalogForSingleRelation = "GetCatalogForSingleRelation"
+ """Indicates support for getting catalog information including table-level and column-level metadata for a single
+ relation."""
class Support(str, Enum):
diff --git a/dbt/adapters/events/types.py b/dbt/adapters/events/types.py
index 7d98269d9..47c48da62 100644
--- a/dbt/adapters/events/types.py
+++ b/dbt/adapters/events/types.py
@@ -190,7 +190,7 @@ def code(self) -> str:
return "E017"
def message(self) -> str:
- return f"SQL status: {self.status} in {self.elapsed} seconds"
+ return f"SQL status: {self.status} in {self.elapsed:.3f} seconds"
class SQLCommit(DebugLevel):
diff --git a/dbt/adapters/sql/connections.py b/dbt/adapters/sql/connections.py
index d8699fd39..13111a6e8 100644
--- a/dbt/adapters/sql/connections.py
+++ b/dbt/adapters/sql/connections.py
@@ -88,7 +88,8 @@ def add_query(
node_info=get_node_info(),
)
)
- pre = time.time()
+
+ pre = time.perf_counter()
cursor = connection.handle.cursor()
cursor.execute(sql, bindings)
@@ -96,7 +97,7 @@ def add_query(
fire_event(
SQLQueryStatus(
status=str(self.get_response(cursor)),
- elapsed=round((time.time() - pre)),
+ elapsed=time.perf_counter() - pre,
node_info=get_node_info(),
)
)
diff --git a/dbt/adapters/sql/impl.py b/dbt/adapters/sql/impl.py
index 8c6e0e8e4..8a8473f27 100644
--- a/dbt/adapters/sql/impl.py
+++ b/dbt/adapters/sql/impl.py
@@ -9,7 +9,6 @@
from dbt.adapters.exceptions import RelationTypeNullError
from dbt.adapters.sql.connections import SQLConnectionManager
-
LIST_RELATIONS_MACRO_NAME = "list_relations_without_caching"
GET_COLUMNS_IN_RELATION_MACRO_NAME = "get_columns_in_relation"
LIST_SCHEMAS_MACRO_NAME = "list_schemas"
@@ -41,6 +40,7 @@ class SQLAdapter(BaseAdapter):
- get_catalog
- list_relations_without_caching
- get_columns_in_relation
+ - get_catalog_for_single_relation
"""
ConnectionManager: Type[SQLConnectionManager]
diff --git a/dbt/include/global_project/macros/adapters/apply_grants.sql b/dbt/include/global_project/macros/adapters/apply_grants.sql
index 10906e7ff..c75eef89d 100644
--- a/dbt/include/global_project/macros/adapters/apply_grants.sql
+++ b/dbt/include/global_project/macros/adapters/apply_grants.sql
@@ -61,7 +61,7 @@
{% endmacro %}
{% macro default__get_show_grant_sql(relation) %}
- show grants on {{ relation }}
+ show grants on {{ relation.render() }}
{% endmacro %}
@@ -70,7 +70,7 @@
{% endmacro %}
{%- macro default__get_grant_sql(relation, privilege, grantees) -%}
- grant {{ privilege }} on {{ relation }} to {{ grantees | join(', ') }}
+ grant {{ privilege }} on {{ relation.render() }} to {{ grantees | join(', ') }}
{%- endmacro -%}
@@ -79,7 +79,7 @@
{% endmacro %}
{%- macro default__get_revoke_sql(relation, privilege, grantees) -%}
- revoke {{ privilege }} on {{ relation }} from {{ grantees | join(', ') }}
+ revoke {{ privilege }} on {{ relation.render() }} from {{ grantees | join(', ') }}
{%- endmacro -%}
@@ -147,7 +147,7 @@
{% set needs_granting = diff_of_two_dicts(grant_config, current_grants_dict) %}
{% set needs_revoking = diff_of_two_dicts(current_grants_dict, grant_config) %}
{% if not (needs_granting or needs_revoking) %}
- {{ log('On ' ~ relation ~': All grants are in place, no revocation or granting needed.')}}
+ {{ log('On ' ~ relation.render() ~': All grants are in place, no revocation or granting needed.')}}
{% endif %}
{% else %}
{#-- We don't think there's any chance of previous grants having carried over. --#}
diff --git a/dbt/include/global_project/macros/adapters/columns.sql b/dbt/include/global_project/macros/adapters/columns.sql
index 663a827b1..96e6f3f24 100644
--- a/dbt/include/global_project/macros/adapters/columns.sql
+++ b/dbt/include/global_project/macros/adapters/columns.sql
@@ -96,10 +96,10 @@
{%- set tmp_column = column_name + "__dbt_alter" -%}
{% call statement('alter_column_type') %}
- alter table {{ relation }} add column {{ adapter.quote(tmp_column) }} {{ new_column_type }};
- update {{ relation }} set {{ adapter.quote(tmp_column) }} = {{ adapter.quote(column_name) }};
- alter table {{ relation }} drop column {{ adapter.quote(column_name) }} cascade;
- alter table {{ relation }} rename column {{ adapter.quote(tmp_column) }} to {{ adapter.quote(column_name) }}
+ alter table {{ relation.render() }} add column {{ adapter.quote(tmp_column) }} {{ new_column_type }};
+ update {{ relation.render() }} set {{ adapter.quote(tmp_column) }} = {{ adapter.quote(column_name) }};
+ alter table {{ relation.render() }} drop column {{ adapter.quote(column_name) }} cascade;
+ alter table {{ relation.render() }} rename column {{ adapter.quote(tmp_column) }} to {{ adapter.quote(column_name) }}
{% endcall %}
{% endmacro %}
@@ -120,7 +120,7 @@
{% set sql -%}
- alter {{ relation.type }} {{ relation }}
+ alter {{ relation.type }} {{ relation.render() }}
{% for column in add_columns %}
add column {{ column.name }} {{ column.data_type }}{{ ',' if not loop.last }}
diff --git a/dbt/include/global_project/macros/adapters/metadata.sql b/dbt/include/global_project/macros/adapters/metadata.sql
index c8e8a4140..0aa7aabb4 100644
--- a/dbt/include/global_project/macros/adapters/metadata.sql
+++ b/dbt/include/global_project/macros/adapters/metadata.sql
@@ -77,6 +77,15 @@
'list_relations_without_caching macro not implemented for adapter '+adapter.type()) }}
{% endmacro %}
+{% macro get_catalog_for_single_relation(relation) %}
+ {{ return(adapter.dispatch('get_catalog_for_single_relation', 'dbt')(relation)) }}
+{% endmacro %}
+
+{% macro default__get_catalog_for_single_relation(relation) %}
+ {{ exceptions.raise_not_implemented(
+ 'get_catalog_for_single_relation macro not implemented for adapter '+adapter.type()) }}
+{% endmacro %}
+
{% macro get_relations() %}
{{ return(adapter.dispatch('get_relations', 'dbt')()) }}
{% endmacro %}
diff --git a/dbt/include/global_project/macros/adapters/relation.sql b/dbt/include/global_project/macros/adapters/relation.sql
index 1c2bd8800..b9af49692 100644
--- a/dbt/include/global_project/macros/adapters/relation.sql
+++ b/dbt/include/global_project/macros/adapters/relation.sql
@@ -38,7 +38,7 @@
{% macro default__truncate_relation(relation) -%}
{% call statement('truncate_relation') -%}
- truncate table {{ relation }}
+ truncate table {{ relation.render() }}
{%- endcall %}
{% endmacro %}
diff --git a/dbt/include/global_project/macros/adapters/show.sql b/dbt/include/global_project/macros/adapters/show.sql
index 33a93f3db..3a5faa98a 100644
--- a/dbt/include/global_project/macros/adapters/show.sql
+++ b/dbt/include/global_project/macros/adapters/show.sql
@@ -1,22 +1,26 @@
+{#
+ We expect a syntax error if dbt show is invoked both with a --limit flag to show
+ and with a limit predicate embedded in its inline query. No special handling is
+ provided out-of-box.
+#}
{% macro get_show_sql(compiled_code, sql_header, limit) -%}
- {%- if sql_header -%}
+ {%- if sql_header is not none -%}
{{ sql_header }}
- {%- endif -%}
- {%- if limit is not none -%}
+ {%- endif %}
{{ get_limit_subquery_sql(compiled_code, limit) }}
- {%- else -%}
- {{ compiled_code }}
- {%- endif -%}
{% endmacro %}
-{% macro get_limit_subquery_sql(sql, limit) %}
- {{ adapter.dispatch('get_limit_subquery_sql', 'dbt')(sql, limit) }}
-{% endmacro %}
+{#
+ Not necessarily a true subquery anymore. Now, merely a query subordinate
+ to the calling macro.
+#}
+{%- macro get_limit_subquery_sql(sql, limit) -%}
+ {{ adapter.dispatch('get_limit_sql', 'dbt')(sql, limit) }}
+{%- endmacro -%}
-{% macro default__get_limit_subquery_sql(sql, limit) %}
- select *
- from (
- {{ sql }}
- ) as model_limit_subq
- limit {{ limit }}
+{% macro default__get_limit_sql(sql, limit) %}
+ {{ compiled_code }}
+ {% if limit is not none %}
+ limit {{ limit }}
+ {%- endif -%}
{% endmacro %}
diff --git a/dbt/include/global_project/macros/materializations/models/clone/clone.sql b/dbt/include/global_project/macros/materializations/models/clone/clone.sql
index 01c8c3930..56d80082d 100644
--- a/dbt/include/global_project/macros/materializations/models/clone/clone.sql
+++ b/dbt/include/global_project/macros/materializations/models/clone/clone.sql
@@ -27,14 +27,14 @@
{%- set target_relation = this.incorporate(type='table') -%}
{% if existing_relation is not none and not existing_relation.is_table %}
- {{ log("Dropping relation " ~ existing_relation ~ " because it is of type " ~ existing_relation.type) }}
+ {{ log("Dropping relation " ~ existing_relation.render() ~ " because it is of type " ~ existing_relation.type) }}
{{ drop_relation_if_exists(existing_relation) }}
{% endif %}
-- as a general rule, data platforms that can clone tables can also do atomic 'create or replace'
{% call statement('main') %}
{% if target_relation and defer_relation and target_relation == defer_relation %}
- {{ log("Target relation and defer relation are the same, skipping clone for relation: " ~ target_relation) }}
+ {{ log("Target relation and defer relation are the same, skipping clone for relation: " ~ target_relation.render()) }}
{% else %}
{{ create_or_replace_clone(target_relation, defer_relation) }}
{% endif %}
diff --git a/dbt/include/global_project/macros/materializations/models/clone/create_or_replace_clone.sql b/dbt/include/global_project/macros/materializations/models/clone/create_or_replace_clone.sql
index 204e9e874..cdb2559c6 100644
--- a/dbt/include/global_project/macros/materializations/models/clone/create_or_replace_clone.sql
+++ b/dbt/include/global_project/macros/materializations/models/clone/create_or_replace_clone.sql
@@ -3,5 +3,5 @@
{% endmacro %}
{% macro default__create_or_replace_clone(this_relation, defer_relation) %}
- create or replace table {{ this_relation }} clone {{ defer_relation }}
+ create or replace table {{ this_relation.render() }} clone {{ defer_relation.render() }}
{% endmacro %}
diff --git a/dbt/include/global_project/macros/materializations/models/materialized_view.sql b/dbt/include/global_project/macros/materializations/models/materialized_view.sql
index 6dc30bf9a..a39f8aa21 100644
--- a/dbt/include/global_project/macros/materializations/models/materialized_view.sql
+++ b/dbt/include/global_project/macros/materializations/models/materialized_view.sql
@@ -71,9 +71,9 @@
{% set build_sql = get_alter_materialized_view_as_sql(target_relation, configuration_changes, sql, existing_relation, backup_relation, intermediate_relation) %}
{% elif on_configuration_change == 'continue' %}
{% set build_sql = '' %}
- {{ exceptions.warn("Configuration changes were identified and `on_configuration_change` was set to `continue` for `" ~ target_relation ~ "`") }}
+ {{ exceptions.warn("Configuration changes were identified and `on_configuration_change` was set to `continue` for `" ~ target_relation.render() ~ "`") }}
{% elif on_configuration_change == 'fail' %}
- {{ exceptions.raise_fail_fast_error("Configuration changes were identified and `on_configuration_change` was set to `fail` for `" ~ target_relation ~ "`") }}
+ {{ exceptions.raise_fail_fast_error("Configuration changes were identified and `on_configuration_change` was set to `fail` for `" ~ target_relation.render() ~ "`") }}
{% else %}
-- this only happens if the user provides a value other than `apply`, 'skip', 'fail'
diff --git a/dbt/include/global_project/macros/materializations/seeds/helpers.sql b/dbt/include/global_project/macros/materializations/seeds/helpers.sql
index 44dbf370d..d87c258b1 100644
--- a/dbt/include/global_project/macros/materializations/seeds/helpers.sql
+++ b/dbt/include/global_project/macros/materializations/seeds/helpers.sql
@@ -37,7 +37,7 @@
{% set sql = create_csv_table(model, agate_table) %}
{% else %}
{{ adapter.truncate_relation(old_relation) }}
- {% set sql = "truncate table " ~ old_relation %}
+ {% set sql = "truncate table " ~ old_relation.render() %}
{% endif %}
{{ return(sql) }}
diff --git a/dbt/include/global_project/macros/materializations/seeds/seed.sql b/dbt/include/global_project/macros/materializations/seeds/seed.sql
index 3b66252da..4ee4fb80c 100644
--- a/dbt/include/global_project/macros/materializations/seeds/seed.sql
+++ b/dbt/include/global_project/macros/materializations/seeds/seed.sql
@@ -22,7 +22,7 @@
-- build model
{% set create_table_sql = "" %}
{% if exists_as_view %}
- {{ exceptions.raise_compiler_error("Cannot seed to '{}', it is a view".format(old_relation)) }}
+ {{ exceptions.raise_compiler_error("Cannot seed to '{}', it is a view".format(old_relation.render())) }}
{% elif exists_as_table %}
{% set create_table_sql = reset_csv_table(model, full_refresh_mode, old_relation, agate_table) %}
{% else %}
diff --git a/dbt/include/global_project/macros/materializations/snapshots/helpers.sql b/dbt/include/global_project/macros/materializations/snapshots/helpers.sql
index 7fd4bfd51..bb71974cf 100644
--- a/dbt/include/global_project/macros/materializations/snapshots/helpers.sql
+++ b/dbt/include/global_project/macros/materializations/snapshots/helpers.sql
@@ -8,7 +8,7 @@
{% macro default__create_columns(relation, columns) %}
{% for column in columns %}
{% call statement() %}
- alter table {{ relation }} add column "{{ column.name }}" {{ column.data_type }};
+ alter table {{ relation.render() }} add column "{{ column.name }}" {{ column.data_type }};
{% endcall %}
{% endfor %}
{% endmacro %}
diff --git a/dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql b/dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql
index 6bc50fd3b..56798811d 100644
--- a/dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql
+++ b/dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql
@@ -7,7 +7,7 @@
{% macro default__snapshot_merge_sql(target, source, insert_cols) -%}
{%- set insert_cols_csv = insert_cols | join(', ') -%}
- merge into {{ target }} as DBT_INTERNAL_DEST
+ merge into {{ target.render() }} as DBT_INTERNAL_DEST
using {{ source }} as DBT_INTERNAL_SOURCE
on DBT_INTERNAL_SOURCE.dbt_scd_id = DBT_INTERNAL_DEST.dbt_scd_id
diff --git a/dbt/include/global_project/macros/relations/drop.sql b/dbt/include/global_project/macros/relations/drop.sql
index 58abd14d9..e66511dab 100644
--- a/dbt/include/global_project/macros/relations/drop.sql
+++ b/dbt/include/global_project/macros/relations/drop.sql
@@ -16,7 +16,7 @@
{{ drop_materialized_view(relation) }}
{%- else -%}
- drop {{ relation.type }} if exists {{ relation }} cascade
+ drop {{ relation.type }} if exists {{ relation.render() }} cascade
{%- endif -%}
diff --git a/dbt/include/global_project/macros/relations/materialized_view/drop.sql b/dbt/include/global_project/macros/relations/materialized_view/drop.sql
index b218d0f3c..8235b1c69 100644
--- a/dbt/include/global_project/macros/relations/materialized_view/drop.sql
+++ b/dbt/include/global_project/macros/relations/materialized_view/drop.sql
@@ -10,5 +10,5 @@ actually executes the drop, and `get_drop_sql`, which returns the template.
{% macro default__drop_materialized_view(relation) -%}
- drop materialized view if exists {{ relation }} cascade
+ drop materialized view if exists {{ relation.render() }} cascade
{%- endmacro %}
diff --git a/dbt/include/global_project/macros/relations/rename.sql b/dbt/include/global_project/macros/relations/rename.sql
index d7f3a72e2..4b913df35 100644
--- a/dbt/include/global_project/macros/relations/rename.sql
+++ b/dbt/include/global_project/macros/relations/rename.sql
@@ -30,6 +30,6 @@
{% macro default__rename_relation(from_relation, to_relation) -%}
{% set target_name = adapter.quote_as_configured(to_relation.identifier, 'identifier') %}
{% call statement('rename_relation') -%}
- alter table {{ from_relation }} rename to {{ target_name }}
+ alter table {{ from_relation.render() }} rename to {{ target_name }}
{%- endcall %}
{% endmacro %}
diff --git a/dbt/include/global_project/macros/relations/table/drop.sql b/dbt/include/global_project/macros/relations/table/drop.sql
index d7d5941c4..038ded9ea 100644
--- a/dbt/include/global_project/macros/relations/table/drop.sql
+++ b/dbt/include/global_project/macros/relations/table/drop.sql
@@ -10,5 +10,5 @@ actually executes the drop, and `get_drop_sql`, which returns the template.
{% macro default__drop_table(relation) -%}
- drop table if exists {{ relation }} cascade
+ drop table if exists {{ relation.render() }} cascade
{%- endmacro %}
diff --git a/dbt/include/global_project/macros/relations/view/create.sql b/dbt/include/global_project/macros/relations/view/create.sql
index 41cd196c3..ee83befae 100644
--- a/dbt/include/global_project/macros/relations/view/create.sql
+++ b/dbt/include/global_project/macros/relations/view/create.sql
@@ -16,7 +16,7 @@
{%- set sql_header = config.get('sql_header', none) -%}
{{ sql_header if sql_header is not none }}
- create view {{ relation }}
+ create view {{ relation.render() }}
{% set contract_config = config.get('contract') %}
{% if contract_config.enforced %}
{{ get_assert_columns_equivalent(sql) }}
diff --git a/dbt/include/global_project/macros/relations/view/drop.sql b/dbt/include/global_project/macros/relations/view/drop.sql
index 7e1924fae..84c91a364 100644
--- a/dbt/include/global_project/macros/relations/view/drop.sql
+++ b/dbt/include/global_project/macros/relations/view/drop.sql
@@ -10,5 +10,5 @@ actually executes the drop, and `get_drop_sql`, which returns the template.
{% macro default__drop_view(relation) -%}
- drop view if exists {{ relation }} cascade
+ drop view if exists {{ relation.render() }} cascade
{%- endmacro %}
diff --git a/dbt/include/global_project/macros/relations/view/replace.sql b/dbt/include/global_project/macros/relations/view/replace.sql
index 1da061347..a0f0dc76f 100644
--- a/dbt/include/global_project/macros/relations/view/replace.sql
+++ b/dbt/include/global_project/macros/relations/view/replace.sql
@@ -61,6 +61,6 @@
{% endmacro %}
{% macro default__handle_existing_table(full_refresh, old_relation) %}
- {{ log("Dropping relation " ~ old_relation ~ " because it is of type " ~ old_relation.type) }}
+ {{ log("Dropping relation " ~ old_relation.render() ~ " because it is of type " ~ old_relation.type) }}
{{ adapter.drop_relation(old_relation) }}
{% endmacro %}
diff --git a/pyproject.toml b/pyproject.toml
index a4b011a8f..e50aa63ab 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -24,7 +24,7 @@ classifiers = [
"Programming Language :: Python :: 3.12",
]
dependencies = [
- "dbt-common<2.0",
+ "dbt-common>=1.3,<2.0",
"pytz>=2015.7",
# installed via dbt-common but used directly
"agate>=1.0,<2.0",
@@ -43,6 +43,9 @@ Changelog = "https://github.com/dbt-labs/dbt-adapters/blob/main/CHANGELOG.md"
requires = ["hatchling"]
build-backend = "hatchling.build"
+[tool.hatch.metadata]
+allow-direct-references = true
+
[tool.hatch.version]
path = "dbt/adapters/__about__.py"