-
Notifications
You must be signed in to change notification settings - Fork 23
fix(world_wb_mides): repair the models, split them per state, and stop table-approve materialising subdirectories #1907
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
Merged
Merged
Changes from all commits
Commits
Show all changes
115 commits
Select commit
Hold shift + click to select a range
2ae243f
fix(world_wb_mides): remove phantom models, unpin staging project, wi…
rdahis aca26c7
refactor(world_wb_mides): one model per state behind each published t…
rdahis aae97e7
fix(ci): only treat models/<dataset>/<model>.sql as a table in table-…
rdahis 52d7b80
Merge remote-tracking branch 'origin/main' into data/world_wb_mides-c…
rdahis b3862c0
feat(world_wb_mides): add Tocantins to empenho, liquidacao and pagamento
rdahis a0b2ba9
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 0c49407
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] b6854c6
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 37ccb89
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] cc0cb84
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] cad39ad
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 862d599
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 46a7567
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] b3ed8ca
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 972e9de
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 828f6e7
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] fee35ee
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 0244a38
Revert "feat(world_wb_mides): add Tocantins to empenho, liquidacao an…
rdahis 435b52e
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 1fb020c
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 15172e4
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 1ba0f8c
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 3f73fc8
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 28ad5cb
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 06f8651
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] c68687b
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 8f75815
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] d2b4267
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 25ebbd7
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] edf9703
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 6a576d5
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 19e0522
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 85ce579
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 451bb0c
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 086db1e
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 59d4642
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 32f767e
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] f7f2f42
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] f828c7a
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 8015cd9
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 449c438
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 8cb4bd4
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] e6496bd
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] e24d820
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 713a810
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 396c202
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 83b4cf5
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] ce591e2
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 2007076
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] d0e8558
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] b1e109f
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] ba492f1
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 75446b7
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] d4bab9e
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] eb8f54b
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] fb28823
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] bbe87ef
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 627416b
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] c13daca
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] bf4065a
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 41fc9f0
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] e5025b7
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 2487915
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 1e7cdbf
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] ec518f8
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] e472e33
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 5c2a478
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 5ca683a
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 2f0b837
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 1d5c440
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 7b754b7
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] a0d9f0a
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 2487297
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 11a37ba
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 534e4ca
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 155b45d
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] d28e0f9
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 8682f6c
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 7dd68e2
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 0607e81
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 446d7e6
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 92e6a09
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] cfab203
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] ba013ab
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] a6691af
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 08ed365
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] b10f92c
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 4265469
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 8409c75
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 27d7fe4
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 75cea7d
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] ae7f2bd
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 3f28ba8
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] fcb49f6
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 195b730
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] e57c1af
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] a336a53
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 29c84fe
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] ec292cc
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 870e5ba
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 704a525
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] dd6bba9
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 53797f0
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 1e98f64
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] e720b92
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 16f855c
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 478ca7b
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] d279dca
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] bcf6b17
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 1f5ee48
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] bf16ecd
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 63c0c4b
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] db7b81a
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 949a4c9
Merge branch 'main' into data/world_wb_mides-cleanup
mergify[bot] 9f95359
fix(world_wb_mides): RJ v2 municipal payments carried empenho ids in …
rdahis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
133 changes: 133 additions & 0 deletions
133
models/world_wb_mides/states/world_wb_mides__empenho_ce.sql
This file contains hidden or 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,133 @@ | ||
| -- Ceará (CE) contribution to world_wb_mides.empenho. | ||
| -- Split out of the monolithic empenho model. The SQL is unchanged: the CTE | ||
| -- bodies are byte-identical and the union order is preserved, so this model | ||
| -- emits exactly the rows and column positions it did before the split. | ||
| -- Column names are positional -- the parent model applies the canonical list. | ||
| -- Materialisation is set in dbt_project.yml (models/world_wb_mides/states). | ||
| with | ||
| empenhado_ce as ( | ||
| select | ||
| (safe_cast(extract(year from date(data_emissao_empenho)) as int64)) as ano, | ||
| (safe_cast(extract(month from date(data_emissao_empenho)) as int64)) as mes, | ||
| safe_cast( | ||
| extract(date from timestamp(data_emissao_empenho)) as date | ||
| ) as data, | ||
| 'CE' as sigla_uf, | ||
| safe_cast(geoibgeid as string) as id_municipio, | ||
| safe_cast(codigo_orgao as string) as orgao, | ||
| safe_cast(trim(codigo_unidade) as string) as id_unidade_gestora, | ||
| safe_cast(null as string) as id_licitacao_bd, | ||
| safe_cast(numero_licitacao as string) as id_licitacao, | ||
| case | ||
| when tipo_processo_licitatorio = 'N' | ||
| then '98' | ||
| when tipo_processo_licitatorio = 'R' | ||
| then '2' | ||
| when tipo_processo_licitatorio = 'D' | ||
| then '8' | ||
| when tipo_processo_licitatorio = 'I' | ||
| then '10' | ||
| when tipo_processo_licitatorio = 'R' | ||
| then '29' | ||
| end as modalidade_licitacao, | ||
| safe_cast( | ||
| concat( | ||
| numero_empenho, | ||
| ' ', | ||
| trim(codigo_orgao), | ||
| ' ', | ||
| trim(codigo_unidade), | ||
| ' ', | ||
| geoibgeid, | ||
| ' ', | ||
| (substring(data_emissao_empenho, 6, 2)), | ||
| ' ', | ||
| (substring(data_emissao_empenho, 3, 2)) | ||
| ) as string | ||
| ) as id_empenho_bd, | ||
| safe_cast(null as string) as id_empenho, | ||
| safe_cast(numero_empenho as string) as numero, | ||
| safe_cast(lower(descricao_empenho) as string) as descricao, | ||
| safe_cast(modalidade_empenho as string) as modalidade, | ||
| safe_cast(safe_cast(codigo_funcao as int64) as string) as funcao, | ||
| safe_cast(safe_cast(codigo_subfuncao as int64) as string) as subfuncao, | ||
| safe_cast(safe_cast(codigo_programa as int64) as string) as programa, | ||
| safe_cast(safe_cast(codigo_projeto_atividade as int64) as string) as acao, | ||
| safe_cast( | ||
| safe_cast(codigo_elemento_despesa as int64) as string | ||
| ) as modalidade_despesa, | ||
| round(safe_cast(valor_empenhado as float64), 2) as valor_inicial, | ||
| from {{ set_datalake_project("world_wb_mides_staging.raw_empenho_ce") }} e | ||
|
|
||
| ), | ||
| anulacao_ce as ( | ||
| select | ||
| safe_cast( | ||
| concat( | ||
| numero_empenho, | ||
| ' ', | ||
| trim(codigo_orgao), | ||
| ' ', | ||
| trim(codigo_unidade), | ||
| ' ', | ||
| geoibgeid, | ||
| ' ', | ||
| (substring(data_emissao_empenho, 6, 2)), | ||
| ' ', | ||
| (substring(data_emissao_empenho, 3, 2)) | ||
| ) as string | ||
| ) as id_empenho_bd, | ||
| round(sum(safe_cast(valor_anulacao as float64)), 2) as valor_anulacao | ||
| from {{ set_datalake_project("world_wb_mides_staging.raw_anulacao_ce") }} | ||
| group by 1 | ||
|
|
||
| ), | ||
| frequencia_ce as ( | ||
| select id_empenho_bd, count(id_empenho_bd) as frequencia_id | ||
| from empenhado_ce | ||
| group by 1 | ||
| order by 2 desc | ||
|
|
||
| ), | ||
| empenho_ce as ( | ||
| select | ||
| e.ano, | ||
| e.mes, | ||
| e.data, | ||
| e.sigla_uf, | ||
| e.id_municipio, | ||
| e.orgao, | ||
| e.id_unidade_gestora, | ||
| e.id_licitacao_bd, | ||
| e.id_licitacao, | ||
| e.modalidade_licitacao, | ||
| ( | ||
| case | ||
| when frequencia_id > 1 | ||
| then (safe_cast(null as string)) | ||
| else e.id_empenho_bd | ||
| end | ||
| ) as id_empenho_bd, | ||
| e.id_empenho, | ||
| e.numero, | ||
| e.descricao, | ||
| e.modalidade, | ||
| e.funcao, | ||
| e.subfuncao, | ||
| e.programa, | ||
| e.acao, | ||
| e.modalidade_despesa, | ||
| round(e.valor_inicial, 2), | ||
| round(safe_cast(0 as float64), 2) as valor_reforco, | ||
| round(a.valor_anulacao, 2), | ||
| round(safe_cast(0 as float64), 2) as valor_ajuste, | ||
| round( | ||
| ifnull(e.valor_inicial, 0) - ifnull(a.valor_anulacao, 0), 2 | ||
| ) as valor_final | ||
| from empenhado_ce e | ||
| left join frequencia_ce f on e.id_empenho_bd = f.id_empenho_bd | ||
| full outer join anulacao_ce a on a.id_empenho_bd = e.id_empenho_bd | ||
|
|
||
| ) | ||
| select * | ||
| from empenho_ce | ||
104 changes: 104 additions & 0 deletions
104
models/world_wb_mides/states/world_wb_mides__empenho_df.sql
This file contains hidden or 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,104 @@ | ||
| -- Distrito Federal (DF) contribution to world_wb_mides.empenho. | ||
| -- Split out of the monolithic empenho model. The SQL is unchanged: the CTE | ||
| -- bodies are byte-identical and the union order is preserved, so this model | ||
| -- emits exactly the rows and column positions it did before the split. | ||
| -- Column names are positional -- the parent model applies the canonical list. | ||
| -- Materialisation is set in dbt_project.yml (models/world_wb_mides/states). | ||
| with | ||
| empenho_df as ( | ||
| select | ||
| (safe_cast(exercicio as int64)) as ano, | ||
| (safe_cast(extract(month from date(lancamento)) as int64)) as mes, | ||
| safe_cast(lancamento as date) as data, | ||
| 'DF' as sigla_uf, | ||
| '5300108' as id_municipio, | ||
| safe_cast(codigo_ug as string) as orgao, | ||
| safe_cast(codigo_gestao as string) as id_unidade_gestora, | ||
| safe_cast(null as string) as id_licitacao_bd, | ||
| safe_cast(null as string) as id_licitacao, | ||
| case | ||
| when codigo_licitacao = '1' | ||
| then '11' | ||
| when codigo_licitacao = '2' | ||
| then '1' | ||
| when codigo_licitacao = '3' | ||
| then '2' | ||
| when codigo_licitacao = '4' | ||
| then '3' | ||
| when codigo_licitacao = '5' | ||
| then '8' | ||
| when codigo_licitacao = '6' | ||
| then '10' | ||
| when codigo_licitacao = '7' | ||
| then '99' | ||
| when codigo_licitacao = '8' | ||
| then '32' | ||
| when codigo_licitacao = '9' | ||
| then '4' | ||
| when codigo_licitacao = '10' | ||
| then '32' | ||
| when codigo_licitacao = '11' | ||
| then '31' | ||
| when codigo_licitacao = '12' | ||
| then '' | ||
| when codigo_licitacao = '13' | ||
| then '5' | ||
| when codigo_licitacao = '14' | ||
| then '6' | ||
| when codigo_licitacao = '15' | ||
| then '5' | ||
| when codigo_licitacao = '16' | ||
| then '5' | ||
| when codigo_licitacao = '17' | ||
| then '6' | ||
| when codigo_licitacao = '18' | ||
| then '3' | ||
| when codigo_licitacao = '19' | ||
| then '32' | ||
| when codigo_licitacao = '20' | ||
| then '31' | ||
| when codigo_licitacao = '21' | ||
| then '31' | ||
| when codigo_licitacao = '22' | ||
| then '32' | ||
| when codigo_licitacao = '23' | ||
| then '12' | ||
| when codigo_licitacao = '25' | ||
| then '98' | ||
| when codigo_licitacao = 'INEXIGÍVEL' | ||
| then '10' | ||
| end as modalidade_licitacao, | ||
| safe_cast( | ||
| concat( | ||
| right(nota_empenho, length(nota_empenho) - 6), | ||
| ' ', | ||
| codigo_ug, | ||
| ' ', | ||
| codigo_gestao, | ||
| ' ', | ||
| '5300108', | ||
| ' ', | ||
| (right(exercicio, 2)) | ||
| ) as string | ||
| ) as id_empenho_bd, | ||
| safe_cast(null as string) as id_empenho, | ||
| safe_cast(nota_empenho as string) as numero, | ||
| safe_cast(descricao as string) as descricao, | ||
| safe_cast(left(modalidade_empenho, 1) as string) as modalidade, | ||
| safe_cast(cast(codigo_funcao as int64) as string) as funcao, | ||
| safe_cast(codigo_subfuncao as string) as subfuncao, | ||
| safe_cast(codigo_programa as string) as programa, | ||
| safe_cast(codigo_acao as string) as acao, | ||
| safe_cast(codigo_natureza as string) as elemento_despesa, | ||
| round(safe_cast(0 as float64), 2) as valor_inicial, | ||
| round(safe_cast(0 as float64), 2) as valor_reforco, | ||
| round(safe_cast(0 as float64), 2) as valor_anulacao, | ||
| round(safe_cast(0 as float64), 2) as valor_ajuste, | ||
| round( | ||
| safe_cast(replace (valor_final, ',', '.') as float64), 2 | ||
| ) as valor_final | ||
| from {{ set_datalake_project("world_wb_mides_staging.raw_empenho_df") }} | ||
|
|
||
| ) | ||
| select * | ||
| from empenho_df |
95 changes: 95 additions & 0 deletions
95
models/world_wb_mides/states/world_wb_mides__empenho_mg.sql
This file contains hidden or 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,95 @@ | ||
| -- Minas Gerais (MG) contribution to world_wb_mides.empenho. | ||
| -- Split out of the monolithic empenho model. The SQL is unchanged: the CTE | ||
| -- bodies are byte-identical and the union order is preserved, so this model | ||
| -- emits exactly the rows and column positions it did before the split. | ||
| -- Column names are positional -- the parent model applies the canonical list. | ||
| -- Materialisation is set in dbt_project.yml (models/world_wb_mides/states). | ||
| with | ||
| empenhado_mg as ( | ||
| select | ||
| safe_cast(ano as int64) as ano, | ||
| safe_cast(mes as int64) as mes, | ||
| safe_cast(data as date) as data, | ||
| 'MG' as sigla_uf, | ||
| safe_cast(id_municipio as string) as id_municipio, | ||
| safe_cast(trim(orgao) as string) as orgao, | ||
| safe_cast(id_unidade_gestora as string) as id_unidade_gestora, | ||
| safe_cast(null as string) as id_licitacao_bd, | ||
| safe_cast(id_licitacao as string) as id_licitacao, | ||
| safe_cast(null as string) as modalidade_licitacao, | ||
| safe_cast( | ||
| concat( | ||
| id_empenho, ' ', orgao, ' ', id_municipio, ' ', (right(ano, 2)) | ||
| ) as string | ||
| ) as id_empenho_bd, | ||
| safe_cast(id_empenho as string) as id_empenho, | ||
| safe_cast(numero_empenho as string) as numero, | ||
| safe_cast(lower(descricao) as string) as descricao, | ||
| safe_cast(substring(dsc_modalidade, 5, 1) as string) as modalidade, | ||
| safe_cast(cast(left(dsc_funcao, 2) as int64) as string) as funcao, | ||
| safe_cast(cast(left(dsc_subfuncao, 3) as int64) as string) as subfuncao, | ||
| safe_cast(cast(left(dsc_programa, 4) as int64) as string) as programa, | ||
| safe_cast(cast(left(dsc_acao, 4) as int64) as string) as acao, | ||
| safe_cast( | ||
| replace(left(elemento_despesa, 12), '.', '') as string | ||
| ) as elemento_despesa, | ||
| round(safe_cast(valor_empenho_original as float64), 2) as valor_inicial, | ||
| round( | ||
| safe_cast(ifnull(safe_cast(valor_reforco as float64), 0) as float64), 2 | ||
| ) as valor_reforco, | ||
| round( | ||
| safe_cast(ifnull(safe_cast(valor_anulacao as float64), 0) as float64), 2 | ||
| ) as valor_anulacao, | ||
| round(safe_cast(0 as float64), 2) as valor_ajuste, | ||
| round( | ||
| safe_cast(valor_empenho_original as float64) | ||
| + safe_cast(ifnull(safe_cast(valor_reforco as float64), 0) as float64) | ||
| - safe_cast(ifnull(safe_cast(valor_anulacao as float64), 0) as float64), | ||
| 2 | ||
| ) as valor_final | ||
| from {{ set_datalake_project("world_wb_mides_staging.raw_empenho_mg") }} | ||
|
|
||
| ), | ||
| dlic as ( | ||
| select | ||
| id_empenho_bd, | ||
| case when (count(distinct id_licitacao)) > 1 then 1 else 0 end as dlic | ||
| from empenhado_mg | ||
| group by 1 | ||
|
|
||
| ), | ||
| empenho_mg as ( | ||
| select distinct | ||
| e.ano, | ||
| e.mes, | ||
| e.data, | ||
| e.sigla_uf, | ||
| e.id_municipio, | ||
| e.orgao, | ||
| e.id_unidade_gestora, | ||
| e.id_licitacao_bd, | ||
| case | ||
| when dlic = 1 then (safe_cast(null as string)) else e.id_licitacao | ||
| end as id_licitacao, | ||
| e.modalidade_licitacao, | ||
| e.id_empenho_bd, | ||
| e.id_empenho, | ||
| e.numero, | ||
| e.descricao, | ||
| e.modalidade, | ||
| e.funcao, | ||
| e.subfuncao, | ||
| e.programa, | ||
| e.acao, | ||
| e.elemento_despesa, | ||
| e.valor_inicial, | ||
| e.valor_reforco, | ||
| e.valor_anulacao, | ||
| e.valor_ajuste, | ||
| e.valor_final | ||
| from empenhado_mg e | ||
| left join dlic l on l.id_empenho_bd = e.id_empenho_bd | ||
|
|
||
| ) | ||
| select * | ||
| from empenho_mg |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Duplicate
'R'branch makes'29'unreachable.Line 24 maps
tipo_processo_licitatorio = 'R'to'2'. Line 30 repeats the same predicate and can never match, so'29'is never produced. If the second branch belongs to a different source code, correct the literal. If'2'is correct, delete lines 30-31.The split is byte-identical by design, so this is carried over from the monolithic model. Confirm the intended mapping before the rebuild, because the
table-approvelabel rebuildsempenho.Proposed cleanup if
'2'is correctwhen tipo_processo_licitatorio = 'I' then '10' - when tipo_processo_licitatorio = 'R' - then '29' end as modalidade_licitacao,📝 Committable suggestion
🤖 Prompt for AI Agents