Skip to content

Commit

Permalink
Fix quoted identifiers in the generate_base_model macro for BigQuery (
Browse files Browse the repository at this point in the history
#199)

* Use `adapter.quote` to create a case-sensitive quoted identifier for column names

* Force a failure for all adapters to help troubleshoot

* Revert "Force a failure for all adapters to help troubleshoot"

This reverts commit d707832.

* Use `adapter.quote` to create a case-sensitive quoted identifier for column names in `generate_base_model` macro
  • Loading branch information
dbeatty10 authored Nov 21, 2024
1 parent c959e4d commit b444bf8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions integration_tests/macros/operations/create_source_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ set enable_case_sensitive_identifier to true;
{% set create_table_sql_case_sensitive %}
create table {{ target_schema }}.codegen_integration_tests__data_source_table_case_sensitive as (
select
1 as {% if target.type == "bigquery" %}My_Integer_Col{% else %}"My_Integer_Col"{% endif %},
true as {% if target.type == "bigquery" %}My_Bool_Col{% else %}"My_Bool_Col"{% endif %}
1 as {{ adapter.quote("My_Integer_Col") }},
true as {{ adapter.quote("My_Bool_Col") }}
)
{% endset %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ with source as (
renamed as (

select
{% if target.type == "bigquery" %}My_Integer_Col{% else %}"My_Integer_Col"{% endif %}
, {% if target.type == "bigquery" %}My_Bool_Col{% else %}"My_Bool_Col"{% endif %}
{{ adapter.quote("My_Integer_Col") }}
, {{ adapter.quote("My_Bool_Col") }}

from source

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ with source as (
renamed as (

select
{% if target.type == "bigquery" %}My_Integer_Col{% else %}"My_Integer_Col"{% endif %},
{% if target.type == "bigquery" %}My_Bool_Col{% else %}"My_Bool_Col"{% endif %}
{{ adapter.quote("My_Integer_Col") }},
{{ adapter.quote("My_Bool_Col") }}

from source

Expand Down
4 changes: 2 additions & 2 deletions macros/generate_base_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ renamed as (
select
{%- if leading_commas -%}
{%- for column in column_names %}
{{", " if not loop.first}}{% if not case_sensitive_cols %}{{ column | lower }}{% elif target.type == "bigquery" %}{{ column }}{% else %}{{ "\"" ~ column ~ "\"" }}{% endif %}
{{", " if not loop.first}}{% if not case_sensitive_cols %}{{ column | lower }}{% else %}{{ adapter.quote(column) }}{% endif %}
{%- endfor %}
{%- else -%}
{%- for column in column_names %}
{% if not case_sensitive_cols %}{{ column | lower }}{% elif target.type == "bigquery" %}{{ column }}{% else %}{{ "\"" ~ column ~ "\"" }}{% endif %}{{"," if not loop.last}}
{% if not case_sensitive_cols %}{{ column | lower }}{% else %}{{ adapter.quote(column) }}{% endif %}{{"," if not loop.last}}
{%- endfor -%}
{%- endif %}

Expand Down

0 comments on commit b444bf8

Please sign in to comment.