Skip to content

Commit

Permalink
Array macros (#454)
Browse files Browse the repository at this point in the history
* Temporary dev-requirements

* Changelog entry

* Implementations and tests for array macros

* Remove `cast_array_to_string` macro

* Restore original dev-requirements.txt
  • Loading branch information
dbeatty10 authored Sep 26, 2022
1 parent ceab5ab commit 32ddd22
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20220913-084852.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Array macros
time: 2022-09-13T08:48:52.684985-06:00
custom:
Author: graciegoheen dbeatty10
Issue: "453"
PR: "454"
3 changes: 3 additions & 0 deletions dbt/include/spark/macros/utils/array_append.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro spark__array_append(array, new_element) -%}
{{ array_concat(array, array_construct([new_element])) }}
{%- endmacro %}
3 changes: 3 additions & 0 deletions dbt/include/spark/macros/utils/array_concat.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro spark__array_concat(array_1, array_2) -%}
concat({{ array_1 }}, {{ array_2 }})
{%- endmacro %}
3 changes: 3 additions & 0 deletions dbt/include/spark/macros/utils/array_construct.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro spark__array_construct(inputs, data_type) -%}
array( {{ inputs|join(' , ') }} )
{%- endmacro %}
15 changes: 15 additions & 0 deletions tests/functional/adapter/utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest

from dbt.tests.adapter.utils.test_array_append import BaseArrayAppend
from dbt.tests.adapter.utils.test_array_concat import BaseArrayConcat
from dbt.tests.adapter.utils.test_array_construct import BaseArrayConstruct
from dbt.tests.adapter.utils.test_any_value import BaseAnyValue
from dbt.tests.adapter.utils.test_bool_or import BaseBoolOr
from dbt.tests.adapter.utils.test_cast_bool_to_text import BaseCastBoolToText
Expand Down Expand Up @@ -31,6 +34,18 @@ class TestAnyValue(BaseAnyValue):
pass


class TestArrayAppend(BaseArrayAppend):
pass


class TestArrayConcat(BaseArrayConcat):
pass


class TestArrayConstruct(BaseArrayConstruct):
pass


class TestBoolOr(BaseBoolOr):
pass

Expand Down

0 comments on commit 32ddd22

Please sign in to comment.