diff --git a/models/br_rf_arrecadacao/br_rf_arrecadacao__cnae.sql b/models/br_rf_arrecadacao/br_rf_arrecadacao__cnae.sql index 5c3edf04..274d138e 100644 --- a/models/br_rf_arrecadacao/br_rf_arrecadacao__cnae.sql +++ b/models/br_rf_arrecadacao/br_rf_arrecadacao__cnae.sql @@ -1,25 +1,24 @@ -{{ config(alias='cnae',schema='br_rf_arrecadacao') }} +{{ config(alias="cnae", schema="br_rf_arrecadacao") }} select -safe_cast(ano as int64) ano, -safe_cast(mes as int64) mes, -safe_cast(secao_sigla as string) secao_sigla, -safe_cast(secao_nome as string) secao_nome, -safe_cast(imposto_importacao as float64) imposto_importacao, -safe_cast(imposto_exportacao as float64) imposto_exportacao, -safe_cast(ipi as float64) ipi, -safe_cast(irpf as float64) irpf, -safe_cast(irpj as float64) irpj, -safe_cast(irrf as float64) irrf, -safe_cast(iof as float64) iof, -safe_cast(itr as float64) itr, -safe_cast(cofins as float64) cofins, -safe_cast(pis_pasep as float64) pis_pasep, -safe_cast(csll as float64) csll, -safe_cast(cide_combustiveis as float64) cide_combustiveis, -safe_cast(contribuicao_previdenciaria as float64) contribuicao_previdenciaria, -safe_cast(cpsss as float64) cpsss, -safe_cast(pagamento_unificado as float64) pagamento_unificado, -safe_cast(outras_receitas_rfb as float64) outras_receitas_rfb, -safe_cast(demais_receitas as float64) demais_receitas, + safe_cast(ano as int64) ano, + safe_cast(mes as int64) mes, + safe_cast(secao_sigla as string) secao_sigla, + safe_cast(secao_nome as string) secao_nome, + safe_cast(imposto_importacao as float64) imposto_importacao, + safe_cast(imposto_exportacao as float64) imposto_exportacao, + safe_cast(ipi as float64) ipi, + safe_cast(irpf as float64) irpf, + safe_cast(irpj as float64) irpj, + safe_cast(irrf as float64) irrf, + safe_cast(iof as float64) iof, + safe_cast(itr as float64) itr, + safe_cast(cofins as float64) cofins, + safe_cast(pis_pasep as float64) pis_pasep, + safe_cast(csll as float64) csll, + safe_cast(cide_combustiveis as float64) cide_combustiveis, + safe_cast(contribuicao_previdenciaria as float64) contribuicao_previdenciaria, + safe_cast(cpsss as float64) cpsss, + safe_cast(pagamento_unificado as float64) pagamento_unificado, + safe_cast(outras_receitas_rfb as float64) outras_receitas_rfb, + safe_cast(demais_receitas as float64) demais_receitas, from `basedosdados-staging.br_rf_arrecadacao_staging.cnae` as t - diff --git a/models/br_rf_arrecadacao/br_rf_arrecadacao__ir_ipi.sql b/models/br_rf_arrecadacao/br_rf_arrecadacao__ir_ipi.sql index abb7c372..d0e21a42 100644 --- a/models/br_rf_arrecadacao/br_rf_arrecadacao__ir_ipi.sql +++ b/models/br_rf_arrecadacao/br_rf_arrecadacao__ir_ipi.sql @@ -1,14 +1,13 @@ -{{ config(alias='ir_ipi',schema='br_rf_arrecadacao') }} +{{ config(alias="ir_ipi", schema="br_rf_arrecadacao") }} select -safe_cast(ano as int64) ano, -safe_cast(mes as int64) mes, -safe_cast(tributo as string) tributo, -safe_cast(decendio as string) decendio, -safe_cast(arrecadacao_bruta as float64) arrecadacao_bruta, -safe_cast(retificacao as float64) retificacao, -safe_cast(compensacao as float64) compensacao, -safe_cast(restituicao as float64) restituicao, -safe_cast(outros as float64) outros, -safe_cast(arrecadacao_liquida as float64) arrecadacao_liquida, + safe_cast(ano as int64) ano, + safe_cast(mes as int64) mes, + safe_cast(tributo as string) tributo, + safe_cast(decendio as string) decendio, + safe_cast(arrecadacao_bruta as float64) arrecadacao_bruta, + safe_cast(retificacao as float64) retificacao, + safe_cast(compensacao as float64) compensacao, + safe_cast(restituicao as float64) restituicao, + safe_cast(outros as float64) outros, + safe_cast(arrecadacao_liquida as float64) arrecadacao_liquida, from `basedosdados-staging.br_rf_arrecadacao_staging.ir_ipi` as t - diff --git a/models/br_rf_arrecadacao/br_rf_arrecadacao__itr.sql b/models/br_rf_arrecadacao/br_rf_arrecadacao__itr.sql index 8fc00b36..62d48cc9 100644 --- a/models/br_rf_arrecadacao/br_rf_arrecadacao__itr.sql +++ b/models/br_rf_arrecadacao/br_rf_arrecadacao__itr.sql @@ -1,10 +1,9 @@ -{{ config(alias='itr',schema='br_rf_arrecadacao') }} +{{ config(alias="itr", schema="br_rf_arrecadacao") }} select -safe_cast(ano as int64) ano, -safe_cast(mes as int64) mes, -safe_cast(nome_uf as string) nome_uf, -safe_cast(regiao_politica as string) regiao_politica, -safe_cast(cidade_uf as string) cidade_uf, -safe_cast(valor_arrecadado as float64) valor_arrecadado, + safe_cast(ano as int64) ano, + safe_cast(mes as int64) mes, + safe_cast(nome_uf as string) nome_uf, + safe_cast(regiao_politica as string) regiao_politica, + safe_cast(cidade_uf as string) cidade_uf, + safe_cast(valor_arrecadado as float64) valor_arrecadado, from `basedosdados-staging.br_rf_arrecadacao_staging.itr` as t - diff --git a/models/br_rf_arrecadacao/br_rf_arrecadacao__natureza_juridica.sql b/models/br_rf_arrecadacao/br_rf_arrecadacao__natureza_juridica.sql index 3d7d07bc..2aa0cad6 100644 --- a/models/br_rf_arrecadacao/br_rf_arrecadacao__natureza_juridica.sql +++ b/models/br_rf_arrecadacao/br_rf_arrecadacao__natureza_juridica.sql @@ -1,30 +1,35 @@ -{{ config(alias='natureza_juridica',schema='br_rf_arrecadacao') }} -WITH referencia_codigo AS ( - select id_natureza_juridica,SUBSTR(CAST(id_natureza_juridica AS STRING),0,3) as inicio_codigo - FROM basedosdados-staging.br_bd_diretorios_brasil.natureza_juridica -) +{{ config(alias="natureza_juridica", schema="br_rf_arrecadacao") }} +with + referencia_codigo as ( + select + id_natureza_juridica, + substr(cast(id_natureza_juridica as string), 0, 3) as inicio_codigo + from basedosdados - staging.br_bd_diretorios_brasil.natureza_juridica + ) select -safe_cast(t.ano as int64) ano, -safe_cast(t.mes as int64) mes, -safe_cast(referencia_codigo.id_natureza_juridica as string) natureza_juridica_codigo, -safe_cast(t.natureza_juridica_nome as string) natureza_juridica_nome, -safe_cast(t.imposto_importacao as float64) imposto_importacao, -safe_cast(t.imposto_exportacao as float64) imposto_exportacao, -safe_cast(t.ipi as float64) ipi, -safe_cast(t.irpf as float64) irpf, -safe_cast(t.irpj as float64) irpj, -safe_cast(t.irrf as float64) irrf, -safe_cast(t.iof as float64) iof, -safe_cast(t.itr as float64) itr, -safe_cast(t.cofins as float64) cofins, -safe_cast(t.pis_pasep as float64) pis_pasep, -safe_cast(t.csll as float64) csll, -safe_cast(t.cide_combustiveis as float64) cide_combustiveis, -safe_cast(t.contribuicao_previdenciaria as float64) contribuicao_previdenciaria, -safe_cast(t.cpsss as float64) cpsss, -safe_cast(t.pagamento_unificado as float64) pagamento_unificado, -safe_cast(t.outras_receitas_rfb as float64) outras_receitas_rfb, -safe_cast(t.demais_receitas as float64) demais_receitas, + safe_cast(t.ano as int64) ano, + safe_cast(t.mes as int64) mes, + safe_cast( + referencia_codigo.id_natureza_juridica as string + ) natureza_juridica_codigo, + safe_cast(t.natureza_juridica_nome as string) natureza_juridica_nome, + safe_cast(t.imposto_importacao as float64) imposto_importacao, + safe_cast(t.imposto_exportacao as float64) imposto_exportacao, + safe_cast(t.ipi as float64) ipi, + safe_cast(t.irpf as float64) irpf, + safe_cast(t.irpj as float64) irpj, + safe_cast(t.irrf as float64) irrf, + safe_cast(t.iof as float64) iof, + safe_cast(t.itr as float64) itr, + safe_cast(t.cofins as float64) cofins, + safe_cast(t.pis_pasep as float64) pis_pasep, + safe_cast(t.csll as float64) csll, + safe_cast(t.cide_combustiveis as float64) cide_combustiveis, + safe_cast(t.contribuicao_previdenciaria as float64) contribuicao_previdenciaria, + safe_cast(t.cpsss as float64) cpsss, + safe_cast(t.pagamento_unificado as float64) pagamento_unificado, + safe_cast(t.outras_receitas_rfb as float64) outras_receitas_rfb, + safe_cast(t.demais_receitas as float64) demais_receitas, from `basedosdados-staging.br_rf_arrecadacao_staging.natureza_juridica` as t -left join referencia_codigo on t.natureza_juridica_codigo = referencia_codigo.inicio_codigo - +left join + referencia_codigo on t.natureza_juridica_codigo = referencia_codigo.inicio_codigo