Skip to content
Draft
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
5 changes: 3 additions & 2 deletions macros/plugins/bigquery/create_external_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
{%- set external = source_node.external -%}
{%- set partitions = external.partitions -%}
{%- set options = external.options -%}
{%- set excluded_options = ['uris', 'connection_name'] %}
{%- set non_string_options = ['max_staleness'] %}

{% if options is mapping and options.get('connection_name', none) %}
{% set connection_name = options.pop('connection_name') %}
{% set connection_name = options.get('connection_name') %}
{% endif %}

{%- set uris = [] -%}
Expand Down Expand Up @@ -41,7 +42,7 @@
options (
uris = [{%- for uri in uris -%} '{{uri}}' {{- "," if not loop.last}} {%- endfor -%}]
{%- if options is mapping -%}
{%- for key, value in options.items() if key != 'uris' %}
{%- for key, value in options.items() if key not in excluded_options %}
{%- if value is string and key not in non_string_options -%}
, {{key}} = '{{value}}'
{%- else -%}
Expand Down
3 changes: 2 additions & 1 deletion macros/plugins/fabric/create_external_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
create external table {{source(source_node.source_name, source_node.name)}} (
{% for column in columns %}
{# TODO set nullity based on schema tests?? #}
{%- set nullity = 'NOT NULL' if 'not_null' in columns.tests else 'NULL'-%}
{%- set column_tests = column.tests if 'tests' in column else [] -%}
{%- set nullity = 'NOT NULL' if 'not_null' in column_tests else 'NULL'-%}
Comment on lines +12 to +13

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i like this but say more

{{adapter.quote(column.name)}} {{column.data_type}} {{nullity}}
{{- ',' if not loop.last -}}
{% endfor %}
Expand Down
6 changes: 3 additions & 3 deletions macros/plugins/redshift/helpers/add_partitions.sql

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, why?

Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#}
{% macro redshift_alter_table_add_partitions(source_node, partitions) %}

{{ log("Generating ADD PARTITION statement for partition set between "
~ partitions[0]['path'] ~ " and " ~ (partitions|last)['path']) }}

{% set ddl = [] %}

{% if partitions|length > 0 %}

{{ log("Generating ADD PARTITION statement for partition set between "
~ partitions[0]['path'] ~ " and " ~ (partitions|last)['path']) }}

{% set alter_table_add %}
alter table {{source(source_node.source_name, source_node.name)}} add if not exists
Expand Down
3 changes: 0 additions & 3 deletions macros/plugins/snowflake/refresh_external_table.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{% macro snowflake__refresh_external_table(source_node) %}

{% set external = source_node.external %}
{% set snowpipe = source_node.external.get('snowpipe', none) %}

{% set auto_refresh = external.get('auto_refresh', false) %}
{% set partitions = external.get('partitions', none) %}
{% set delta_format = (external.table_format | lower == "delta") %}
Comment on lines -4 to -8

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these do exist in the snowpipe tables which also get refreshed with refresh_external_table btw


{% set manual_refresh = not auto_refresh %}

Expand Down
37 changes: 37 additions & 0 deletions tests/test_jinja_macro_contracts.py

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this file do?!

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from pathlib import Path
from unittest import TestCase


REPO_ROOT = Path(__file__).resolve().parents[1]


def read_macro(path: str) -> str:
return (REPO_ROOT / path).read_text()


class JinjaMacroContractsTest(TestCase):
def test_bigquery_connection_name_does_not_mutate_options(self):
macro = read_macro("macros/plugins/bigquery/create_external_table.sql")

self.assertNotIn(".pop(", macro)
self.assertIn("key not in excluded_options", macro)

def test_redshift_empty_partitions_checked_before_logging_range(self):
macro = read_macro("macros/plugins/redshift/helpers/add_partitions.sql")

empty_guard = macro.index("if partitions|length > 0")
first_partition_lookup = macro.index("partitions[0]")
self.assertLess(empty_guard, first_partition_lookup)

def test_fabric_nullity_uses_current_column_tests(self):
macro = read_macro("macros/plugins/fabric/create_external_table.sql")

self.assertNotIn("columns.tests", macro)
self.assertIn("column_tests", macro)

def test_snowflake_refresh_has_no_unused_branch_variables(self):
macro = read_macro("macros/plugins/snowflake/refresh_external_table.sql")

self.assertNotIn("set snowpipe", macro)
self.assertNotIn("set partitions", macro)
self.assertNotIn("set delta_format", macro)
Comment on lines +32 to +37

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there even a pytest harness in this repo??

Loading