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

Release/v1.0 #2

Merged
merged 20 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
70 changes: 70 additions & 0 deletions .github/workflows/ci-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CI

on:
pull_request:

# Automatically cancel any previous runs of this workflow
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
ci-check-snowflake:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./integration_tests
env:
SNOWFLAKE_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }}
SNOWFLAKE_USER_CI: ${{ secrets.SNOWFLAKE_CI_USER }}
SNOWFLAKE_PASSWORD_CI: ${{ secrets.SNOWFLAKE_CI_USER_PASSWORD }}
SNOWFLAKE_DATABASE_CI: DBT_PACKAGE_CI
SNOWFLAKE_ROLE_CI: PACKAGE_CI_ROLE
SNOWFLAKE_WAREHOUSE_CI: PACKAGE_CI_WH
SNOWFLAKE_SCHEMA_CI: DBT_CI_${{github.event.number}}_${{ github.actor }} # Creates a unique schema for each PR
steps:
- name: Checkout branch
id: checkout-branch
uses: actions/checkout@v3

- name: Install Poetry
id: install-poetry
run: |
pipx install poetry
- name: setup-python
id: setup-python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: 'poetry' # Auto cache based on poetry.lock

- name: Install python deps
id: install-python-deps
run: |
poetry install
- name: Install dbt deps
id: install-dbt-deps
run: |
poetry run dbt deps
- name: Check dbt compiles and CI Profiles work
id: check-dbt-ci-profiles-work
run: |
poetry run dbt debug --target snowflake-ci
- name: dbt seed on Snowflake
id: dbt-seed-snowflake
run: |
poetry run dbt seed --target snowflake-ci
- name: dbt run on Snowflake
id: dbt-run-snowflake
run: |
poetry run dbt run --full-refresh --target snowflake-ci
- name: dbt test on Snowflake
id: dbt-test-snowflake
run: |
poetry run dbt test --target snowflake-ci
4 changes: 0 additions & 4 deletions .sqlfluffignore

This file was deleted.

674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ log-path: "logs"

models:
tasman_dbt_revenuecat:
+materialized: table
+materialized: table
+schema: revenuecat
File renamed without changes.
4 changes: 1 addition & 3 deletions integration_tests/package-lock.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
packages:
- local: ../
- package: dbt-labs/dbt_utils
version: 1.1.1
sha1_hash: 7ddc9cc629d204960cdbec3d712481aace9ed5d3
sha1_hash: de2deba3d66ce03d8c02949013650cc9b94f6030
5 changes: 1 addition & 4 deletions integration_tests/packages.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
packages:
- local: ../

- package: dbt-labs/dbt_utils
version: 1.1.1
- local: ../
13 changes: 13 additions & 0 deletions integration_tests/profiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tasman_integration_tests:
outputs:
snowflake-ci:
account: "{{ env_var('SNOWFLAKE_ACCOUNT') }}"
client_session_keep_alive: true
database: "{{ env_var('SNOWFLAKE_DATABASE_CI') }}"
user: "{{ env_var('SNOWFLAKE_USER_CI') }}"
password: "{{ env_var('SNOWFLAKE_PASSWORD_CI') }}"
role: "{{ env_var('SNOWFLAKE_ROLE_CI') }}"
schema: "{{ env_var('SNOWFLAKE_SCHEMA_CI') }}"
warehouse: "{{ env_var('SNOWFLAKE_WAREHOUSE_CI') }}"
threads: 12
type: snowflake
75 changes: 75 additions & 0 deletions macros/date_spine.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{% macro get_intervals_between(start_date, end_date, datepart) -%}
{{ return(adapter.dispatch('get_intervals_between', 'tasman_dbt_revenuecat')(start_date, end_date, datepart)) }}
{%- endmacro %}

{% macro default__get_intervals_between(start_date, end_date, datepart) -%}
{%- call statement('get_intervals_between', fetch_result=True) %}

select {{ dbt.datediff(start_date, end_date, datepart) }}

{%- endcall -%}

{%- set value_list = load_result('get_intervals_between') -%}

{%- if value_list and value_list['data'] -%}
{%- set values = value_list['data'] | map(attribute=0) | list %}
{{ return(values[0]) }}
{%- else -%}
{{ return(1) }}
{%- endif -%}

{%- endmacro %}




{% macro date_spine(datepart, start_date, end_date) %}
{{ return(adapter.dispatch('date_spine', 'tasman_dbt_revenuecat')(datepart, start_date, end_date)) }}
{%- endmacro %}

{% macro default__date_spine(datepart, start_date, end_date) %}


{# call as follows:

date_spine(
"day",
"to_date('01/01/2016', 'mm/dd/yyyy')",
"dbt.dateadd(week, 1, current_date)"
) #}


with rawdata as (

{{tasman_dbt_revenuecat.generate_series(
tasman_dbt_revenuecat.get_intervals_between(start_date, end_date, datepart)
)}}

),

all_periods as (

select (
{{
dbt.dateadd(
datepart,
"row_number() over (order by 1) - 1",
start_date
)
}}
) as date_{{datepart}}
from rawdata

),

filtered as (

select *
from all_periods
where date_{{datepart}} <= {{ end_date }}

)

select * from filtered

{% endmacro %}
53 changes: 53 additions & 0 deletions macros/generate_series.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% macro get_powers_of_two(upper_bound) %}
{{ return(adapter.dispatch('get_powers_of_two', 'tasman_dbt_revenuecat')(upper_bound)) }}
{% endmacro %}

{% macro default__get_powers_of_two(upper_bound) %}

{% if upper_bound <= 0 %}
{{ exceptions.raise_compiler_error("upper bound must be positive") }}
{% endif %}

{% for _ in range(1, 100) %}
{% if upper_bound <= 2 ** loop.index %}{{ return(loop.index) }}{% endif %}
{% endfor %}

{% endmacro %}


{% macro generate_series(upper_bound) %}
{{ return(adapter.dispatch('generate_series', 'tasman_dbt_revenuecat')(upper_bound)) }}
{% endmacro %}

{% macro default__generate_series(upper_bound) %}

{% set n = tasman_dbt_revenuecat.get_powers_of_two(upper_bound) %}

with p as (
select 0 as generated_number union all select 1
), unioned as (

select

{% for i in range(n) %}
p{{i}}.generated_number * power(2, {{i}})
{% if not loop.last %} + {% endif %}
{% endfor %}
+ 1
as generated_number

from

{% for i in range(n) %}
p as p{{i}}
{% if not loop.last %} cross join {% endif %}
{% endfor %}

)

select *
from unioned
where generated_number <= {{upper_bound}}
order by generated_number

{% endmacro %}
29 changes: 29 additions & 0 deletions macros/generate_surrogate_key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{%- macro generate_surrogate_key(field_list) -%}
{{ return(adapter.dispatch('generate_surrogate_key', 'tasman_dbt_revenuecat')(field_list)) }}
{% endmacro %}

{%- macro default__generate_surrogate_key(field_list) -%}

{%- if var('surrogate_key_treat_nulls_as_empty_strings', False) -%}
{%- set default_null_value = "" -%}
{%- else -%}
{%- set default_null_value = '_tasman_dbt_revenuecat_surrogate_key_null_' -%}
{%- endif -%}

{%- set fields = [] -%}

{%- for field in field_list -%}

{%- do fields.append(
"coalesce(cast(" ~ field ~ " as " ~ dbt.type_string() ~ "), '" ~ default_null_value ~"')"
) -%}

{%- if not loop.last %}
{%- do fields.append("'-'") -%}
{%- endif -%}

{%- endfor -%}

{{ dbt.hash(dbt.concat(fields)) }}

{%- endmacro -%}
33 changes: 33 additions & 0 deletions macros/get_single_value.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% macro get_single_value(query, default=none) %}
{{ return(adapter.dispatch('get_single_value', 'tasman_dbt_revenuecat')(query, default)) }}
{% endmacro %}

{% macro default__get_single_value(query, default) %}

{# This macro returns the (0, 0) record in a query, i.e. the first row of the first column #}

{%- call statement('get_query_result', fetch_result=True, auto_begin=false) -%}

{{ query }}

{%- endcall -%}

{%- if execute -%}

{% set r = load_result('get_query_result').table.columns[0].values() %}
{% if r | length == 0 %}
{% do print('Query `' ~ query ~ '` returned no rows. Using the default value: ' ~ default) %}
{% set sql_result = default %}
{% else %}
{% set sql_result = r[0] %}
{% endif %}

{%- else -%}

{% set sql_result = default %}

{%- endif -%}

{% do return(sql_result) %}

{% endmacro %}
Loading
Loading