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

i am increasing prices because i can! #114

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions macros/get_filtered_columns_in_relation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% macro get_filtered_columns_in_relation(from, except=[]) -%}
{{ return(adapter.dispatch('get_filtered_columns_in_relation', 'dbt_utils')(from, except)) }}
{% endmacro %}

{% macro default__get_filtered_columns_in_relation(from, except=[]) -%}
{%- if not execute -%}
{{ return('') }}
{% endif %}
{%- do dbt_utils._is_relation(from, 'get_filtered_columns_in_relation') -%}
{%- do dbt_utils._is_ephemeral(from, 'get_filtered_columns_in_relation') -%}

{# -- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #}


{%- set include_cols = [] %}
{%- set cols = adapter.get_columns_in_relation(from) -%}
{%- set except = except | map("lower") | list %}
{%- for col in cols -%}
{%- if col.column|lower not in except -%}
{% do include_cols.append(col.column) %}
{%- endif %}
{%- endfor %}

{{ return(include_cols) }}

{%- endmacro %}
2 changes: 1 addition & 1 deletion models/_samples/snapshot/example_join_snapshots.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ final as (
from joined
)

select * from final
select * from final order by order_id
17 changes: 17 additions & 0 deletions models/audit_helper_play.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% set dbt_relation=ref('snapshot_stg_payments') %}

{% if execute %}
{%- set old_etl_relation = adapter.get_relation(
database="RAW",
schema="STRIPE",
identifier="PAYMENT") -%}
with audit_results as (
{{ audit_helper.compare_relations(
a_relation=old_etl_relation,
b_relation=dbt_relation,
primary_key="orderid",
summarize = false
) }} )
{% endif %}
--if there are any rows where in_a and in_b are not the same, there are mismatching rows between db objects
select * from audit_results where in_a != in_b
4 changes: 4 additions & 0 deletions models/check_payment_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT column_name
FROM raw.information_schema.columns
WHERE table_schema = 'STRIPE'
AND table_name = 'PAYMENT'
6 changes: 6 additions & 0 deletions models/marts/finance/fct_payments.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
*,
null as test_col,
10 as constant
from
{{ ref('stg_stripe__payments') }}
2 changes: 2 additions & 0 deletions models/marts/operations/_operations__models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ models:
- not_null
- name: manufacturer
description: manufacturer of the part
data_tests:
- not_null
- name: name
description: name of the part
- name: brand
Expand Down
3 changes: 2 additions & 1 deletion models/marts/operations/dim_parts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ final as (
type,
size,
container,
retail_price
retail_price,
retail_price + 30 as inflation_price
from
part
)
Expand Down
1 change: 1 addition & 0 deletions models/staging/stripe/stg_stripe__payments.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- example showing staging model after snapshot


select
-- ids
id as payment_id,
Expand Down
1 change: 1 addition & 0 deletions models/staging/stripe/stg_stripe_payments_non_snapshot.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from {{ source('stripe', 'payment') }}
25 changes: 25 additions & 0 deletions models/staging/stripe/stg_stripe_payments_non_snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
models:
- name: stg_stripe_payments_non_snapshot
description: This model extracts all payment data from the Stripe source without applying any snapshot logic, providing a real-time view of payment transactions.
data_tests:
- audit_compare_relations:
dbt_model: ref('stg_stripe_payments_non_snapshot')
database: 'RAW' # Replace with the target database name
schema: 'STRIPE' # Replace with the target schema name
identifier: 'PAYMENT' # Replace with the target table name
primary_key: 'order_id'
columns:
- name: id
description: A unique identifier for each payment transaction.
- name: amount
description: The total amount of the payment transaction.
- name: currency
description: The currency in which the payment was made.
- name: created
description: The timestamp when the payment was created.
- name: status
description: The current status of the payment transaction, such as succeeded or failed.
- name: customer_id
description: A unique identifier for the customer associated with the payment.
- name: payment_method
description: The method used for the payment, such as credit card or bank transfer.
30 changes: 15 additions & 15 deletions package-lock.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
packages:
- package: dbt-labs/codegen
version: 0.9.0
- package: dbt-labs/dbt_utils
version: 1.1.0
- package: dbt-labs/audit_helper
version: 0.9.0
- package: brooklyn-data/dbt_artifacts
version: 2.6.2
- package: dbt-labs/dbt_project_evaluator
version: 0.6.0
- package: calogica/dbt_expectations
version: 0.8.5
- package: calogica/dbt_date
version: 0.7.2
sha1_hash: a17b7bdcdb4efda257369bdfd548f5104eb383a3
- package: dbt-labs/codegen
version: 0.9.0
- package: dbt-labs/dbt_utils
version: 1.1.0
- package: dbt-labs/audit_helper
version: 0.12.0
- package: brooklyn-data/dbt_artifacts
version: 2.6.2
- package: dbt-labs/dbt_project_evaluator
version: 0.6.0
- package: calogica/dbt_expectations
version: 0.8.5
- package: calogica/dbt_date
version: 0.7.2
sha1_hash: 63b5c93e38778479feac12cf895f51e16d1454e6
2 changes: 1 addition & 1 deletion packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ packages:
- package: dbt-labs/dbt_utils
version: 1.1.0
- package: dbt-labs/audit_helper
version: 0.9.0
version: 0.12.0
- package: brooklyn-data/dbt_artifacts
version: 2.6.2
- package: dbt-labs/dbt_project_evaluator
Expand Down
23 changes: 23 additions & 0 deletions tests/generic/audit_compare_relations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


{% test audit_compare_relations(dbt_model, database=none, schema=none, identifier=none, primary_key=none) %}

{% set dbt_relation= dbt_model %}

{% if execute %}
{%- set old_etl_relation = adapter.get_relation(
database= database,
schema= schema,
identifier= identifier ) -%}
with audit_results as (
{{ audit_helper.compare_relations(
a_relation=old_etl_relation,
b_relation=dbt_relation,
primary_key= primary_key ,
summarize = false
) }} )
{% endif %}
--if there are any rows where in_a and in_b are not the same, there are mismatching rows between db objects
select * from audit_results where in_a != in_b

{% endtest %}