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

partial whitespace fix #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
98 changes: 47 additions & 51 deletions macros/one_hot_encoder.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,58 +70,54 @@
{{ adapter.dispatch('one_hot_encoder','dbt_ml_preprocessing')(source_table, source_column, category_values, handle_unknown, col_list) }}
{%- endmacro %}

{% macro default__one_hot_encoder(source_table, source_column, category_values, handle_unknown, col_list) %}

select
{% for column in col_list %}
{{ column.name }},
{%- endfor -%}
{% for category in category_values %}
{% set no_whitespace_column_name = category | replace( " ", "_") -%}
{%- if handle_unknown=='ignore' %}
case
when {{ source_column }} = '{{ category }}' then true
else false
end as is_{{ source_column }}_{{ no_whitespace_column_name }}
{% endif %}
{%- if handle_unknown=='error' %}
case
when {{ source_column }} = '{{ category }}' then true
when {{ source_column }} in ('{{ category_values | join("','") }}') then false
else cast('Error: unknown value found and handle_unknown parameter was "error"' as boolean)
end as is_{{ source_column }}_{{ no_whitespace_column_name }}
{% endif %}
{%- if not loop.last %},{% endif -%}
{% endfor %}
from {{ source_table }}
{%- endmacro %}

{% macro sqlserver__one_hot_encoder(source_table, source_column, category_values, handle_unknown, col_list) %}
{%- macro default__one_hot_encoder(source_table, source_column, category_values, handle_unknown, col_list) -%}
select
{% for column in col_list -%}
{{ column.name }},
{% endfor %}
{%- for category in category_values -%}
{% set no_whitespace_column_name = category | replace( " ", "_") -%}
{%- if handle_unknown=='ignore' %}
case
when {{ source_column }} = '{{ category }}' then true
else false
end as is_{{ source_column }}_{{ no_whitespace_column_name }}
{%- endif -%}
{%- if handle_unknown=='error' %}
case
when {{ source_column }} = '{{ category }}' then true
when {{ source_column }} in ('{{ category_values | join("','") }}') then false
else cast('Error: unknown value found and handle_unknown parameter was "error"' as boolean)
end as is_{{ source_column }}_{{ no_whitespace_column_name }}
{%- endif -%}{%- if not loop.last -%},{%- endif -%}
{%- endfor %}
from {{ source_table }}
{%- endmacro -%}

select
{% for column in col_list %}
{{ column.name }},
{%- endfor -%}
{% for category in category_values %}
{% set no_whitespace_column_name = category | replace( " ", "_") -%}
{%- if handle_unknown=='ignore' %}
case
when {{ source_column }} = '{{ category }}' then 1
else 0
end as is_{{ source_column }}_{{ no_whitespace_column_name }}
{% endif %}
{%- if handle_unknown=='error' %}
case
when {{ source_column }} = '{{ category }}' then 1
when {{ source_column }} in ('{{ category_values | join("','") }}') then 0
else cast('Error: unknown value found and handle_unknown parameter was "error"' as bit)
end as is_{{ source_column }}_{{ no_whitespace_column_name }}
{% endif %}
{%- if not loop.last %},{% endif -%}
{% endfor %}
from {{ source_table }}
{%- endmacro %}
{%- macro sqlserver__one_hot_encoder(source_table, source_column, category_values, handle_unknown, col_list) -%}
select
{% for column in col_list -%}
{{ column.name }},
{% endfor %}
{%- for category in category_values -%}
{%- set no_whitespace_column_name = category | replace( " ", "_") -%}
{%- if handle_unknown=='ignore' %}
case
when {{ source_column }} = '{{ category }}' then 1
else 0
end as is_{{ source_column }}_{{ no_whitespace_column_name }}
{%- endif -%}
{%- if handle_unknown=='error' %}
case
when {{ source_column }} = '{{ category }}' then 1
when {{ source_column }} in ('{{ category_values | join("','") }}') then 0
else cast('Error: unknown value found and handle_unknown parameter was "error"' as bit)
end as is_{{ source_column }}_{{ no_whitespace_column_name }}
{%- endif -%}
{%- if not loop.last -%},{%- endif -%}
{%- endfor %}
from {{ source_table }}
{%- endmacro -%}

{% macro synapse__one_hot_encoder(source_table, source_column, category_values, handle_unknown, col_list) %}
{% do return( dbt_ml_preprocessing.sqlserver__one_hot_encoder(source_table, source_column, category_values, handle_unknown, col_list)) %}
Expand Down