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

Add include_data_types flag to generate_source macro #76

Merged
merged 18 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ source data is in.
column names to your source definition.
* `include_descriptions` (optional, default=False): Whether you want to add
description placeholders to your source definition.
* `include_include_data_types` (optional, default=False): Whether you want to add
GSokol marked this conversation as resolved.
Show resolved Hide resolved
data types to your source columns definitions.
* `table_pattern` (optional, default='%'): A table prefix / postfix that you
want to subselect from all available tables within a given schema.
* `exclude` (optional, default=''): A string you want to exclude from the selection criteria
Expand Down
9 changes: 9 additions & 0 deletions integration_tests/macros/integer_type_value.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{%- macro integer_type_value() -%}
{%- if target.type == "snowflake" -%}
NUMBER(38,0)
{%- elif target.type == "bigquery" -%}
INT64
{%- else -%}
INTEGER
{%- endif -%}
{%- endmacro -%}
11 changes: 11 additions & 0 deletions integration_tests/macros/text_type_value.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{%- macro text_type_value(text_length) -%}
{%- if target.type == "redshift" -%}
CHARACTER VARYING({{ text_length }})
{%- elif target.type == "snowflake" -%}
CHARACTER VARYING(16777216)
{%- elif target.type == "bigquery" -%}
STRING
{%- else -%}
TEXT
{%- endif -%}
{%- endmacro -%}
10 changes: 10 additions & 0 deletions integration_tests/tests/test_generate_source_all_args.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
database_name=target.database,
generate_columns=True,
include_descriptions=True,
include_data_types=True,
name=raw_schema
) %}

Expand All @@ -24,30 +25,39 @@ sources:
description: ""
columns:
- name: col_a
data_type: {{ integer_type_value() }}
description: ""
- name: col_b
data_type: {{ text_type_value(1) }}
GSokol marked this conversation as resolved.
Show resolved Hide resolved
description: ""

- name: data__b_relation
description: ""
columns:
- name: col_a
data_type: {{ integer_type_value() }}
description: ""
- name: col_b
data_type: {{ text_type_value(1) }}
description: ""

- name: data__campaign_analytics
description: ""
columns:
- name: source
data_type: {{ text_type_value(8) }}
description: ""
- name: medium
data_type: {{ text_type_value(8) }}
description: ""
- name: source_medium
data_type: {{ text_type_value(2) }}
description: ""
- name: analytics
data_type: {{ integer_type_value() }}
description: ""
- name: col_x
data_type: {{ text_type_value(1) }}
description: ""

{% endset %}
Expand Down
5 changes: 4 additions & 1 deletion macros/generate_source.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


---
{% macro generate_source(schema_name, database_name=target.database, generate_columns=False, include_descriptions=False, table_pattern='%', exclude='', name=schema_name, table_names=None) %}
{% macro generate_source(schema_name, database_name=target.database, generate_columns=False, include_descriptions=False, include_data_types=False, table_pattern='%', exclude='', name=schema_name, table_names=None) %}

{% set sources_yaml=[] %}
{% do sources_yaml.append('version: 2') %}
Expand Down Expand Up @@ -61,6 +61,9 @@

{% for column in columns %}
{% do sources_yaml.append(' - name: ' ~ column.name | lower ) %}
{% if include_data_types %}
{% do sources_yaml.append(' data_type: ' ~ (column.data_type | upper ) ) %}
{% endif %}
{% if include_descriptions %}
{% do sources_yaml.append(' description: ""' ) %}
{% endif %}
Expand Down