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

feat: run dbt in batches for document_metadata model #174

Open
wants to merge 8 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
4 changes: 4 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ profile: 'default'

on-run-end:
- "{{ log_dbt_results(results) }}"

vars:
start_timestamp: null
batch_size: null
34 changes: 26 additions & 8 deletions models/root/document_metadata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,30 @@
)
}}

SELECT
_id as uuid,
_deleted,
saved_timestamp,
doc->>'type' as doc_type
from {{ source('couchdb', env_var('POSTGRES_TABLE')) }} source_table
{% if is_incremental() %}
WHERE source_table.saved_timestamp >= {{ max_existing_timestamp('saved_timestamp') }}
WITH source_table_CTE AS (
SELECT
_id as uuid,
_deleted,
saved_timestamp,
doc->>'type' as doc_type
FROM {{ source('couchdb', env_var('POSTGRES_TABLE')) }}
)

{% if var("start_timestamp") is not none and var("batch_size") is not none %}
SELECT *
FROM source_table_CTE
WHERE saved_timestamp >= '{{ var("start_timestamp") }}'
ORDER BY saved_timestamp
LIMIT {{ var('batch_size') }}
{% else %}

SELECT
_id as uuid,
_deleted,
saved_timestamp,
doc->>'type' as doc_type
FROM {{ source('couchdb', env_var('POSTGRES_TABLE')) }} source_table
{% if is_incremental() %}
WHERE source_table.saved_timestamp >= {{ max_existing_timestamp('saved_timestamp') }}
{% endif %}
{% endif %}
Loading