forked from dbt-labs/dbt-project-evaluator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_column_values.sql
More file actions
42 lines (33 loc) · 1.75 KB
/
get_column_values.sql
File metadata and controls
42 lines (33 loc) · 1.75 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
30
31
32
33
34
35
36
37
38
39
40
41
42
{%- macro get_column_values(node_type) -%}
{{ return(adapter.dispatch('get_column_values', 'dbt_project_evaluator')(node_type)) }}
{%- endmacro -%}
{%- macro default__get_column_values(node_type) -%}
{%- if execute -%}
{%- if node_type == 'nodes' %}
{% set nodes_list = graph.nodes.values() %}
{%- elif node_type == 'sources' -%}
{% set nodes_list = graph.sources.values() %}
{%- else -%}
{{ exceptions.raise_compiler_error("node_type needs to be either nodes or sources, got " ~ node_type) }}
{% endif -%}
{%- set values = [] -%}
{%- for node in nodes_list -%}
{%- for column in node.columns.values() -%}
{%- set values_line =
[
wrap_string_with_quotes(node.unique_id),
wrap_string_with_quotes(dbt.escape_single_quotes(column.name)),
wrap_string_with_quotes(dbt.escape_single_quotes(column.description | replace("\\","\\\\"))),
wrap_string_with_quotes(dbt.escape_single_quotes(column.data_type)),
wrap_string_with_quotes(dbt.escape_single_quotes(tojson(column.constraints))),
"cast(" ~ dbt_project_evaluator.bool_literal(column.constraints | selectattr('type', 'equalto', 'not_null') | list | length > 0) | trim ~ " as " ~ dbt.type_boolean() ~ ")",
column.constraints | length,
wrap_string_with_quotes(dbt.escape_single_quotes(column.quote))
]
%}
{%- do values.append(values_line) -%}
{%- endfor -%}
{%- endfor -%}
{{ return(values) }}
{%- endif -%}
{%- endmacro -%}