Skip to content

Commit

Permalink
Merge pull request #54 from ciklista/main
Browse files Browse the repository at this point in the history
Add flag to skip `compress_table` if running model in incremental mode
  • Loading branch information
joellabes authored Nov 7, 2023
2 parents 72f43ee + 7d63418 commit ad9e686
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ These models (default ephemeral) make it possible to inspect tables, columns, co

#### compress_table ([source](macros/compression.sql))

This macro returns the SQL required to auto-compress a table using the results of an `analyze compression` query. All comments, constraints, keys, and indexes are copied to the newly compressed table by this macro. Additionally, sort and dist keys can be provided to override the settings from the source table. By default, a backup table is made which is _not_ deleted. To delete this backup table after a successful copy, use `drop_backup` flag.
This macro returns the SQL required to auto-compress a table using the results of an `analyze compression` query. All comments, constraints, keys, and indexes are copied to the newly compressed table by this macro. Additionally, sort and dist keys can be provided to override the settings from the source table. By default, a backup table is made which is _not_ deleted. To delete this backup table after a successful copy, use `drop_backup` flag.
Note, that this macro will have to rewrite the entire table. The `skip_if_incremental` flag can be used to skip this macro if it is being called in an `is_incremental()` context, e.g. when used as a post-hook on an incremental model.

Macro signature:
```
Expand All @@ -69,7 +70,8 @@ Macro signature:
sort_style=none|compound|interleaved,
sort_keys=none|List<String>,
dist_style=none|all|even,
dist_key=none|String) }}
dist_key=none|String,
skip_if_incremental=False) }}
```

Example usage:
Expand Down
6 changes: 5 additions & 1 deletion macros/compression.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@

{%- macro compress_table(schema, table, drop_backup=False,
comprows=none, sort_style=none, sort_keys=none,
dist_style=none, dist_key=none) -%}
dist_style=none, dist_key=none, skip_if_incremental=False) -%}

{% if not execute %}
{{ return(none) }}
{% endif %}

{% if skip_if_incremental and is_incremental() %}
{{ return('') }}
{% endif %}

{% set recommendation = redshift.find_analyze_recommendations(schema, table, comprows) %}
{% set definition = redshift.fetch_table_definition(schema, table) %}
Expand Down

0 comments on commit ad9e686

Please sign in to comment.