-
Notifications
You must be signed in to change notification settings - Fork 3
/
feature_json.sql
30 lines (29 loc) · 1.21 KB
/
feature_json.sql
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
30
{# Given a list of feature columns -- encodes them into a json type column called feature_json #}
{% macro feature_json(feature_columns) %}
{%- if feature_columns is not none -%}
{% if target.type == 'redshift' %}
object(
{%- for column in feature_columns -%}
'{{column}}', "{{column}}"{% if not loop.last %}, {% endif %}
{%- endfor -%}
)
{% elif target.type == 'bigquery' %}
to_json(struct({{ feature_columns|join(', ') }}))
{% elif target.type == 'snowflake' %}
object_construct(
{%- for column in feature_columns -%}
'{{column}}', {{column}}{% if not loop.last %}, {% endif %}
{%- endfor -%}
)
{% elif target.type == 'postgres' %}
json_build_object(
{%- for column in feature_columns -%}
'{{column}}', "{{column}}"{% if not loop.last %}, {% endif %}
{%- endfor -%}
)
{% else %}
{{ exceptions.raise_compiler_error(target.type ~" not supported in this project") }}
{% endif %}
as feature_json
{%- endif -%}
{% endmacro %}