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

feature/passthrough-ids #58

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ vars:
### Daily Issue Field History Columns
The `jira__daily_issue_field_history` model generates historical data for the columns specified by the `issue_field_history_columns` variable. By default, the only columns tracked are `status` and `sprint`, but all fields found in the `field_name` column within the Jira `FIELD` table can be included in this model. The most recent value of any tracked column is also captured in `jira__issue_enhanced`.

Additionally, if you are concerned about the mutable nature of the `field_name` being used for the custom fields. This package includes another variable `issue_field_history_columns_ids` that can be used to include the `field_id` value of your custom fields. A positive of this is that the materialized models will leverage the `field_name` for the column name. Please note if your field names are constantly changing then new columns will appear in your end model.

**If you would like to change these columns, add the following configuration to your dbt_project.yml file. Then, after adding the columns to your `dbt_project.yml` file, run the `dbt run --full-refresh` command to fully refresh any existing models.**

```yml
Expand All @@ -60,6 +62,7 @@ config-version: 2
vars:
jira:
issue_field_history_columns: ['the', 'list', 'of', 'field', 'names']
issue_field_history_columns_ids: ['this_id', 'that_id', 'ids_id']
```

> Note: `sprint` and `status` will always be tracked, as they are necessary for creating common agile reports.
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: 'jira'
version: '0.8.1'
version: '0.8.2'
config-version: 2
require-dbt-version: [">=1.0.0", "<2.0.0"]

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'jira_integration_tests'
version: '0.8.1'
version: '0.8.2'
config-version: 2
profile: 'integration_tests'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ limit_to_relevant_fields as (

from combined_field_histories

where lower(field_id) = 'status' -- As sprint is a custom field, we filter by field name only for sprint. All others are on field_id.
-- As sprint is a custom field, we filter by field name only for sprint. All others are on field_id.
where lower(field_id) in ('status'
{%- for col in var('issue_field_history_columns_ids', []) -%}
,'{{ (col|lower) }}'
{%- endfor -%} )

or lower(field_name) in ('status'
{%- for col in var('issue_field_history_columns', []) -%}
,'{{ (col|lower) }}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,23 @@ pivot_out as (
max(case when lower(field_name) = 'sprint' then field_value end) as sprint -- As sprint is a custom field, we aggregate on the field_name.

{% for col in var('issue_field_history_columns', []) -%}
,
max(case when lower(field_name) = '{{ col|lower }}' then field_value end) as {{ dbt_utils.slugify(col) | replace(' ', '_') | lower }}
, max(case when lower(field_name) = '{{ col|lower }}' then field_value end) as {{ dbt_utils.slugify(col) | replace(' ', '_') | lower }}
{% endfor -%}

{% if var('issue_field_history_columns_ids', []) != [] %}
{% for col in var('issue_field_history_columns_ids', []) -%}

--Map the corresponding field id that is used in the variable to the field name from the staging model
{% set name_mapping = dbt_utils.get_column_values(
table=ref('stg_jira__field'),
column='field_name',
where="field_id = '" ~ col ~ "'")
%}

, max(case when lower(field_id) = '{{ col|lower }}' then field_value end) as {{ dbt_utils.slugify(name_mapping[0]) | replace(' ', '_') | lower }}
{% endfor -%}
{%endif %}

from daily_field_history

group by 1,2
Expand Down