From 3e0b14b828b3f24b2da9d23c52c47d2addf54978 Mon Sep 17 00:00:00 2001 From: Jasper Selman Date: Wed, 4 Oct 2023 10:29:33 +0200 Subject: [PATCH 1/4] feat: introduce id macro --- macros/multiple_databases/id.sql | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 macros/multiple_databases/id.sql diff --git a/macros/multiple_databases/id.sql b/macros/multiple_databases/id.sql new file mode 100644 index 0000000..32acd93 --- /dev/null +++ b/macros/multiple_databases/id.sql @@ -0,0 +1,5 @@ +{%- macro id() -%} + +row_number() over (order by (select null)) + +{%- endmacro -%} From b7b07ffa85f53b4a399788bebccd6b91154d593f Mon Sep 17 00:00:00 2001 From: Jasper Selman Date: Wed, 4 Oct 2023 11:44:22 +0200 Subject: [PATCH 2/4] chore: move generate_id to the deprecated folder --- macros/{multiple_databases => deprecated}/generate_id.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename macros/{multiple_databases => deprecated}/generate_id.sql (100%) diff --git a/macros/multiple_databases/generate_id.sql b/macros/deprecated/generate_id.sql similarity index 100% rename from macros/multiple_databases/generate_id.sql rename to macros/deprecated/generate_id.sql From 6235515451e416fefd905ac9dfef49b41622db9e Mon Sep 17 00:00:00 2001 From: Jasper Selman Date: Thu, 5 Oct 2023 10:06:24 +0200 Subject: [PATCH 3/4] docs: update README with the id macro changes - add a note that generate_id macro will be deprecated - add the description for the new id macro --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index b3c7470..24edbbf 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ This dbt package contains macros for SQL functions to run the dbt project on mul - [date_from_timestamp](#date_from_timestamp-source) - [datediff](#datediff-source) - [generate_id](#generate_id-source) + - [id](#id-source) - [min_boolean](#min_boolean-source) - [string_agg](#string_agg-source) - [timestamp_from_date](#timestamp_from_date-source) @@ -103,6 +104,8 @@ Usage: `{{ pm_utils.datediff('[datepart]', '[start_date_expression]', '[end_date_expression]') }}` #### generate_id ([source](macros/multiple_databases/generate_id.sql)) +**Note:** this macro is deprecated and will be removed in a future release. To create an ID, the `id()` macro should be used. + This macro generates an id field for the current model. This macro can only be used in a dbt post-hook. With the argument you specify the name of the id field which can be referenced in next transformations like any other field. Usage: @@ -112,6 +115,12 @@ Usage: ) }} ``` +#### id ([source](macros/multiple_databases/id.sql)) +This macro generates an id field that can be used as a column for the current model. + +Usage: +`{{ pm_utils.id() }}` + #### min_boolean ([source](macros/multiple_databases/min_boolean.sql)) This macro selects the minimum of the records in an aggregate expression for boolean fields. From 56d87a48edfe420bf6f527eedc3c92dd46eb98be Mon Sep 17 00:00:00 2001 From: Jasper Selman Date: Wed, 4 Oct 2023 11:53:43 +0200 Subject: [PATCH 4/4] chore: update dbt version --- dbt_project.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_project.yml b/dbt_project.yml index de91130..e33cb32 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,5 +1,5 @@ name: 'pm_utils' -version: '0.14.5' +version: '0.15.0' config-version: 2 require-dbt-version: [">=1.0.0", "<2.0.0"]