-
Notifications
You must be signed in to change notification settings - Fork 17
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
[WIP] - Partitioning support #78
base: main
Are you sure you want to change the base?
Conversation
{{ adapter.dispatch('get_column_names', 'dbt')() }} | ||
) | ||
{%- set sql = get_select_subquery(sql) %} | ||
{% if config.get('partition_by') != None %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I separated the logic for partitioning as it's easier to read. When partioning is not enabled, the code is exactly the same as before.
alter table {{ from_relation }} rename to {{ target_name }}; | ||
|
||
{# If the relation is partitioned, rename the subtables #} | ||
{% set existing_partitions_query %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partitions are created with the __dbt_tmp suffix and so they need to be individually renamed. Sadly I don't think the config
variable is available here so I don't know if there's a way to determine if the relation is partitioned.
{% endmacro %} | ||
|
||
{% macro postgres__get_incremental_delete_insert_sql(arg_dict) %} | ||
{{ create_incremental_missing_partitions(arg_dict) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was parsed but not executed.
When I wrote the following, it was executed and the partition was created.
{% do return(
create_incremental_missing_partitions(arg_dict) + default__get_incremental_delete_insert_sql(arg_dict)
) %}
Do you have any plans for when these changes will be available in the master branch? |
resolves #168
Problem
This is a draft PR adding partitioning support for Postgres as stated on #168. It doesn't use dbt coding best practices and lacks, but it works. I'm opening it to gather feedback on how to proceed.
Syntax is copied from on dbt-bigquery partitioning:
Benefits this brings:
Moreover, creating a custom incremental strategy replacing partitions is then relatively easy as shown in #168. That incremental strategy is out of scope for this PR as there are a lot of possible variations.
IMO this patch is already in a stage that can be reviewed. I would help on some best practices and adding tests though.
Solution
To Do:
Add a default partition to handle uncovered ranges. Without specific partition support on incremental strategies, one must handle creation of future partitions. This can be done via a cron job or manually. Having a default partition means inserts won't fail.Handle incremental partitionsChecklist