Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migra queries STPL #142

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions queries/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ vars:
sppo_registros_staging: "rj-smtr-staging.br_rj_riodejaneiro_onibus_gps_staging.registros"
sppo_realocacao_staging: "rj-smtr-staging.br_rj_riodejaneiro_onibus_gps_staging.realocacao"
data_inicio_realocacao: "2022-11-15"
stpl_registros_staging: "rj-smtr-staging.br_rj_riodejaneiro_stpl_gps_staging.registros"
fifteen_minutes: ""

# Parametros de intersecção do ônibus com rota
Expand Down Expand Up @@ -337,6 +338,9 @@ models:
catalogo:
+materialized: view
+schema: catalogo
br_rj_riodejaneiro_stpl_gps:
+materialized: view
+schema: br_rj_riodejaneiro_stpl_gps
planejamento:
+materialized: incremental
+incremental_strategy: insert_overwrite
Expand Down
76 changes: 76 additions & 0 deletions queries/models/br_rj_riodejaneiro_stpl_gps/schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
version: 2

models:
- name: registros
description: "View para os dados de GPS das vans em staging."
columns:
- name: codigo
description: ""codigo""
- name: placa
description: "{{ doc('placa') }}"
- name: linha
description: "{{ doc('linha') }}"
- name: latitude
description: "{{ doc('latitude_gps') }}"
- name: longitude
description: "{{ doc('longitude_gps') }}"
- name: timestamp_gps
description: "{{ doc('timestamp_gps') }}"
- name: velocidade
description: "{{ doc('velocidade_instantanea') }}"
- name: id_migracao_trajeto
description: ""id_migracao_trajeto""
- name: sentido
description: "{{ doc('sentido') }}"
- name: trajeto
description: "{{ doc('trajeto') }}"
- name: timestamp_captura
description: "{{ doc('timestamp_captura') }}"
- name: data
description: "{{ doc('data_captura') }}"
- name: hora
description: "{{ doc('hora_captura') }}"
- name: registros_desaninhada
description: "View para os dados de GPS das vans em staging com a coluna content desaninhada."
columns:
- name: data
description: "{{ doc('data_captura') }}"
- name: hora
description: "{{ doc('hora_captura') }}"
- name: id_veiculo
description: "{{ doc('id_veiculo') }}"
- name: timestamp_captura
description: "{{ doc('timestamp_captura') }}"
- name: timestamp_gps
description: "{{ doc('timestamp_gps') }}"
- name: latitude
description: "{{ doc('latitude_gps') }}"
- name: longitude
description: "{{ doc('longitude_gps') }}"
- name: linha
description: "{{ doc('linha') }}"
- name: velocidade
description: "{{ doc('velocidade_instantanea') }}"
- name: id_migracao_trajeto
description: ""id_migracao_trajeto""
- name: sentido
description: "{{ doc('sentido') }}"
- name: trajeto
description: "{{ doc('trajeto') }}"
- name: hodometro
description: ""hodometro""
- name: registros_v2
description: "View para os dados de GPS das vans em staging."
columns:
- name: id_veiculo
description: "{{ doc('id_veiculo') }}"
- name: timestamp_gps
description: "{{ doc('timestamp_gps') }}"
- name: timestamp_captura
description: "{{ doc('timestamp_captura') }}"
- name: content
description: "{{ doc('content') }}"
- name: data
description: "{{ doc('data_captura') }}"
- name: hora
description: "{{ doc('hora_captura') }}"
22 changes: 22 additions & 0 deletions queries/models/br_rj_riodejaneiro_stpl_gps/stpl_registros.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

{{ config(
materialized='view',
alias='registros'
)
}}

SELECT
SAFE_CAST(codigo AS STRING) codigo,
SAFE_CAST(placa AS STRING) placa,
SAFE_CAST(linha AS STRING) linha,
SAFE_CAST(latitude AS FLOAT64) latitude,
SAFE_CAST(longitude AS FLOAT64) longitude,
SAFE_CAST(DATETIME(TIMESTAMP(dataHora), "America/Sao_Paulo") AS DATETIME) timestamp_gps,
SAFE_CAST(velocidade AS INT64) velocidade,
SAFE_CAST(id_migracao_trajeto AS STRING) id_migracao_trajeto,
SAFE_CAST(sentido AS STRING) sentido,
SAFE_CAST(trajeto AS STRING) trajeto,
SAFE_CAST(DATETIME(TIMESTAMP(timestamp_captura), "America/Sao_Paulo") AS DATETIME) timestamp_captura,
SAFE_CAST(data AS DATE) data,
SAFE_CAST(hora AS INT64) hora
from {{var('stpl_registros_staging')}} as t
15 changes: 15 additions & 0 deletions queries/models/br_rj_riodejaneiro_stpl_gps/stpl_registros_v2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

{{ config(
materialized='view',
alias='registros_v2'
)
}}

SELECT
SAFE_CAST(codigo AS STRING) id_veiculo,
SAFE_CAST(DATETIME(TIMESTAMP(dataHora), "America/Sao_Paulo") AS DATETIME) timestamp_gps,
SAFE_CAST(DATETIME(TIMESTAMP_TRUNC(TIMESTAMP(timestamp_captura), SECOND), "America/Sao_Paulo" ) AS DATETIME) timestamp_captura,
REPLACE(content,"None","") content,
SAFE_CAST(data as date) data,
SAFE_CAST(hora as int64) hora
FROM {{var('stpl_registros_staging')}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

{{ config(
materialized='view',
alias='registros_desaninhada'
)
}}

SELECT
data,
hora,
id_veiculo,
timestamp_captura,
timestamp_gps,
SAFE_CAST(json_value(content,"$.latitude") AS FLOAT64) latitude,
SAFE_CAST(json_value(content,"$.longitude") AS FLOAT64) longitude,
json_value(content,"$.linha") linha,
SAFE_CAST(json_value(content,'$.velocidade') as FLOAT64) as velocidade,
json_value(content,'$.id_migracao_trajeto') as id_migracao_trajeto,
json_value(content,'$.sentido') as sentido,
json_value(content,'$.trajeto') as trajeto,
json_value(content,'$.hodometro') as hodometro
FROM {{ ref('stpl_registros_v2') }}
12 changes: 12 additions & 0 deletions queries/models/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ Tipo de dado da coluna
Descrição da coluna
{% enddocs %}

{% docs data_captura %}
Data do 'timestamp_captura'
{% enddocs %}

{% docs hora_captura %}
Hora do 'timestamp_captura'
{% enddocs %}

{% docs placa %}
Placa do veículo
{% enddocs %}

{% docs timestamp_gps %}
Timestamp de emissão do sinal de GPS
{% enddocs %}
Expand Down
Loading