Skip to content

Commit

Permalink
Merge branch 'main' into update-contributor-guide
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare authored Jul 13, 2024
2 parents e5be1c7 + 782a32b commit 922d876
Show file tree
Hide file tree
Showing 30 changed files with 270 additions and 103 deletions.
6 changes: 6 additions & 0 deletions .changes/1.3.2.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions .changes/1.3.3.md
Original file line number Diff line number Diff line change
@@ -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..
1 change: 1 addition & 0 deletions .changes/1.9.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## dbt-adapters 1.9.2 - July 09, 2024
6 changes: 0 additions & 6 deletions .changes/unreleased/Under the Hood-20240621-150837.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions .changes/unreleased/Under the Hood-20240624-161108.yaml

This file was deleted.

9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,12 @@ cython_debug/
# PyCharm
.idea/

# MacOS
.DS_Store

# VSCode
*.DS_Store
.vscode/
.venv/

# Vim
*.swp
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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-adapters 1.9.2 - July 09, 2024

## dbt-adapters 1.9.1 - June 20, 2024

## dbt-adapters 1.9.0 - June 18, 2024
Expand All @@ -19,6 +21,23 @@ and is generated by [Changie](https://github.com/miniscruff/changie).

* Update Clone test to reflect core change removing `deferred` attribute from nodes

## 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
Expand Down
2 changes: 1 addition & 1 deletion dbt-tests-adapter/dbt/tests/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.9.1"
version = "1.9.2"
17 changes: 17 additions & 0 deletions dbt-tests-adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
111 changes: 111 additions & 0 deletions dbt-tests-adapter/dbt/tests/adapter/empty/_models.py
Original file line number Diff line number Diff line change
@@ -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") }}
"""
99 changes: 52 additions & 47 deletions dbt-tests-adapter/dbt/tests/adapter/empty/test_empty.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
Expand All @@ -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])
2 changes: 1 addition & 1 deletion dbt/adapters/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.3.1"
version = "1.3.3"
8 changes: 4 additions & 4 deletions dbt/include/global_project/macros/adapters/apply_grants.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
{% endmacro %}

{% macro default__get_show_grant_sql(relation) %}
show grants on {{ relation }}
show grants on {{ relation.render() }}
{% endmacro %}


Expand All @@ -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 -%}


Expand All @@ -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 -%}


Expand Down Expand Up @@ -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. --#}
Expand Down
Loading

0 comments on commit 922d876

Please sign in to comment.