From bac63f26e196380d9216d41d65fe5126a20731bd Mon Sep 17 00:00:00 2001 From: 0xRob <83790096+0xRobin@users.noreply.github.com> Date: Mon, 9 Jan 2023 16:37:27 +0100 Subject: [PATCH] Allow for local compile of incremental models. (#2403) * base is_incremental * add force-incremental variable --- macros/dune/is_incremental.sql | 18 ++++++++++++++++++ macros/dune/macros_schema.yml | 10 ++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 macros/dune/is_incremental.sql diff --git a/macros/dune/is_incremental.sql b/macros/dune/is_incremental.sql new file mode 100644 index 00000000000..39cd360ec05 --- /dev/null +++ b/macros/dune/is_incremental.sql @@ -0,0 +1,18 @@ +{% macro is_incremental() %} + {#-- allow for command line compile of incremental models #} + {#-- Usage: dbt compile --vars '{force-incremental: True}' #} + {% if var('force-incremental', False) %} + {{ return(True) }} + {% endif %} + + {#-- do not run introspective queries in parsing #} + {% if not execute %} + {{ return(False) }} + {% else %} + {% set relation = adapter.get_relation(this.database, this.schema, this.table) %} + {{ return(relation is not none + and relation.type == 'table' + and model.config.materialized == 'incremental' + and not should_full_refresh()) }} + {% endif %} +{% endmacro %} diff --git a/macros/dune/macros_schema.yml b/macros/dune/macros_schema.yml index d3213da0d95..7870486a38a 100644 --- a/macros/dune/macros_schema.yml +++ b/macros/dune/macros_schema.yml @@ -9,7 +9,7 @@ macros: description: "Custom schema name" - name: node type: column name or expression - description: "Node" + description: "Node" - name: generate_alias_name description: "This overrides the dbt-core function for setting aliases. For PR test, the alias is set to the user schema and file name. " @@ -38,4 +38,10 @@ macros: - name: spark__create_csv_table description: > - Same as create_table_as but for seeds with spark package \ No newline at end of file + Same as create_table_as but for seeds with spark package + + - name: is_incremental + description: > + Overrides the core is_incremental marco to allow the usage of a force-incremental command line variable. + This enables us to easily get the compiled incremental models. + Example usage: dbt compile --vars '{force-incremental: True}'