datavault4dbt icon indicating copy to clipboard operation
datavault4dbt copied to clipboard

Add prejoining condition parameter

Open lorogno opened this issue 1 year ago • 1 comments

Description

This PR handles issue #370. A new Parameter "condition" is introduced to Prejoining which allows to define a custom condition for each Join.

@tkiehn @tkirschke Hope its helpful for the Package in general, feel free to review it and give me Feedback :) Actually only in Staging-Template for databricks. But would be the same pattern. Open to apply it as well to all other platforms when general approach is approved.

Parameter Description:

Key: condition (optional) DataType: string | list Explanation: Can be used optionally to define custom join conditions. If a single condition is defined as string it will apply the condition to all joins. If multiple conditions are defined it will be applied in the according order. The Default condition will be '='. Supported conditions: ['<>', '!=', '=', '<=', '>=', '<', '>']. The Condition Parameter should be quoted in the Template.

Condition-Examples:

prejoined_columns:
    - extract_columns: 
         - account_id
      aliases:
         - acc_id
      ref_model: account_sap
      this_column_name: 
        - acc_code
        - active_date
        - active_date
      ref_column_name: 
        - account_kuerzel
        - acc_valid_from
        - acc_valid_to
      condition:
        - '='
        - '>='
        - '<='

=> Will lead to 3 Joins with: acc_code = account_kuerzel and active_date >= acc_valid_from and active_date <= acc_valid_to

prejoined_columns:
    - extract_columns: 
         - account_id
      aliases:
         - acc_id
      ref_model: account_sap
      this_column_name: 
        - acc_code
      ref_column_name: 
        - account_kuerzel

=> Will lead to normal Join with: acc_code = account_kuerzel

prejoined_columns:
    - extract_columns: 
         - account_id
      aliases:
         - acc_id
      ref_model: account_sap
      this_column_name: 
        - acc_code
        - name
      ref_column_name: 
        - account_kuerzel
        - name_lang
     condition: '!='

=> Lead that all joins using the defined condition: acc_code != account_kuerzel and name != name_lang

Tests & Allowed Values

The following Tests are implemented and results in error if not fulfilled:

  • The length of conditions (if list) needs to be identical with the length of source_columns
  • The allowed conditions are ['<>', '!=', '=', '<=', '>=', '<', '>']

Type of change

  • [x] New feature (non-breaking change which adds functionality)
  • [x] This change requires a documentation update

How Has This Been Tested?

  • [x] Test a Staging config without condition Parameter to guarantee Backward Compatability
  • [x] Test a Staging config with a single condition (string)
  • [x] Test a Staging config with multiple conditions (list)
  • [x] Test a Staging config with invalid conditions or non-matching length of conditions with source_columns

Test Configuration:

  • datavault4dbt-Version: 1.10.0
  • dbt-Version: core, version number: 1.10.11
  • dbt-adapter-Version: 1.10.12

Checklist:

  • [x] I have performed a self-review of my code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation or included information that needs updates (e.g. in the Wiki)

lorogno avatar Sep 29 '25 11:09 lorogno

Hey @tkiehn! Thanks for your Review :) I will have a look asap to them and try to improve it (may also consider the recommended refactoring). But might take time.

Beste regards

Jan

lorogno avatar Oct 06 '25 06:10 lorogno