-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
queries/models/br_rj_riodejaneiro_bilhetagem_staging/staging_endereco.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{{ | ||
config( | ||
alias='endereco', | ||
) | ||
}} | ||
|
||
WITH | ||
endereco AS ( | ||
SELECT | ||
data, | ||
SAFE_CAST(NR_SEQ_ENDERECO AS STRING) AS nr_seq_endereco, | ||
timestamp_captura, | ||
SAFE_CAST(JSON_VALUE(content, '$.CD_CLIENTE') AS STRING) AS cd_cliente, | ||
SAFE_CAST(JSON_VALUE(content, '$.CD_TIPO_ENDERECO') AS STRING) AS cd_tipo_endereco, | ||
SAFE_CAST(JSON_VALUE(content, '$.CD_TIPO_LOGRADOURO') AS STRING) AS cd_tipo_logradouro, | ||
DATETIME(PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%S%Ez', SAFE_CAST(JSON_VALUE(content, '$.DT_INCLUSAO') AS STRING)), "America/Sao_Paulo") AS dt_inclusao, | ||
SAFE_CAST(JSON_VALUE(content, '$.NM_BAIRRO') AS STRING) AS nm_bairro, | ||
SAFE_CAST(JSON_VALUE(content, '$.NM_CIDADE') AS STRING) AS nm_cidade, | ||
SAFE_CAST(JSON_VALUE(content, '$.NR_CEP') AS STRING) AS nr_cep, | ||
SAFE_CAST(JSON_VALUE(content, '$.NR_LOGRADOURO') AS STRING) AS nr_logradouro, | ||
SAFE_CAST(JSON_VALUE(content, '$.SG_UF') AS STRING) AS sg_uf, | ||
SAFE_CAST(JSON_VALUE(content, '$.TX_COMPLEMENTO_LOGRADOURO') AS STRING) AS tx_complemento_logradouro, | ||
SAFE_CAST(JSON_VALUE(content, '$.TX_LOGRADOURO') AS STRING) AS tx_logradouro | ||
FROM | ||
{{ source("br_rj_riodejaneiro_bilhetagem_staging", "endereco") }} | ||
), | ||
endereco_rn AS ( | ||
SELECT | ||
*, | ||
ROW_NUMBER() OVER (PARTITION BY nr_seq_endereco ORDER BY timestamp_captura DESC) AS rn | ||
FROM | ||
endereco | ||
) | ||
SELECT | ||
* EXCEPT(rn) | ||
FROM | ||
endereco_rn | ||
WHERE | ||
rn = 1 |
32 changes: 32 additions & 0 deletions
32
...ls/br_rj_riodejaneiro_bilhetagem_staging/staging_linha_consorcio_operadora_transporte.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{ | ||
config( | ||
alias='linha_consorcio_operadora_transporte', | ||
) | ||
}} | ||
|
||
WITH linha_consorcio_operadora_transporte AS ( | ||
SELECT | ||
data, | ||
SAFE_CAST(CD_CONSORCIO AS STRING) AS cd_consorcio, | ||
SAFE_CAST(CD_OPERADORA_TRANSPORTE AS STRING) AS cd_operadora_transporte, | ||
SAFE_CAST(CD_LINHA AS STRING) AS cd_linha, | ||
timestamp_captura, | ||
DATETIME(PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%S%Ez', SAFE_CAST(JSON_VALUE(content, '$.DT_INCLUSAO') AS STRING)), "America/Sao_Paulo") AS dt_inclusao, | ||
PARSE_DATE("%Y-%m-%d", SAFE_CAST(JSON_VALUE(content, '$.DT_INICIO_VALIDADE') AS STRING)) AS dt_inicio_validade, | ||
PARSE_DATE("%Y-%m-%d", SAFE_CAST(JSON_VALUE(content, '$.DT_FIM_VALIDADE') AS STRING)) AS dt_fim_validade | ||
FROM | ||
{{ source("br_rj_riodejaneiro_bilhetagem_staging", "linha_consorcio_operadora_transporte") }} | ||
), | ||
linha_consorcio_operadora_transporte_rn AS ( | ||
SELECT | ||
*, | ||
ROW_NUMBER() OVER (PARTITION BY cd_consorcio, cd_operadora_transporte, cd_linha ORDER BY timestamp_captura DESC) AS rn | ||
FROM | ||
linha_consorcio_operadora_transporte | ||
) | ||
SELECT | ||
* EXCEPT(rn) | ||
FROM | ||
linha_consorcio_operadora_transporte_rn | ||
WHERE | ||
rn = 1 |