-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinteract.sql
More file actions
29 lines (23 loc) · 1.25 KB
/
Copy pathinteract.sql
File metadata and controls
29 lines (23 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{% macro interact(column_one, column_two, interaction='multiplicative') %}
{# Validate inputs #}
{% if column_one is none or column_one == '' %}
{{ exceptions.raise_compiler_error("interact: 'column_one' parameter is required and cannot be empty.") }}
{% endif %}
{% if column_two is none or column_two == '' %}
{{ exceptions.raise_compiler_error("interact: 'column_two' parameter is required and cannot be empty.") }}
{% endif %}
{% set valid_interactions = ['multiplicative', 'additive', 'exponential'] %}
{% if interaction not in valid_interactions %}
{{ exceptions.raise_compiler_error("interact: Invalid interaction '" ~ interaction ~ "'. Valid options are: " ~ valid_interactions | join(", ") ~ ".") }}
{% endif %}
{{ return(adapter.dispatch('interact', 'dbt_ml_inline_preprocessing')(column_one, column_two, interaction)) }}
{% endmacro %}
{% macro default__interact(column_one, column_two, interaction) %}
{% if interaction == 'multiplicative' %}
({{ column_one }} * {{ column_two }})
{% elif interaction == 'additive' %}
({{ column_one }} + {{ column_two }})
{% elif interaction == 'exponential' %}
POW({{ column_one }}, {{ column_two }})
{% endif %}
{% endmacro %}