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

Use single quotes in gets in templates #889

Merged
merged 1 commit into from
Dec 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{% set batch_size = get_batch_size() %}
{% set column_override = model['config'].get('column_types', {}) %}
{% set must_cast = model['config'].get("file_format", "delta") == "parquet" %}
{% set must_cast = model['config'].get('file_format', 'delta') == 'parquet' %}

{% set statements = [] %}

Expand Down
34 changes: 17 additions & 17 deletions dbt/include/databricks/macros/relations/constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,27 @@

{% macro get_constraint_sql(relation, constraint, model, column={}) %}
{% set statements = [] %}
{% set type = constraint.get("type", "") %}
{% set type = constraint.get('type', '') %}

{% if type == 'check' %}
{% set expression = constraint.get("expression", "") %}
{% set expression = constraint.get('expression', '') %}
{% if not expression %}
{{ exceptions.raise_compiler_error('Invalid check constraint expression') }}
{% endif %}

{% set name = constraint.get("name") %}
{% set name = constraint.get('name') %}
{% if not name %}
{% if local_md5 %}
{{ exceptions.warn("Constraint of type " ~ type ~ " with no `name` provided. Generating hash instead for relation " ~ relation.identifier) }}
{%- set name = local_md5 (relation.identifier ~ ";" ~ column.get("name", "") ~ ";" ~ expression ~ ";") -%}
{%- set name = local_md5 (relation.identifier ~ ";" ~ column.get('name', '') ~ ";" ~ expression ~ ";") -%}
{% else %}
{{ exceptions.raise_compiler_error("Constraint of type " ~ type ~ " with no `name` provided, and no md5 utility.") }}
{% endif %}
{% endif %}
{% set stmt = "alter table " ~ relation ~ " add constraint " ~ name ~ " check (" ~ expression ~ ");" %}
{% do statements.append(stmt) %}
{% elif type == 'not_null' %}
{% set column_names = constraint.get("columns", []) %}
{% set column_names = constraint.get('columns', []) %}
{% if column and not column_names %}
{% set column_names = [column['name']] %}
{% endif %}
Expand All @@ -144,7 +144,7 @@
{% if constraint.get('warn_unenforced') %}
{{ exceptions.warn("unenforced constraint type: " ~ type)}}
{% endif %}
{% set column_names = constraint.get("columns", []) %}
{% set column_names = constraint.get('columns', []) %}
{% if column and not column_names %}
{% set column_names = [column['name']] %}
{% endif %}
Expand All @@ -161,7 +161,7 @@

{% set joined_names = quoted_names|join(", ") %}

{% set name = constraint.get("name") %}
{% set name = constraint.get('name') %}
{% if not name %}
{% if local_md5 %}
{{ exceptions.warn("Constraint of type " ~ type ~ " with no `name` provided. Generating hash instead for relation " ~ relation.identifier) }}
Expand All @@ -178,7 +178,7 @@
{{ exceptions.warn("unenforced constraint type: " ~ constraint.type)}}
{% endif %}

{% set name = constraint.get("name") %}
{% set name = constraint.get('name') %}

{% if constraint.get('expression') %}

Expand All @@ -193,7 +193,7 @@

{% set stmt = "alter table " ~ relation ~ " add constraint " ~ name ~ " foreign key" ~ constraint.get('expression') %}
{% else %}
{% set column_names = constraint.get("columns", []) %}
{% set column_names = constraint.get('columns', []) %}
{% if column and not column_names %}
{% set column_names = [column['name']] %}
{% endif %}
Expand All @@ -210,7 +210,7 @@

{% set joined_names = quoted_names|join(", ") %}

{% set parent = constraint.get("to") %}
{% set parent = constraint.get('to') %}
{% if not parent %}
{{ exceptions.raise_compiler_error('No parent table defined for foreign key: ' ~ expression) }}
{% endif %}
Expand All @@ -228,21 +228,21 @@
{% endif %}

{% set stmt = "alter table " ~ relation ~ " add constraint " ~ name ~ " foreign key(" ~ joined_names ~ ") references " ~ parent %}
{% set parent_columns = constraint.get("to_columns") %}
{% set parent_columns = constraint.get('to_columns') %}
{% if parent_columns %}
{% set stmt = stmt ~ "(" ~ parent_columns|join(", ") ~ ")"%}
{% endif %}
{% endif %}
{% set stmt = stmt ~ ";" %}
{% do statements.append(stmt) %}
{% elif type == 'custom' %}
{% set expression = constraint.get("expression", "") %}
{% set expression = constraint.get('expression', '') %}
{% if not expression %}
{{ exceptions.raise_compiler_error('Missing custom constraint expression') }}
{% endif %}

{% set name = constraint.get("name") %}
{% set expression = constraint.get("expression") %}
{% set name = constraint.get('name') %}
{% set expression = constraint.get('expression') %}
{% if not name %}
{% if local_md5 %}
{{ exceptions.warn("Constraint of type " ~ type ~ " with no `name` provided. Generating hash instead for relation " ~ relation.identifier) }}
Expand All @@ -264,15 +264,15 @@
{# convert constraints defined using the original databricks format #}
{% set dbt_constraints = [] %}
{% for constraint in constraints %}
{% if constraint.get and constraint.get("type") %}
{% if constraint.get and constraint.get('type') %}
{# already in model contract format #}
{% do dbt_constraints.append(constraint) %}
{% else %}
{% if column %}
{% if constraint == "not_null" %}
{% do dbt_constraints.append({"type": "not_null", "columns": [column.get("name")]}) %}
{% do dbt_constraints.append({"type": "not_null", "columns": [column.get('name')]}) %}
{% else %}
{{ exceptions.raise_compiler_error('Invalid constraint for column ' ~ column.get("name", "") ~ '. Only `not_null` is supported.') }}
{{ exceptions.raise_compiler_error('Invalid constraint for column ' ~ column.get('name', "") ~ '. Only `not_null` is supported.') }}
{% endif %}
{% else %}
{% set name = constraint['name'] %}
Expand Down
Loading