Skip to content

Commit

Permalink
cria modelo
Browse files Browse the repository at this point in the history
  • Loading branch information
pixuimpou committed Aug 23, 2024
1 parent dd7ed71 commit b442285
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
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
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

0 comments on commit b442285

Please sign in to comment.