-
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.
Cria tabela de receita de autuação (#194)
* criacao da view de autuacoes da citran * cria tabela de autuaçoes com dados da citran * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * exclusao de comentarios e movimentação de constantes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * correções no schema, tratamento de strings vazias e alteração no id_autuacao * corrige formatação * Adiciona condição para valor null em autuacao e corrige nome de coluna em autuacao_citran * corrige colunas status_infracao e descricao_situacao_autuacao * corrige filtro incremental * atualiza changelog * cria tabela de receita de autuação * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Altera a tabela para incremental * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * corrige referencia a tabela utilizando source e atualiza changelog * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b27ef24
commit 05d0740
Showing
4 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
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
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
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,56 @@ | ||
{{ config( | ||
materialized='incremental', | ||
partition_by={ | ||
"field": "data", | ||
"data_type": "date", | ||
"granularity": "day" | ||
}, | ||
incremental_strategy='insert_overwrite' | ||
) }} | ||
|
||
WITH receita_unpivot AS ( | ||
SELECT | ||
ano, | ||
CASE | ||
WHEN mes = 'janeiro' THEN '01' | ||
WHEN mes = 'fevereiro' THEN '02' | ||
WHEN mes = 'marco' THEN '03' | ||
WHEN mes = 'abril' THEN '04' | ||
WHEN mes = 'maio' THEN '05' | ||
WHEN mes = 'junho' THEN '06' | ||
WHEN mes = 'julho' THEN '07' | ||
WHEN mes = 'agosto' THEN '08' | ||
WHEN mes = 'setembro' THEN '09' | ||
WHEN mes = 'outubro' THEN '10' | ||
WHEN mes = 'novembro' THEN '11' | ||
WHEN mes = 'dezembro' THEN '12' | ||
END AS mes, | ||
SAFE_CAST(REPLACE(REPLACE(valor_arrecadacao, '.', ''), ',', '.') AS NUMERIC) AS valor_arrecadacao | ||
FROM | ||
{{ source('infracao_staging','receita_autuacao') }} | ||
UNPIVOT ( | ||
valor_arrecadacao FOR mes IN (janeiro, fevereiro, marco, abril, maio, junho, julho, agosto, setembro, outubro, novembro, dezembro) | ||
) | ||
|
||
), | ||
|
||
receita_com_data AS ( | ||
SELECT | ||
PARSE_DATE('%Y-%m-%d', CONCAT(ano, '-', mes, '-01')) AS data, | ||
ano, | ||
mes, | ||
valor_arrecadacao | ||
FROM receita_unpivot | ||
WHERE valor_arrecadacao IS NOT NULL | ||
) | ||
|
||
SELECT | ||
data, | ||
ano, | ||
mes, | ||
valor_arrecadacao | ||
FROM receita_com_data | ||
{% if is_incremental() %} | ||
WHERE | ||
data BETWEEN DATE("{{ var('date_range_start') }}") AND DATE("{{ var('date_range_end') }}") | ||
{% endif %} |
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