Skip to content

Commit

Permalink
teste var fifteen_minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
akaBotelho committed Aug 7, 2024
1 parent 17122d4 commit 974bf8f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
6 changes: 4 additions & 2 deletions pipelines/migration/br_rj_riodejaneiro_onibus_gps/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
rematerialization = Parameter("rematerialization", default=False)
date_range_start = Parameter("date_range_start", default=None)
date_range_end = Parameter("date_range_end", default=None)
fifteen_minutes = Parameter("fifteen_minutes", default="")

LABELS = get_current_flow_labels()
MODE = get_current_flow_mode()
Expand Down Expand Up @@ -205,7 +206,7 @@
table_id=table_id,
upstream=True,
exclude="+data_versao_efetiva",
_vars=[date_range, dataset_sha],
_vars=[date_range, dataset_sha, fifteen_minutes],
flags="--full-refresh",
)

Expand All @@ -215,7 +216,7 @@
dataset_id=dataset_id,
table_id=table_id,
exclude="+data_versao_efetiva",
_vars=[date_range, dataset_sha],
_vars=[date_range, dataset_sha, fifteen_minutes],
upstream=True,
)

Expand Down Expand Up @@ -549,6 +550,7 @@
"rebuild": rebuild,
"materialize_delay_hours": 0,
"truncate_minutes": False,
"fifteen_minutes": "_15_minutos",
},
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{% if var("fifteen_minutes") == "_15_minutos" %}
{{
config(
materialized='ephemeral',
alias=this.name ~ var("fifteen_minutes")
)
}}
{% else %}
{{
config(
materialized='incremental',
Expand All @@ -8,6 +16,8 @@
}
)
}}
{% endif %}

/*
Descrição:
Filtragem e tratamento básico de registros de gps.
Expand Down Expand Up @@ -44,7 +54,7 @@ realocacao as (
FROM
gps g
LEFT JOIN
{{ ref('sppo_aux_registros_realocacao') }} r
{{ ref('sppo_aux_registros_realocacao') ~ var('fifteen_minutes')}} r
ON
g.ordem = r.id_veiculo
and g.timestamp_gps = r.timestamp_gps
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{% if var("fifteen_minutes") == "_15_minutos" %}
{{
config(
materialized='ephemeral',
alias=this.name ~ var("fifteen_minutes")
)
}}
{% else %}
{{
config(
materialized='incremental',
Expand All @@ -8,6 +16,7 @@
}
)
}}
{% endif %}

-- 1. Filtra realocações válidas dentro do intervalo de GPS avaliado
with realocacao as (
Expand Down
19 changes: 12 additions & 7 deletions queries/models/br_rj_riodejaneiro_veiculos/gps_sppo_15_minutos.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{
config(
materialized='table',
alias=this.name ~ "_dev",
partition_by={
'field':"data",
'data_type':'date',
Expand Down Expand Up @@ -34,11 +35,13 @@ WITH
linha,
latitude,
longitude,
FROM {{ ref('sppo_aux_registros_filtrada') }}
FROM {{ ref('sppo_aux_registros_filtrada') ~ var('fifteen_minutes') }}
WHERE
data = DATE("{{var('date_range_end')}}")
AND timestamp_gps > DATETIME_SUB("{{var('date_range_end')}}", INTERVAL 75 MINUTE)
AND timestamp_gps <= "{{var('date_range_end')}}"
data between DATE("{{var('date_range_start')}}") and DATE("{{var('date_range_end')}}")
AND timestamp_gps > "{{var('date_range_start')}}" and timestamp_gps <="{{var('date_range_end')}}"
-- data = DATE("{{var('date_range_end')}}")
-- AND timestamp_gps > DATETIME_SUB("{{var('date_range_end')}}", INTERVAL 75 MINUTE)
-- AND timestamp_gps <= "{{var('date_range_end')}}"
),
velocidades AS (
-- 2. velocidades
Expand Down Expand Up @@ -133,6 +136,8 @@ ON
AND r.timestamp_gps = p.timestamp_gps
AND r.linha = p.linha
WHERE
DATE(r.timestamp_gps) = DATE("{{var('date_range_end')}}")
AND r.timestamp_gps > DATETIME_SUB("{{var('date_range_end')}}", INTERVAL 75 MINUTE)
AND r.timestamp_gps <= "{{var('date_range_end')}}"
date(r.timestamp_gps) between DATE("{{var('date_range_start')}}") and DATE("{{var('date_range_end')}}")
AND r.timestamp_gps > "{{var('date_range_start')}}" and r.timestamp_gps <="{{var('date_range_end')}}"
-- DATE(r.timestamp_gps) = DATE("{{var('date_range_end')}}")
-- AND r.timestamp_gps > DATETIME_SUB("{{var('date_range_end')}}", INTERVAL 75 MINUTE)
-- AND r.timestamp_gps <= "{{var('date_range_end')}}"

0 comments on commit 974bf8f

Please sign in to comment.