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

[dados-atualizacao] world_wb_mides #441

Merged
merged 4 commits into from
Feb 22, 2024
Merged
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
134 changes: 130 additions & 4 deletions models/world_wb_mides/world_wb_mides__empenho.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
partition_by={
"field": "ano",
"data_type": "int64",
"range": {"start": 1994, "end": 2022, "interval": 1},
"range": {"start": 1994, "end": 2024, "interval": 1},
},
cluster_by=["mes", "sigla_uf"],
labels={"tema": "economia"},
Expand Down Expand Up @@ -2025,16 +2025,140 @@ from
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(replace(valor_inicial, ',', '.') as float64), 2
) as valor_inicial,
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 `basedosdados-staging.world_wb_mides_staging.raw_empenho_df`
),
empenhado_sc as (
select
safe_cast(ano_emp as int64) as ano,
safe_cast(substring(trim(data_empenho), -7, 2) as int64) as mes,
safe_cast(
concat(
substring(trim(data_empenho), -4),
'-',
substring(trim(data_empenho), -7, 2),
'-',
substring(trim(data_empenho), 1, 2)
) as date
) as data,
'SC' as sigla_uf,
safe_cast(id_municipio as string) as id_municipio,
safe_cast(codigo_orgao as string) as orgao,
safe_cast(null as string) as id_unidade_gestora,
safe_cast(null as string) as id_licitacao_bd,
safe_cast(
case
when
(
split(nr_licitacao_contrato_convenio, ' / ')[
offset(0)
]
)
!= "Sem Licitação"
and (
split(nr_licitacao_contrato_convenio, ' / ')[
offset(0)
]
)
!= "Sem licitação"
and (
split(nr_licitacao_contrato_convenio, ' / ')[
offset(0)
]
)
!= "Sem Licitacao"
and (
split(nr_licitacao_contrato_convenio, ' / ')[
offset(0)
]
)
!= "SEM LICITACAO"
then
(
split(nr_licitacao_contrato_convenio, ' / ')[
offset(0)
]
)
else ''
end as string
) as id_licitacao,
safe_cast(null as string) as modalidade_licitacao,
safe_cast(
concat(
num_empenho,
' ',
codigo_orgao,
' ',
id_municipio,
' ',
(right(cast(ano_emp as string), 2))
) as string
) as id_empenho_bd,
safe_cast(null as string) as id_empenho,
safe_cast(num_empenho as string) as numero,
safe_cast(
lower(descricao_historico_empenho) as string
) as descricao,
safe_cast(null as string) as modalidade,
safe_cast(cast(left(funcao, 2) as int64) as string) as funcao,
safe_cast(cast(left(subfuncao, 3) as int64) as string) as subfuncao,
safe_cast(null as string) as programa,
safe_cast(null as string) as acao,
safe_cast(elemento_despesa as string) as elemento_despesa,
round(safe_cast(valor_empenho 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(valor_empenho as float64), 2) as valor_final
from `basedosdados-staging.world_wb_mides_staging.raw_empenho_sc`
),
frequencia_sc as (
select id_empenho_bd, count(id_empenho_bd) as frequencia_id
from empenhado_sc
group by 1
order by 2 desc
),
empenho_sc 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.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,
e.valor_final as valor_final
from empenhado_sc e
left join frequencia_sc f on e.id_empenho_bd = f.id_empenho_bd
)

select *
Expand All @@ -2061,4 +2185,6 @@ from
(select * from empenho_municipio_rj_v2)
union all
(select * from empenho_df)
union all
(select * from empenho_sc)
)
89 changes: 80 additions & 9 deletions models/world_wb_mides/world_wb_mides__liquidacao.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
partition_by={
"field": "ano",
"data_type": "int64",
"range": {"start": 1995, "end": 2022, "interval": 1},
"range": {"start": 1995, "end": 2024, "interval": 1},
},
cluster_by=["mes", "sigla_uf"],
labels={"tema": "economia"},
Expand Down Expand Up @@ -162,10 +162,9 @@ from
2
) as valor_final
from
`basedosdados-staging.world_wb_mides_staging.raw_liquidacao_mg `
as l
`basedosdados-staging.world_wb_mides_staging.raw_liquidacao_mg` as l
left join
`basedosdados-staging.world_wb_mides_staging.raw_rsp_mg ` as r
`basedosdados-staging.world_wb_mides_staging.raw_rsp_mg` as r
on l.id_rsp = r.id_rsp
),
liquidacao_pb as (
Expand Down Expand Up @@ -961,15 +960,85 @@ from
safe_cast(credor as string) as nome_responsavel,
safe_cast(cnpj_cpf_credor as string) as documento_responsavel,
safe_cast(null as bool) as indicador_restos_pagar,
round(
safe_cast(replace (valor, ',', '.') as float64), 2
) as valor_inicial,
round(safe_cast(0 as float64), 2) as valor_inicial,
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, ',', '.') as float64), 2
) as valor_final
safe_cast(replace(valor, ',', '.') as float64), 2
) as valor_inicial,
from `basedosdados-staging.world_wb_mides_staging.raw_liquidacao_df`
),
liquidado_sc as (
select
safe_cast(ano_emp as int64) as ano,
safe_cast(substring(trim(data_empenho), -7, 2) as int64) as mes,
safe_cast(null as date) as data,
'SC' as sigla_uf,
safe_cast(id_municipio as string) as id_municipio,
safe_cast(codigo_orgao as string) as orgao,
safe_cast(null as string) as id_unidade_gestora,
safe_cast(
concat(
num_empenho,
' ',
codigo_orgao,
' ',
id_municipio,
' ',
(right(cast(ano_emp as string), 2))
) as string
) as id_empenho_bd,
safe_cast(null as string) as id_empenho,
safe_cast(num_empenho as string) as numero_empenho,
safe_cast(null as string) as id_liquidacao_bd,
safe_cast(null as string) as id_liquidacao,
safe_cast(null as string) as numero,
safe_cast(null as string) as nome_responsavel,
safe_cast(null as string) as documento_responsavel,
safe_cast(null as bool) as indicador_restos_pagar,
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(valor_liquidacao as float64), 2) as valor_final
from `basedosdados-staging.world_wb_mides_staging.raw_empenho_sc`
),
frequencia_sc as (
select id_empenho_bd, count(id_empenho_bd) as frequencia_id
from liquidado_sc
group by 1
order by 2 desc
),
liquidacao_sc as (
select
l.ano,
l.mes,
l.data,
l.sigla_uf,
l.id_municipio,
l.orgao,
l.id_unidade_gestora,
(
case
when frequencia_id > 1
then (safe_cast(null as string))
else l.id_empenho_bd
end
) as id_empenho_bd,
l.id_empenho,
l.numero_empenho,
l.id_liquidacao_bd,
l.id_liquidacao,
l.numero,
l.nome_responsavel,
l.documento_responsavel,
l.indicador_restos_pagar,
l.valor_inicial,
l.valor_anulacao,
l.valor_ajuste,
l.valor_final
from liquidado_sc l
left join frequencia_sc f on l.id_empenho_bd = f.id_empenho_bd
)

select *
Expand All @@ -996,4 +1065,6 @@ from
(select * from liquidacao_rj)
union all
(select * from liquidacao_df)
union all
(select * from liquidacao_sc)
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
schema="world_wb_mides",
materialized="table",
cluster_by=["sigla_uf"],
labels={"tema": "economia"},
labels={"project_id": "basedosdados", "tema": "economia"},
)
}}
-- inclui novos municípios e estados
select
safe_cast(ano as string) ano,
safe_cast(sigla_uf as string) sigla_uf,
Expand All @@ -17,4 +16,8 @@ select
safe_cast(id_unidade_gestora as string) id_unidade_gestora,
safe_cast(nome_unidade_gestora as string) nome_unidade_gestora,
safe_cast(esfera as string) esfera
from `basedosdados-staging.world_wb_mides_staging.orgao_unidade_gestora` as t
from
`basedosdados-staging.world_wb_mides_staging.orgao_unidade_gestora` as t

-- contém 10 UFs: CE, DF, MG, PB, PE, PR, RJ, RS, SC, SP

Loading
Loading