-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_positions.sql
36 lines (25 loc) · 1.02 KB
/
get_positions.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
36
-- INCLUDE DESCRIPTION HERE TO DESCRIBE MACRO FILE --
{%- macro get_position(position, by_column_name, from_column_name) -%}
{{ position }}_VALUE({{ from_column_name }} IGNORE NULLS) OVER (
PARTITION BY {{ by_column_name }}
ORDER BY
event_timestamp ROWS BETWEEN UNBOUNDED PRECEDING
AND UNBOUNDED FOLLOWING
)
{%- endmacro -%}
{%- macro get_first(by_column_name, from_column_name) -%}
FIRST_VALUE({{ from_column_name }} IGNORE NULLS) OVER (
PARTITION BY {{ by_column_name }}
ORDER BY
event_timestamp ROWS BETWEEN UNBOUNDED PRECEDING
AND UNBOUNDED FOLLOWING
)
{%- endmacro -%}
{%- macro get_last(by_column_name, from_column_name) -%}
LAST_VALUE({{ from_column_name }} IGNORE NULLS) OVER (
PARTITION BY {{ by_column_name }}
ORDER BY
event_timestamp ROWS BETWEEN UNBOUNDED PRECEDING
AND UNBOUNDED FOLLOWING
)
{%- endmacro -%}