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: add id macro DNA-12353 (DNA-19240) #69

Merged
merged 4 commits into from
Oct 5, 2023
Merged
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 5 additions & 0 deletions macros/multiple_databases/id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{%- macro id() -%}

row_number() over (order by (select null))

{%- endmacro -%}