Skip to content

Commit

Permalink
extend behavior to generate_schema_name
Browse files Browse the repository at this point in the history
  • Loading branch information
guenp committed Oct 4, 2024
1 parent 9a195f0 commit 3a389b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 4 additions & 4 deletions dbt/include/duckdb/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
{% set sql -%}
select count(*)
from system.information_schema.schemata
where schema_name = '{{ schema }}'
and catalog_name = '{{ information_schema.database }}'
where lower(schema_name) = '{{ schema | lower }}'
and lower(catalog_name) = '{{ information_schema.database | lower }}'
{%- endset %}
{{ return(run_query(sql)) }}
{% endmacro %}
Expand Down Expand Up @@ -132,7 +132,7 @@ def materialize(df, con):
from system.information_schema.columns
where table_name = '{{ relation.identifier }}'
{% if relation.schema %}
and table_schema = '{{ relation.schema }}'
and lower(table_schema) = '{{ relation.schema | lower }}'
{% endif %}
{% if relation.database %}
and lower(table_catalog) = '{{ relation.database | lower }}'
Expand All @@ -156,7 +156,7 @@ def materialize(df, con):
WHEN 'LOCAL TEMPORARY' THEN 'table'
END as type
from system.information_schema.tables
where table_schema = '{{ schema_relation.schema }}'
where lower(table_schema) = '{{ schema_relation.schema | lower }}'
and lower(table_catalog) = '{{ schema_relation.database | lower }}'
{% endcall %}
{{ return(load_result('list_relations_without_caching').table) }}
Expand Down
7 changes: 7 additions & 0 deletions tests/functional/plugins/motherduck/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
{%- endmacro %}
"""


macros__generate_schema_name = """
{% macro generate_schema_name(custom_schema_name=none, node=none) -%}
{{ target.schema | trim }}_{{ var("build_env") | trim }}_{{ var("org_prefix") | trim }}
{%- endmacro %}
"""

#
# Seeds
#
Expand Down
6 changes: 5 additions & 1 deletion tests/functional/plugins/motherduck/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from tests.functional.plugins.motherduck.fixtures import (
models__gen_data_macro,
macros__generate_database_name,
macros__generate_schema_name,
seeds__example_seed_csv,
)

Expand Down Expand Up @@ -47,7 +48,10 @@ def models(self):

@pytest.fixture(scope="class")
def macros(self):
return {"db_name.sql": macros__generate_database_name}
return {
"db_name.sql": macros__generate_database_name,
"schema_name.sql": macros__generate_schema_name
}

@staticmethod
def gen_project_config_update(build_env, org_prefix):
Expand Down

0 comments on commit 3a389b2

Please sign in to comment.