From 51fc75522f9be6327f4667cc7fc9bacaed2c667b Mon Sep 17 00:00:00 2001 From: vtr363 Date: Sat, 9 Nov 2024 04:52:53 -0300 Subject: [PATCH] =?UTF-8?q?Altera=C3=A7=C3=B5es=20para=20reprocessamento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- queries/dbt_project.yml | 18 +- queries/dev/run.py | 217 +++++++++++++++++- .../sumario_servico_dia.sql | 4 +- ...subsidio_faixa_servico_dia_tipo_viagem.sql | 4 +- .../subsidio_penalidade_servico_dia.sql | 4 +- .../gtfs/ordem_servico_trips_shapes_gtfs.sql | 6 +- .../ordem_servico_faixa_horaria.sql | 194 +++++++++------- .../aux_registros_status_trajeto.sql | 8 +- queries/models/subsidio/viagem_transacao.sql | 16 +- queries/profiles.yml | 6 +- 10 files changed, 362 insertions(+), 115 deletions(-) diff --git a/queries/dbt_project.yml b/queries/dbt_project.yml index bd594b102..531608ea4 100644 --- a/queries/dbt_project.yml +++ b/queries/dbt_project.yml @@ -91,7 +91,7 @@ vars: trips_staging: "rj-smtr-staging.br_rj_riodejaneiro_sigmob_staging.trips" ## GTFS - data_versao_gtfs: "2024-05-03" # fixada última data disponível + data_versao_gtfs: "2024-09-29" # fixada última data disponível ### Subsídio SPPO (Ônibus) ### buffer: 500 # distância em metros para buffer @@ -197,10 +197,10 @@ models: rj_smtr: projeto_subsidio_sppo: +materialized: view - +schema: projeto_subsidio_sppo + +schema: victor__projeto_subsidio_sppo deprecated: +materialized: view - +schema: projeto_subsidio_sppo + +schema: victor__projeto_subsidio_sppo br_rj_riodejaneiro_sigmob: +materialized: view +schema: br_rj_riodejaneiro_sigmob @@ -218,10 +218,10 @@ models: +schema: br_rj_riodejaneiro_veiculos dashboard_subsidio_sppo: +materialized: view - +schema: dashboard_subsidio_sppo + +schema: victor__dashboard_subsidio_sppo dashboard_subsidio_sppo_staging: +materialized: view - +schema: dashboard_subsidio_sppo_staging + +schema: victor__dashboard_subsidio_sppo_staging veiculo: +materialized: view +schema: veiculo @@ -300,18 +300,18 @@ models: financeiro: +materialized: incremental +incremental_strategy: insert_overwrite - +schema: financeiro + +schema: victor__financeiro staging: +materialized: incremental +incremental_strategy: insert_overwrite - +schema: financeiro_staging + +schema: victor__financeiro_staging dashboard_subsidio_sppo_v2: +materialized: view - +schema: dashboard_subsidio_sppo_v2 + +schema: victor__dashboard_subsidio_sppo_v2 subsidio: +materialized: incremental +incremental_strategy: insert_overwrite - +schema: subsidio + +schema: victor__subsidio catalogo: +materialized: view +schema: catalogo diff --git a/queries/dev/run.py b/queries/dev/run.py index f6fa99f3e..ded4908cc 100644 --- a/queries/dev/run.py +++ b/queries/dev/run.py @@ -1,11 +1,218 @@ # -*- coding: utf-8 -*- -# import os +import os +from typing import Dict, List, Union -from utils import run_dbt_model -# Veja os parâmetros disponíveis da função run_dbt_model em util.py +def run_dbt_tests( + dataset_id: str = None, + table_id: str = None, + model: str = None, + upstream: bool = None, + downstream: bool = None, + exclude: str = None, + flags: str = None, + _vars: Union[dict, List[Dict]] = None, +): + """ + Run DBT test + """ + run_command = "dbt test" + + common_flags = "--profiles-dir ./dev" + + if flags: + flags = f"{common_flags} {flags}" + else: + flags = common_flags + + if not model: + model = dataset_id + if table_id: + model += f".{table_id}" + + if model: + run_command += " --select " + if upstream: + run_command += "+" + run_command += model + if downstream: + run_command += "+" + + if exclude: + run_command += f" --exclude {exclude}" + + if _vars: + if isinstance(_vars, list): + vars_dict = {} + for elem in _vars: + vars_dict.update(elem) + vars_str = f'"{vars_dict}"' + run_command += f" --vars {vars_str}" + else: + vars_str = f'"{_vars}"' + run_command += f" --vars {vars_str}" + if flags: + run_command += f" {flags}" + + print(f"\n>>> RUNNING: {run_command}\n") + + project_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + os.chdir(project_dir) + os.system(run_command) + + +from utils import run_dbt_model +from datetime import datetime, timedelta + +# ordem_servico_trips_shapes_gtfs ## run_dbt_model( - dataset_id="example", - table_id="my_first_dbt_model", + dataset_id="gtfs", + # dataset_id="planejamento", + table_id="ordem_servico_trips_shapes_gtfs", + # upstream=True, + _vars={"data_versao_gtfs": "2024-11-06"}, + flags="--target hmg", ) + +## dados de autuação ## +# run_dbt_model( +# dataset_id="transito", +# table_id="receita_autuacao", +# # upstream=True, +# # _vars={"date_range_start": "2019-01-01", "date_range_end": "2023-08-26"}, +# flags="--full-refresh", +# ) + +# dados viagens ## +# run_dbt_model( +# dataset_id="projeto_subsidio_sppo", +# table_id="viagem_completa", +# upstream=True, +# exclude="+gps_sppo +ordem_servico_trips_shapes_gtfs", +# _vars={"run_date": "2024-11-07"}, +# flags="--target hmg", +# ) + +## loop para dados de viagens em D+1 ## + +# data_inicial = datetime.strptime("2024-11-07", "%Y-%m-%d") +# data_final = datetime.strptime("2024-11-08", "%Y-%m-%d") + +# data_atual = data_inicial +# while data_atual <= data_final: +# run_dbt_model( +# dataset_id="projeto_subsidio_sppo", +# table_id="viagem_completa", +# upstream=True, +# exclude="+gps_sppo +ordem_servico_trips_shapes_gtfs", +# _vars={"run_date": data_atual.strftime("%Y-%m-%d")}, +# # flags="--full-refresh", +# flags="--target hmg", +# ) +# print(data_atual.strftime("%Y-%m-%d")) +# data_atual += timedelta(days=1) + +# data_inicial = datetime.strptime("2024-10-02", "%Y-%m-%d") +# data_final = datetime.strptime("2024-10-16", "%Y-%m-%d") + +# data_atual = data_inicial +# while data_atual <= data_final: +# run_dbt_model( +# dataset_id="projeto_subsidio_sppo", +# table_id="viagem_completa", +# upstream=True, +# exclude="+gps_sppo +ordem_servico_trips_shapes_gtfs", +# _vars={"run_date": data_atual.strftime("%Y-%m-%d")}, +# # flags="--full-refresh", +# flags="--target hmg", +# ) +# print(data_atual.strftime("%Y-%m-%d")) +# data_atual += timedelta(days=1) + +## dados subsidio ## +# run_dbt_model( +# dataset_id=" subsidio dashboard_subsidio_sppo", +# _vars={"start_date": "2024-07-16", "end_date": "2024-07-31"}, +# # flags="--full-refresh", +# ) +# run_dbt_model( +# dataset_id="dashboard_subsidio_sppo", +# table_id="sumario_servico_dia_historico", +# _vars={"start_date": "2024-07-16", "end_date": "2024-07-17"}, +# # flags="--full-refresh", +# ) +# run_dbt_model( +# dataset_id="subsidio", +# # table_id="sumario_servico_dia_tipo_sem_glosa", +# _vars={"start_date": "2024-07-20", "end_date": "2024-07-20"}, +# flags="--full-refresh", +# ) + + +## Teste de modelos ## +# run_dbt_tests( # ok +# dataset_id="br_rj_riodejaneiro_onibus_gps", +# table_id="sppo_registros sppo_realocacao", +# _vars={"start_timestamp": "2024-09-01 00:00:00", "end_timestamp": "2024-09-15 03:00:00"}, +# flags="--target hmg", +# ) +# run_dbt_tests( # ok +# dataset_id="br_rj_riodejaneiro_veiculos", +# table_id="gps_sppo", +# _vars={"start_timestamp": "2024-09-01 00:00:00", "end_timestamp": "2024-09-15 03:00:00"}, +# flags="--target dev", +# ) +# run_dbt_tests( # ok +# dataset_id="veiculo", +# table_id="sppo_veiculo_dia", +# _vars={"start_timestamp": "2024-09-01 00:00:00", "end_timestamp": "2024-09-15 00:00:00"}, +# flags="--target dev", +# ) +# run_dbt_tests( # ok +# dataset_id="dashboard_subsidio_sppo", +# table_id="viagens_remuneradas", +# _vars={"start_timestamp": "2024-10-06 00:00:00", "end_timestamp": "2024-10-06 03:00:00"}, +# flags="--target hmg", +# ) +# run_dbt_tests( # ok +# dataset_id="dashboard_subsidio_sppo_v2", +# table_id="sumario_servico_dia_pagamento", +# _vars={"start_timestamp": "2024-10-06 00:00:00", "end_timestamp": "2024-10-06 03:00:00"}, +# flags="--target hmg", +# ) +# run_dbt_tests( # ok +# dataset_id="dashboard_subsidio_sppo", +# table_id="sumario_servico_dia_historico", +# _vars={"start_timestamp": "2024-09-01 00:00:00", "end_timestamp": "2024-09-15 00:00:00"}, +# flags="--target dev", +# ) +# run_dbt_tests( # ok +# dataset_id="dashboard_subsidio_sppo", +# table_id="sumario_servico_dia", +# _vars={"start_timestamp": "2024-07-19 00:00:00", "end_timestamp": "2024-07-20 00:00:00"}, +# ) +# run_dbt_tests( # ok +# dataset_id="dashboard_subsidio_sppo", +# table_id="sumario_servico_dia_tipo_sem_glosa", +# _vars={"start_timestamp": "2024-07-19 00:00:00", "end_timestamp": "2024-07-19 00:00:00"}, +# ) +# run_dbt_tests( # ok +# dataset_id="dashboard_subsidio_sppo", +# table_id="sumario_servico_dia_tipo", +# _vars={"start_timestamp": "2024-07-19 00:00:00", "end_timestamp": "2024-07-19 00:00:00"}, +# ) + + +## Selector apuração ## +# run_command = """dbt run --selector apuracao_subsidio_v9 --vars "{'start_date': '2024-10-01', 'end_date': '2024-10-05'}" -x --profiles-dir ./dev --target hmg""" + +# project_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +# os.chdir(project_dir) +# os.system(run_command) + +# run_command = """dbt run --selector apuracao_subsidio_v9 --vars "{'start_date': '2024-10-06', 'end_date': '2024-10-06'}" -x --profiles-dir ./dev --target hmg""" + +# project_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +# os.chdir(project_dir) +# os.system(run_command) diff --git a/queries/models/dashboard_subsidio_sppo/sumario_servico_dia.sql b/queries/models/dashboard_subsidio_sppo/sumario_servico_dia.sql index 9e7a65cea..89d0fd18b 100644 --- a/queries/models/dashboard_subsidio_sppo/sumario_servico_dia.sql +++ b/queries/models/dashboard_subsidio_sppo/sumario_servico_dia.sql @@ -95,8 +95,8 @@ SELECT FROM servico_km_apuracao AS s LEFT JOIN - {{ ref("valor_tipo_penalidade") }} AS p - -- `rj-smtr`.`dashboard_subsidio_sppo`.`valor_tipo_penalidade` AS p + -- {{ ref("valor_tipo_penalidade") }} AS p + `rj-smtr`.`dashboard_subsidio_sppo`.`valor_tipo_penalidade` AS p ON s.data BETWEEN p.data_inicio AND p.data_fim diff --git a/queries/models/financeiro/subsidio_faixa_servico_dia_tipo_viagem.sql b/queries/models/financeiro/subsidio_faixa_servico_dia_tipo_viagem.sql index cbf497dfa..cffb9e85a 100644 --- a/queries/models/financeiro/subsidio_faixa_servico_dia_tipo_viagem.sql +++ b/queries/models/financeiro/subsidio_faixa_servico_dia_tipo_viagem.sql @@ -54,8 +54,8 @@ WITH status, SAFE_CAST(JSON_VALUE(indicadores,"$.indicador_ar_condicionado") AS BOOL) AS indicador_ar_condicionado FROM - {{ ref("sppo_veiculo_dia") }} - -- rj-smtr.veiculo.sppo_veiculo_dia + -- {{ ref("sppo_veiculo_dia") }} + rj-smtr.veiculo.sppo_veiculo_dia WHERE data BETWEEN DATE("{{ var("start_date") }}") AND DATE("{{ var("end_date") }}") diff --git a/queries/models/financeiro/subsidio_penalidade_servico_dia.sql b/queries/models/financeiro/subsidio_penalidade_servico_dia.sql index d02a556c7..81aa0a936 100644 --- a/queries/models/financeiro/subsidio_penalidade_servico_dia.sql +++ b/queries/models/financeiro/subsidio_penalidade_servico_dia.sql @@ -34,8 +34,8 @@ WITH perc_km_superior, IFNULL(-valor, 0) AS valor_penalidade FROM - {{ ref("valor_tipo_penalidade") }} - -- rj-smtr.dashboard_subsidio_sppo.valor_tipo_penalidade + -- {{ ref("valor_tipo_penalidade") }} + rj-smtr.dashboard_subsidio_sppo.valor_tipo_penalidade ) SELECT s.data, diff --git a/queries/models/gtfs/ordem_servico_trips_shapes_gtfs.sql b/queries/models/gtfs/ordem_servico_trips_shapes_gtfs.sql index 971d4824f..4d41391d2 100644 --- a/queries/models/gtfs/ordem_servico_trips_shapes_gtfs.sql +++ b/queries/models/gtfs/ordem_servico_trips_shapes_gtfs.sql @@ -49,7 +49,7 @@ with and ( ( o.tipo_dia = t.tipo_dia - and o.tipo_os not in ("CNU", "Eleição") + and o.tipo_os not in ("CNU", "Eleição", "Enem") ) or ( o.tipo_dia = "Ponto Facultativo" @@ -222,8 +222,8 @@ select from ordem_servico_trips as o left join shapes as s using (feed_version, feed_start_date, shape_id) left join - {{ ref("ordem_servico_faixa_horaria") }} as fh - -- `rj-smtr.planejamento.ordem_servico_faixa_horaria` as fh + {{ ref("ordem_servico_faixa_horaria") }} AS fh + -- `rj-smtr.planejamento.ordem_servico_faixa_horaria` as fh using ( feed_version, feed_start_date, tipo_os, tipo_dia, servico ) diff --git a/queries/models/planejamento/ordem_servico_faixa_horaria.sql b/queries/models/planejamento/ordem_servico_faixa_horaria.sql index d52c02c3c..994b675c7 100644 --- a/queries/models/planejamento/ordem_servico_faixa_horaria.sql +++ b/queries/models/planejamento/ordem_servico_faixa_horaria.sql @@ -15,84 +15,100 @@ WITH SAFE_CAST(tipo_os AS STRING) AS tipo_os, SAFE_CAST(servico AS STRING) AS servico, SAFE_CAST(JSON_VALUE(content, "$.consorcio") AS STRING) AS consorcio, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_00h_e_03h_dias_uteis') AS STRING) AS partidas_entre_00h_e_03h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_03h_e_06h_dias_uteis') AS STRING) AS partidas_entre_03h_e_06h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_06h_e_09h_dias_uteis') AS STRING) AS partidas_entre_06h_e_09h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_09h_e_12h_dias_uteis') AS STRING) AS partidas_entre_09h_e_12h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_12h_e_15h_dias_uteis') AS STRING) AS partidas_entre_12h_e_15h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_15h_e_18h_dias_uteis') AS STRING) AS partidas_entre_15h_e_18h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_18h_e_21h_dias_uteis') AS STRING) AS partidas_entre_18h_e_21h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_21h_e_24h_dias_uteis') AS STRING) AS partidas_entre_21h_e_24h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_24h_e_03h_diaseguinte_dias_uteis') AS STRING) AS partidas_entre_24h_e_03h_diaseguinte_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_00h_e_03h_sabado') AS STRING) AS partidas_entre_00h_e_03h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_03h_e_06h_sabado') AS STRING) AS partidas_entre_03h_e_06h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_06h_e_09h_sabado') AS STRING) AS partidas_entre_06h_e_09h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_09h_e_12h_sabado') AS STRING) AS partidas_entre_09h_e_12h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_12h_e_15h_sabado') AS STRING) AS partidas_entre_12h_e_15h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_15h_e_18h_sabado') AS STRING) AS partidas_entre_15h_e_18h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_18h_e_21h_sabado') AS STRING) AS partidas_entre_18h_e_21h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_21h_e_24h_sabado') AS STRING) AS partidas_entre_21h_e_24h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_24h_e_03h_diaseguinte_sabado') AS STRING) AS partidas_entre_24h_e_03h_diaseguinte_sabado, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_00h_e_03h_domingo') AS STRING) AS partidas_entre_00h_e_03h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_03h_e_06h_domingo') AS STRING) AS partidas_entre_03h_e_06h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_06h_e_09h_domingo') AS STRING) AS partidas_entre_06h_e_09h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_09h_e_12h_domingo') AS STRING) AS partidas_entre_09h_e_12h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_12h_e_15h_domingo') AS STRING) AS partidas_entre_12h_e_15h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_15h_e_18h_domingo') AS STRING) AS partidas_entre_15h_e_18h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_18h_e_21h_domingo') AS STRING) AS partidas_entre_18h_e_21h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_21h_e_24h_domingo') AS STRING) AS partidas_entre_21h_e_24h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_24h_e_03h_diaseguinte_domingo') AS STRING) AS partidas_entre_24h_e_03h_diaseguinte_domingo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_00h_e_03h_ponto_facultativo') AS STRING) AS partidas_entre_00h_e_03h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_03h_e_06h_ponto_facultativo') AS STRING) AS partidas_entre_03h_e_06h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_06h_e_09h_ponto_facultativo') AS STRING) AS partidas_entre_06h_e_09h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_09h_e_12h_ponto_facultativo') AS STRING) AS partidas_entre_09h_e_12h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_12h_e_15h_ponto_facultativo') AS STRING) AS partidas_entre_12h_e_15h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_15h_e_18h_ponto_facultativo') AS STRING) AS partidas_entre_15h_e_18h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_18h_e_21h_ponto_facultativo') AS STRING) AS partidas_entre_18h_e_21h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_21h_e_24h_ponto_facultativo') AS STRING) AS partidas_entre_21h_e_24h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.partidas_entre_24h_e_03h_diaseguinte_ponto_facultativo') AS STRING) AS partidas_entre_24h_e_03h_diaseguinte_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_00h_e_03h_dias_uteis') AS STRING) AS quilometragem_entre_00h_e_03h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_03h_e_06h_dias_uteis') AS STRING) AS quilometragem_entre_03h_e_06h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_06h_e_09h_dias_uteis') AS STRING) AS quilometragem_entre_06h_e_09h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_09h_e_12h_dias_uteis') AS STRING) AS quilometragem_entre_09h_e_12h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_12h_e_15h_dias_uteis') AS STRING) AS quilometragem_entre_12h_e_15h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_15h_e_18h_dias_uteis') AS STRING) AS quilometragem_entre_15h_e_18h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_18h_e_21h_dias_uteis') AS STRING) AS quilometragem_entre_18h_e_21h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_21h_e_24h_dias_uteis') AS STRING) AS quilometragem_entre_21h_e_24h_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_24h_e_03h_diaseguinte_dias_uteis') AS STRING) AS quilometragem_entre_24h_e_03h_diaseguinte_dias_uteis, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_00h_e_03h_sabado') AS STRING) AS quilometragem_entre_00h_e_03h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_03h_e_06h_sabado') AS STRING) AS quilometragem_entre_03h_e_06h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_06h_e_09h_sabado') AS STRING) AS quilometragem_entre_06h_e_09h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_09h_e_12h_sabado') AS STRING) AS quilometragem_entre_09h_e_12h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_12h_e_15h_sabado') AS STRING) AS quilometragem_entre_12h_e_15h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_15h_e_18h_sabado') AS STRING) AS quilometragem_entre_15h_e_18h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_18h_e_21h_sabado') AS STRING) AS quilometragem_entre_18h_e_21h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_21h_e_24h_sabado') AS STRING) AS quilometragem_entre_21h_e_24h_sabado, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_24h_e_03h_diaseguinte_sabado') AS STRING) AS quilometragem_entre_24h_e_03h_diaseguinte_sabado, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_00h_e_03h_domingo') AS STRING) AS quilometragem_entre_00h_e_03h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_03h_e_06h_domingo') AS STRING) AS quilometragem_entre_03h_e_06h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_06h_e_09h_domingo') AS STRING) AS quilometragem_entre_06h_e_09h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_09h_e_12h_domingo') AS STRING) AS quilometragem_entre_09h_e_12h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_12h_e_15h_domingo') AS STRING) AS quilometragem_entre_12h_e_15h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_15h_e_18h_domingo') AS STRING) AS quilometragem_entre_15h_e_18h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_18h_e_21h_domingo') AS STRING) AS quilometragem_entre_18h_e_21h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_21h_e_24h_domingo') AS STRING) AS quilometragem_entre_21h_e_24h_domingo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_24h_e_03h_diaseguinte_domingo') AS STRING) AS quilometragem_entre_24h_e_03h_diaseguinte_domingo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_00h_e_03h_ponto_facultativo') AS STRING) AS quilometragem_entre_00h_e_03h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_03h_e_06h_ponto_facultativo') AS STRING) AS quilometragem_entre_03h_e_06h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_06h_e_09h_ponto_facultativo') AS STRING) AS quilometragem_entre_06h_e_09h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_09h_e_12h_ponto_facultativo') AS STRING) AS quilometragem_entre_09h_e_12h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_12h_e_15h_ponto_facultativo') AS STRING) AS quilometragem_entre_12h_e_15h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_15h_e_18h_ponto_facultativo') AS STRING) AS quilometragem_entre_15h_e_18h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_18h_e_21h_ponto_facultativo') AS STRING) AS quilometragem_entre_18h_e_21h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_21h_e_24h_ponto_facultativo') AS STRING) AS quilometragem_entre_21h_e_24h_ponto_facultativo, - SAFE_CAST(JSON_VALUE(content, '$.quilometragem_entre_24h_e_03h_diaseguinte_ponto_facultativo') AS STRING) AS quilometragem_entre_24h_e_03h_diaseguinte_ponto_facultativo + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_03h_e_12h_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_03h_e_12h_dias_uteis, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_12h_e_21h_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_12h_e_21h_dias_uteis, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_00h_e_03h_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_00h_e_03h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_03h_e_06h_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_03h_e_06h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_06h_e_09h_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_06h_e_09h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_09h_e_12h_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_09h_e_12h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_12h_e_15h_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_12h_e_15h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_15h_e_18h_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_15h_e_18h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_18h_e_21h_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_18h_e_21h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_21h_e_24h_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_21h_e_24h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_24h_e_03h_diaseguinte_dias_uteis'), ',', '.') AS STRING) AS partidas_entre_24h_e_03h_diaseguinte_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_03h_e_12h_sabado'), ',', '.') AS STRING) AS partidas_entre_03h_e_12h_sabado, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_12h_e_21h_sabado'), ',', '.') AS STRING) AS partidas_entre_12h_e_21h_sabado, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_00h_e_03h_sabado'), ',', '.') AS STRING) AS partidas_entre_00h_e_03h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_03h_e_06h_sabado'), ',', '.') AS STRING) AS partidas_entre_03h_e_06h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_06h_e_09h_sabado'), ',', '.') AS STRING) AS partidas_entre_06h_e_09h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_09h_e_12h_sabado'), ',', '.') AS STRING) AS partidas_entre_09h_e_12h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_12h_e_15h_sabado'), ',', '.') AS STRING) AS partidas_entre_12h_e_15h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_15h_e_18h_sabado'), ',', '.') AS STRING) AS partidas_entre_15h_e_18h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_18h_e_21h_sabado'), ',', '.') AS STRING) AS partidas_entre_18h_e_21h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_21h_e_24h_sabado'), ',', '.') AS STRING) AS partidas_entre_21h_e_24h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_24h_e_03h_diaseguinte_sabado'), ',', '.') AS STRING) AS partidas_entre_24h_e_03h_diaseguinte_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_03h_e_12h_domingo'), ',', '.') AS STRING) AS partidas_entre_03h_e_12h_domingo, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_12h_e_21h_domingo'), ',', '.') AS STRING) AS partidas_entre_12h_e_21h_domingo, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_00h_e_03h_domingo'), ',', '.') AS STRING) AS partidas_entre_00h_e_03h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_03h_e_06h_domingo'), ',', '.') AS STRING) AS partidas_entre_03h_e_06h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_06h_e_09h_domingo'), ',', '.') AS STRING) AS partidas_entre_06h_e_09h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_09h_e_12h_domingo'), ',', '.') AS STRING) AS partidas_entre_09h_e_12h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_12h_e_15h_domingo'), ',', '.') AS STRING) AS partidas_entre_12h_e_15h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_15h_e_18h_domingo'), ',', '.') AS STRING) AS partidas_entre_15h_e_18h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_18h_e_21h_domingo'), ',', '.') AS STRING) AS partidas_entre_18h_e_21h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_21h_e_24h_domingo'), ',', '.') AS STRING) AS partidas_entre_21h_e_24h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_24h_e_03h_diaseguinte_domingo'), ',', '.') AS STRING) AS partidas_entre_24h_e_03h_diaseguinte_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_03h_e_12h_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_03h_e_12h_ponto_facultativo, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_12h_e_21h_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_12h_e_21h_ponto_facultativo, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_00h_e_03h_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_00h_e_03h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_03h_e_06h_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_03h_e_06h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_06h_e_09h_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_06h_e_09h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_09h_e_12h_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_09h_e_12h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_12h_e_15h_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_12h_e_15h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_15h_e_18h_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_15h_e_18h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_18h_e_21h_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_18h_e_21h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_21h_e_24h_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_21h_e_24h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.partidas_entre_24h_e_03h_diaseguinte_ponto_facultativo'), ',', '.') AS STRING) AS partidas_entre_24h_e_03h_diaseguinte_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_03h_e_12h_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_03h_e_12h_dias_uteis, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_12h_e_21h_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_12h_e_21h_dias_uteis, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_00h_e_03h_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_00h_e_03h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_03h_e_06h_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_03h_e_06h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_06h_e_09h_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_06h_e_09h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_09h_e_12h_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_09h_e_12h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_12h_e_15h_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_12h_e_15h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_15h_e_18h_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_15h_e_18h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_18h_e_21h_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_18h_e_21h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_21h_e_24h_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_21h_e_24h_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_24h_e_03h_diaseguinte_dias_uteis'), ',', '.') AS STRING) AS quilometragem_entre_24h_e_03h_diaseguinte_dias_uteis, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_03h_e_12h_sabado'), ',', '.') AS STRING) AS quilometragem_entre_03h_e_12h_sabado, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_12h_e_21h_sabado'), ',', '.') AS STRING) AS quilometragem_entre_12h_e_21h_sabado, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_00h_e_03h_sabado'), ',', '.') AS STRING) AS quilometragem_entre_00h_e_03h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_03h_e_06h_sabado'), ',', '.') AS STRING) AS quilometragem_entre_03h_e_06h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_06h_e_09h_sabado'), ',', '.') AS STRING) AS quilometragem_entre_06h_e_09h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_09h_e_12h_sabado'), ',', '.') AS STRING) AS quilometragem_entre_09h_e_12h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_12h_e_15h_sabado'), ',', '.') AS STRING) AS quilometragem_entre_12h_e_15h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_15h_e_18h_sabado'), ',', '.') AS STRING) AS quilometragem_entre_15h_e_18h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_18h_e_21h_sabado'), ',', '.') AS STRING) AS quilometragem_entre_18h_e_21h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_21h_e_24h_sabado'), ',', '.') AS STRING) AS quilometragem_entre_21h_e_24h_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_24h_e_03h_diaseguinte_sabado'), ',', '.') AS STRING) AS quilometragem_entre_24h_e_03h_diaseguinte_sabado, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_03h_e_12h_domingo'), ',', '.') AS STRING) AS quilometragem_entre_03h_e_12h_domingo, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_12h_e_21h_domingo'), ',', '.') AS STRING) AS quilometragem_entre_12h_e_21h_domingo, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_00h_e_03h_domingo'), ',', '.') AS STRING) AS quilometragem_entre_00h_e_03h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_03h_e_06h_domingo'), ',', '.') AS STRING) AS quilometragem_entre_03h_e_06h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_06h_e_09h_domingo'), ',', '.') AS STRING) AS quilometragem_entre_06h_e_09h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_09h_e_12h_domingo'), ',', '.') AS STRING) AS quilometragem_entre_09h_e_12h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_12h_e_15h_domingo'), ',', '.') AS STRING) AS quilometragem_entre_12h_e_15h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_15h_e_18h_domingo'), ',', '.') AS STRING) AS quilometragem_entre_15h_e_18h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_18h_e_21h_domingo'), ',', '.') AS STRING) AS quilometragem_entre_18h_e_21h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_21h_e_24h_domingo'), ',', '.') AS STRING) AS quilometragem_entre_21h_e_24h_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_24h_e_03h_diaseguinte_domingo'), ',', '.') AS STRING) AS quilometragem_entre_24h_e_03h_diaseguinte_domingo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_03h_e_12h_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_03h_e_12h_ponto_facultativo, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_12h_e_21h_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_12h_e_21h_ponto_facultativo, -- faixa antiga + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_00h_e_03h_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_00h_e_03h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_03h_e_06h_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_03h_e_06h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_06h_e_09h_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_06h_e_09h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_09h_e_12h_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_09h_e_12h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_12h_e_15h_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_12h_e_15h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_15h_e_18h_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_15h_e_18h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_18h_e_21h_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_18h_e_21h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_21h_e_24h_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_21h_e_24h_ponto_facultativo, + SAFE_CAST(REPLACE(JSON_VALUE(content, '$.quilometragem_entre_24h_e_03h_diaseguinte_ponto_facultativo'), ',', '.') AS STRING) AS quilometragem_entre_24h_e_03h_diaseguinte_ponto_facultativo FROM {{ source("br_rj_riodejaneiro_gtfs_staging", "ordem_servico_faixa_horaria") }} - {% if is_incremental() -%} + {# {% if is_incremental() -%} #} WHERE data_versao = '{{ var("data_versao_gtfs") }}' - {%- endif %} + {# {%- endif %} #} ), dados_agrupados AS ( SELECT @@ -107,6 +123,10 @@ WITH WHEN column_name LIKE '%ponto_facultativo%' THEN 'Ponto Facultativo' END AS tipo_dia, CASE + WHEN column_name LIKE '%03h_e_12h%' THEN -- faixa antiga + '03:00:00' + WHEN column_name LIKE '%12h_e_21h%' THEN -- faixa antiga + '12:00:00' WHEN column_name LIKE '%00h_e_03h%' THEN '00:00:00' WHEN column_name LIKE '%03h_e_06h%' THEN @@ -127,6 +147,10 @@ WITH '24:00:00' END AS faixa_horaria_inicio, CASE + WHEN column_name LIKE '%03h_e_12h%' THEN -- faixa antiga + '11:59:59' + WHEN column_name LIKE '%12h_e_21h%' THEN -- faixa antiga + '20:59:59' WHEN column_name LIKE '%00h_e_03h%' THEN '02:59:59' WHEN column_name LIKE '%03h_e_06h%' THEN @@ -157,6 +181,22 @@ WITH FROM dados UNPIVOT ( value FOR column_name IN ( + partidas_entre_03h_e_12h_dias_uteis, -- faixa antiga + partidas_entre_12h_e_21h_dias_uteis, -- faixa antiga + partidas_entre_03h_e_12h_sabado, -- faixa antiga + partidas_entre_12h_e_21h_sabado, -- faixa antiga + partidas_entre_03h_e_12h_domingo, -- faixa antiga + partidas_entre_12h_e_21h_domingo, -- faixa antiga + partidas_entre_03h_e_12h_ponto_facultativo, -- faixa antiga + partidas_entre_12h_e_21h_ponto_facultativo, -- faixa antiga + quilometragem_entre_03h_e_12h_dias_uteis, -- faixa antiga + quilometragem_entre_12h_e_21h_dias_uteis, -- faixa antiga + quilometragem_entre_03h_e_12h_sabado, -- faixa antiga + quilometragem_entre_12h_e_21h_sabado, -- faixa antiga + quilometragem_entre_03h_e_12h_domingo, -- faixa antiga + quilometragem_entre_12h_e_21h_domingo, -- faixa antiga + quilometragem_entre_03h_e_12h_ponto_facultativo, -- faixa antiga + quilometragem_entre_12h_e_21h_ponto_facultativo, -- faixa antiga partidas_entre_00h_e_03h_dias_uteis, quilometragem_entre_00h_e_03h_dias_uteis, partidas_entre_03h_e_06h_dias_uteis, @@ -245,11 +285,11 @@ LEFT JOIN {{ ref('feed_info_gtfs') }} AS fi ON d.data_versao = fi.feed_start_date -{% if is_incremental() -%} +{# {% if is_incremental() -%} #} WHERE d.data_versao = '{{ var("data_versao_gtfs") }}' AND fi.feed_start_date = '{{ var("data_versao_gtfs") }}' -{% else %} +{# {% else %} WHERE d.data_versao >= '{{ var("DATA_SUBSIDIO_V9_INICIO") }}' -{%- endif %} +{%- endif %} #} diff --git a/queries/models/projeto_subsidio_sppo/aux_registros_status_trajeto.sql b/queries/models/projeto_subsidio_sppo/aux_registros_status_trajeto.sql index 3e297a36f..942f35872 100644 --- a/queries/models/projeto_subsidio_sppo/aux_registros_status_trajeto.sql +++ b/queries/models/projeto_subsidio_sppo/aux_registros_status_trajeto.sql @@ -33,8 +33,8 @@ with gps as ( date_sub(date("{{ var("run_date") }}"), interval 1 day) as data_operacao {% endif %} from - -- `rj-smtr.br_rj_riodejaneiro_veiculos.gps_sppo` g - {{ ref('gps_sppo') }} g + `rj-smtr.br_rj_riodejaneiro_veiculos.gps_sppo` g + -- {{ ref('gps_sppo') }} g where ( data between date_sub(date("{{ var("run_date") }}"), interval 1 day) and date("{{ var("run_date") }}") ) @@ -123,8 +123,8 @@ with gps as ( ST_GEOGPOINT(longitude, latitude) posicao_veiculo_geo, date_sub(date("{{ var("run_date") }}"), interval 1 day) as data_operacao from - -- `rj-smtr.br_rj_riodejaneiro_veiculos.gps_sppo` g - {{ ref('gps_sppo') }} g + `rj-smtr.br_rj_riodejaneiro_veiculos.gps_sppo` g + -- {{ ref('gps_sppo') }} g where ( data between date_sub(date("{{ var("run_date") }}"), interval 1 day) and date("{{ var("run_date") }}") ) diff --git a/queries/models/subsidio/viagem_transacao.sql b/queries/models/subsidio/viagem_transacao.sql index d90197c4a..1e2d93222 100644 --- a/queries/models/subsidio/viagem_transacao.sql +++ b/queries/models/subsidio/viagem_transacao.sql @@ -13,8 +13,8 @@ WITH id_veiculo, datetime_transacao FROM - {{ ref("transacao") }} - -- rj-smtr.br_rj_riodejaneiro_bilhetagem.transacao + -- {{ ref("transacao") }} + rj-smtr.br_rj_riodejaneiro_bilhetagem.transacao WHERE data BETWEEN DATE("{{ var("start_date") }}") AND DATE_ADD(DATE("{{ var("end_date") }}"), INTERVAL 1 DAY) @@ -25,8 +25,8 @@ WITH id_veiculo, datetime_transacao FROM - {{ ref("transacao_riocard") }} - -- rj-smtr.br_rj_riodejaneiro_bilhetagem.transacao_riocard + -- {{ ref("transacao_riocard") }} + rj-smtr.br_rj_riodejaneiro_bilhetagem.transacao_riocard WHERE data BETWEEN DATE("{{ var("start_date") }}") AND DATE_ADD(DATE("{{ var("end_date") }}"), INTERVAL 1 DAY) @@ -42,8 +42,8 @@ WITH latitude, longitude FROM - {{ ref("gps_validador") }} - -- rj-smtr.br_rj_riodejaneiro_bilhetagem.gps_validador + -- {{ ref("gps_validador") }} + rj-smtr.br_rj_riodejaneiro_bilhetagem.gps_validador WHERE data BETWEEN DATE("{{ var("start_date") }}") AND DATE_ADD(DATE("{{ var("end_date") }}"), INTERVAL 1 DAY) @@ -72,8 +72,8 @@ WITH id_veiculo, status FROM - {{ ref("sppo_veiculo_dia") }} - -- rj-smtr.veiculo.sppo_veiculo_dia + -- {{ ref("sppo_veiculo_dia") }} + rj-smtr.veiculo.sppo_veiculo_dia WHERE data BETWEEN DATE("{{ var("start_date") }}") AND DATE("{{ var("end_date") }}") ), diff --git a/queries/profiles.yml b/queries/profiles.yml index e67088d2d..730a24073 100644 --- a/queries/profiles.yml +++ b/queries/profiles.yml @@ -30,7 +30,7 @@ queries: dataset: dbt job_execution_timeout_seconds: 600 job_retries: 1 - keyfile: /tmp/credentials.json + keyfile: /mnt/c/Users/Softex/.basedosdados/credentials/staging.json location: us method: service-account priority: interactive @@ -56,7 +56,7 @@ queries: dataset: dbt job_execution_timeout_seconds: 600 job_retries: 1 - keyfile: /tmp/credentials.json + keyfile: /mnt/c/Users/Softex/.basedosdados/credentials/staging.json location: us method: service-account priority: interactive @@ -78,4 +78,4 @@ queries: spark.executor.instances: "2" spark.driver.memory: 4g spark.driver.memoryOverhead: 1g - target: prod \ No newline at end of file + target: hmg \ No newline at end of file