-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcollect_freshness.sql
35 lines (29 loc) · 1.02 KB
/
collect_freshness.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
31
32
33
34
35
{% macro collect_freshness(source, loaded_at_field, filter) %}
{{ return(adapter.dispatch('collect_freshness')(source, loaded_at_field, filter))}}
{% endmacro %}
{% macro default__collect_freshness(source, loaded_at_field, filter) %}
{% call statement('collect_freshness', fetch_result=True, auto_begin=False) -%}
{%- set enabled_array = [] -%}
{% for node in graph.sources.values() %}
{% if node.name == source.name %}
{% if (node.meta['is_enabled'] | default(true)) %}
{%- do enabled_array.append(1) -%}
{% endif %}
{% endif %}
{% endfor %}
{% set is_enabled = (enabled_array != []) %}
select
{% if is_enabled %}
max({{ loaded_at_field }})
{% else %}
{{ current_timestamp() }} {% endif %} as max_loaded_at,
{{ current_timestamp() }} as snapshotted_at
{% if is_enabled %}
from {{ source }}
{% if filter %}
where {{ filter }}
{% endif %}
{% endif %}
{% endcall %}
{{ return(load_result('collect_freshness').table) }}
{% endmacro %}