Skip to content

Commit

Permalink
cria macro para filtrar por hora
Browse files Browse the repository at this point in the history
  • Loading branch information
pixuimpou committed Jan 8, 2025
1 parent 398a793 commit 3764d41
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions queries/macros/generate_date_hour_partition_filter.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% macro generate_date_hour_partition_filter(start_timestamp, end_timestamp) %}
{% set start = modules.datetime.datetime.fromisoformat(start_timestamp) %}
{% set end = modules.datetime.datetime.fromisoformat(end_timestamp) %}
{% set days = (end.date() - start.date()).days %}

{% if days == 0 %}
data = date("{{ start_timestamp }}")
and hora between {{ start.hour }} and {{ end.hour }}

{% elif days == 1 %}
(data = date("{{ start_timestamp }}")
and hora >= {{ start.hour }})
or
(data = date("{{ end_timestamp }}")
and hora <= {{ end.hour }})
{% else %}
(data = date("{{ start_timestamp }}")
and hora >= {{ start.hour }})
or
(data > date("{{ start_timestamp }}")
and data < date("{{ end_timestamp }}"))
or
(data = date("{{ end_timestamp }}")
and hora <= {{ end.hour }})
{% endif %}

{% endmacro %}

0 comments on commit 3764d41

Please sign in to comment.