Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.8.latest] quoting config not working with 1.8 #1076

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240607-102708.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: return to previous naming convention to return to quoting policy
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
time: 2024-06-07T10:27:08.542159-05:00
custom:
Author: McKnight-42
Issue: "1074"
27 changes: 19 additions & 8 deletions dbt/include/snowflake/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@

{% for _ in range(0, max_iter) %}

{%- set paginated_sql -%}
show objects in {{ schema_relation.database }}.{{ schema_relation.schema }} limit {{ max_results_per_iter }} from '{{ watermark.table_name }}'
{%- endset -%}
{% if schema_relation is string %}
{%- set paginated_sql -%}
show objects in {{ schema_relation }} limit {{ max_results_per_iter }} from '{{ watermark.table_name }}'
{%- endset -%}
{% else %}
{%- set paginated_sql -%}
show objects in {{ schema_relation.include(identifier=False) }} limit {{ max_results_per_iter }} from '{{ watermark.table_name }}'
{%- endset -%}
{% endif -%}

{%- set paginated_result = run_query(paginated_sql) %}
{%- set paginated_n = (paginated_result | length) -%}
Expand All @@ -96,7 +102,7 @@

{%- if loop.index == max_iter -%}
{%- set msg -%}
dbt will list a maximum of {{ max_total_results }} objects in schema {{ schema_relation.database }}.{{ schema_relation.schema }}.
dbt will list a maximum of {{ max_total_results }} objects in schema {{ schema_relation }}.
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
Your schema exceeds this limit. Please contact [email protected] for troubleshooting tips,
or review and reduce the number of objects contained.
{%- endset -%}
Expand All @@ -122,10 +128,15 @@
{% macro snowflake__list_relations_without_caching(schema_relation, max_iter=10, max_results_per_iter=10000) %}

{%- set max_total_results = max_results_per_iter * max_iter -%}

{%- set sql -%}
show objects in {{ schema_relation.database }}.{{ schema_relation.schema }} limit {{ max_results_per_iter }}
{%- endset -%}
{% if schema_relation is string %}
{%- set sql -%}
show objects in {{ schema_relation }} limit {{ max_results_per_iter }}
{%- endset -%}
{% else %}
{%- set sql -%}
show objects in {{ schema_relation.include(identifier=False) }} limit {{ max_results_per_iter }}
{%- endset -%}
{% endif -%}

{%- set result = run_query(sql) -%}

Expand Down
16 changes: 7 additions & 9 deletions tests/functional/adapter/list_relations_tests/test_pagination.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os

import pytest

import json
from dbt.tests.util import run_dbt, run_dbt_and_capture
from dbt.adapters.snowflake import SnowflakeRelation # Ensure this is the correct import path

# Testing rationale:
# - snowflake SHOW TERSE OBJECTS command returns at max 10K objects in a single call
Expand Down Expand Up @@ -122,8 +121,8 @@ def test__snowflake__list_relations_without_caching_termination(self, project):
schemas = project.created_schemas

for schema in schemas:
schema_relation = {"database": database, "schema": schema}
kwargs = {"schema_relation": schema_relation}
schema_relation = SnowflakeRelation.create(database=database, schema=schema)
kwargs = {"schema_relation": schema_relation.render()}
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
_, log_output = run_dbt_and_capture(
[
"--debug",
Expand All @@ -137,7 +136,6 @@ def test__snowflake__list_relations_without_caching_termination(self, project):

parsed_logs = parse_json_logs(log_output)
n_relations = find_result_in_parsed_logs(parsed_logs, "n_relations")

assert n_relations == "n_relations: 1"


Expand Down Expand Up @@ -171,8 +169,8 @@ def test__snowflake__list_relations_without_caching(self, project):
schemas = project.created_schemas

for schema in schemas:
schema_relation = {"database": database, "schema": schema}
kwargs = {"schema_relation": schema_relation}
schema_relation = SnowflakeRelation.create(database=database, schema=schema)
kwargs = {"schema_relation": schema_relation.render()}
_, log_output = run_dbt_and_capture(
[
"--debug",
Expand All @@ -199,9 +197,9 @@ def test__snowflake__list_relations_without_caching_raise_error(self, project):
schemas = project.created_schemas

for schema in schemas:
schema_relation = {"database": database, "schema": schema}
schema_relation = SnowflakeRelation.create(database=database, schema=schema)

kwargs = {"schema_relation": schema_relation}
kwargs = {"schema_relation": schema_relation.render()}
_, log_output = run_dbt_and_capture(
[
"--debug",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
from dbt.tests.util import run_dbt


TABLE_BASE_SQL = """
-- models/my_model.sql
{{ config(schema = '1_contains_special*character$') }}
select 1 as id
"""


class TestSpecialCharactersInSchema:
@pytest.fixture(scope="class")
def project_config_update(self):
return {"quoting": {"schema": True}}

@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": TABLE_BASE_SQL,
}

def test_schema_with_special_chars(self, project):
run_dbt(["run", "-s", "my_model"])
Loading