Skip to content

Commit

Permalink
Merge branch 'staging/mundo_transfermarkt_competicoes.copa_brasil' of h…
Browse files Browse the repository at this point in the history
…ttps://github.com/basedosdados/queries-basedosdados into staging/mundo_transfermarkt_competicoes.copa_brasil
  • Loading branch information
gabrielle-carv committed Sep 21, 2023
2 parents 42be26c + 3a18d8a commit e599bbe
Show file tree
Hide file tree
Showing 15 changed files with 730 additions and 122 deletions.
499 changes: 499 additions & 0 deletions metadata.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{
config(
alias = 'pessoa_fisica',
schema='br_cvm_administradores_carteira',
materialized='incremental',
partition_by = {
"field": "data_registro",
"data_type": "date",
"granularity": "day"
},
pre_hook = "DROP ALL ROW ACCESS POLICIES ON {{ this }}",
post_hook=['CREATE OR REPLACE ROW ACCESS POLICY allusers_filter
ON {{this}}
GRANT TO ("allUsers")
FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(data_registro), MONTH) > 6)',
'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter
ON {{this}}
GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org")
FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(data_registro), MONTH) <= 6)']
)
}}
WITH tabela as( SELECT
SAFE_CAST(nome AS STRING) nome,
SAFE_CAST(data_registro AS DATE) data_registro,
SAFE_CAST(data_cancelamento AS DATE) data_cancelamento,
SAFE_CAST(motivo_cancelamento AS STRING) motivo_cancelamento,
SAFE_CAST(situacao AS STRING) situacao,
SAFE_CAST(data_inicio_situacao AS DATE) data_inicio_situacao,
SAFE_CAST(categoria_registro AS STRING) categoria_registro
FROM basedosdados-staging.br_cvm_administradores_carteira_staging.pessoa_fisica AS t)
select *
from tabela
{% if is_incremental() %}

-- this filter will only be applied on an incremental run
-- (uses > to include records whose timestamp occurred since the last run of this model)
where data_registro > (select max(data_registro) from {{ this }})

{% endif %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
SELECT
{{
config(
alias = 'pessoa_juridica',
schema='br_cvm_administradores_carteira',
materialized='incremental',
partition_by = {
"field": "data_registro",
"data_type": "date",
"granularity": "day"
},
pre_hook = "DROP ALL ROW ACCESS POLICIES ON {{ this }}",
post_hook=['CREATE OR REPLACE ROW ACCESS POLICY allusers_filter
ON {{this}}
GRANT TO ("allUsers")
FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(data_registro), MONTH) > 6)',
'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter
ON {{this}}
GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org")
FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(data_registro), MONTH) <= 6)' ]
)
}}

WITH tabela as(SELECT
SAFE_CAST(cnpj AS STRING) cnpj,
SAFE_CAST(denominacao_social AS STRING) denominacao_social,
SAFE_CAST(denominacao_comercial AS STRING) denominacao_comercial,
Expand All @@ -23,4 +45,13 @@ SAFE_CAST(valor_patrimonial_liquido AS STRING) valor_patrimonial_liquido,
SAFE_CAST(data_patrimonio_liquido AS DATE) data_patrimonio_liquido,
SAFE_CAST(email AS STRING) email,
SAFE_CAST(website AS STRING) website
FROM basedosdados-staging.br_cvm_administradores_carteira_staging.pessoa_juridica AS t
FROM basedosdados-staging.br_cvm_administradores_carteira_staging.pessoa_juridica AS t)
select *
from tabela
{% if is_incremental() %}

-- this filter will only be applied on an incremental run
-- (uses > to include records whose timestamp occurred since the last run of this model)
where data_registro > (select max(data_registro) from {{ this }})

{% endif %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{{
config(
alias = 'responsavel',
schema='br_cvm_administradores_carteira',
materialized='table',
)
}}
SELECT
SAFE_CAST(cnpj AS STRING) cnpj,
SAFE_CAST(nome AS STRING) nome,
SAFE_CAST(tipo AS STRING) tipo
FROM basedosdados-staging.br_cvm_administradores_carteira_staging.responsavel AS t
FROM basedosdados-staging.br_cvm_administradores_carteira_staging.responsavel AS t
9 changes: 0 additions & 9 deletions models/br_cvm_administradores_carteira/pessoa_fisica.sql

This file was deleted.

12 changes: 6 additions & 6 deletions models/br_cvm_administradores_carteira/schema.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2

models:
- name: pessoa_fisica
description: "dbt model for pessoa_fisica"
- name: br_cvm_administradores_carteira__pessoa_fisica
description: Dados Cadastrais de Administradores de Carteira da CVM (Pessoa Física)
columns:
- name: nome
description: Nome
Expand All @@ -18,8 +18,8 @@ models:
description: Data de início da situação
- name: categoria_registro
description: Categoria de registro
- name: pessoa_juridica
description: "dbt model for pessoa_juridica"
- name: br_cvm_administradores_carteira__pessoa_juridica
description: Dados Cadastrais de Administradores de Carteira da CVM (Pessoa Jurídica)
columns:
- name: cnpj
description: Cadastro Nacional de Pessoas Jurídicas (CNPJ)
Expand Down Expand Up @@ -69,8 +69,8 @@ models:
description: Email
- name: website
description: Website
- name: responsavel
description: "dbt model for responsavel"
- name: br_cvm_administradores_carteira__responsavel
description: Dados Cadastrais de Administradores de Carteira da CVM.
columns:
- name: cnpj
description: Cadastro Nacional de Pessoas Jurídicas (CNPJ)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
SELECT
{{
config(
alias = 'dia',
schema='br_cvm_oferta_publica_distribuicao',
materialized='incremental',
partition_by = {
"field": "data_abertura_processo",
"data_type": "date",
"granularity": "day"
},
pre_hook = "DROP ALL ROW ACCESS POLICIES ON {{ this }}",
post_hook=['CREATE OR REPLACE ROW ACCESS POLICY allusers_filter
ON {{this}}
GRANT TO ("allUsers")
FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(data_abertura_processo), MONTH) > 6)',
'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter
ON {{this}}
GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org")
FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(data_abertura_processo), MONTH) <= 6)']
)
}}

WITH tabela as(SELECT
SAFE_CAST(numero_processo AS STRING) numero_processo,
SAFE_CAST(numero_registro_oferta AS STRING) numero_registro_oferta,
SAFE_CAST(tipo_oferta AS STRING) tipo_oferta,
Expand Down Expand Up @@ -43,4 +65,13 @@ SAFE_CAST(tipo_societario_emissor AS STRING) tipo_societario_emissor,
SAFE_CAST(tipo_fundo_investimento AS STRING) tipo_fundo_investimento,
SAFE_CAST(ultimo_comunicado AS STRING) ultimo_comunicado,
SAFE_CAST(data_comunicado AS DATE) data_comunicado
FROM basedosdados-staging.br_cvm_oferta_publica_distribuicao_staging.dia AS t
FROM basedosdados-staging.br_cvm_oferta_publica_distribuicao_staging.dia AS t)
SELECT *
FROM tabela
{% if is_incremental() %}

-- this filter will only be applied on an incremental run
-- (uses > to include records whose timestamp occurred since the last run of this model)
where data_abertura_processo > (select max(data_abertura_processo) from {{ this }})

{% endif %}
4 changes: 2 additions & 2 deletions models/br_cvm_oferta_publica_distribuicao/schema.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2

models:
- name: dia
description: "dbt model for table dia"
- name: br_cvm_oferta_publica_distribuicao__dia
description: Ofertas de distribuição (ações, fundos, debêntures, CRI, etc) registradas ou dispensadas de registro.
columns:
- name: numero_processo
description: Número do processo administrativo
Expand Down
16 changes: 16 additions & 0 deletions models/world_wb_mides/licitacao.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
{{
config(
schema = "world_wb_mides",
materialized = "table",
partition_by = {
"field": "ano",
"data_type": "int64",
"range": {
"start": 2009,
"end": 2021,
"interval": 1}
},
cluster_by = ["mes", "sigla_uf"],
labels = {"project_id": "basedosdados", "tema": "economia"}
)
}}
SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(mes AS INT64) mes,
Expand Down
16 changes: 16 additions & 0 deletions models/world_wb_mides/licitacao_item.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
{{
config(
schema = "world_wb_mides",
materialized = "table",
partition_by = {
"field": "ano",
"data_type": "int64",
"range": {
"start": 2009,
"end": 2022,
"interval": 1}
},
cluster_by = ["sigla_uf"],
labels = {"project_id": "basedosdados", "tema": "economia"}
)
}}
SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
Expand Down
16 changes: 16 additions & 0 deletions models/world_wb_mides/licitacao_participante.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
{{
config(
schema = "world_wb_mides",
materialized = "table",
partition_by = {
"field": "ano",
"data_type": "int64",
"range": {
"start": 2009,
"end": 2021,
"interval": 1}
},
cluster_by = ["sigla_uf"],
labels = {"project_id": "basedosdados", "tema": "economia"}
)
}}
SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
Expand Down
18 changes: 18 additions & 0 deletions models/world_wb_mides/orgao_unidade_gestora.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{
config(
schema = "world_wb_mides",
materialized = "table",
cluster_by = ["sigla_uf"],
labels = {"project_id": "basedosdados", "tema": "economia"}
)
}}
SELECT
SAFE_CAST(ano AS STRING) ano,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
SAFE_CAST(id_municipio AS STRING) id_municipio,
SAFE_CAST(orgao AS STRING) orgao,
SAFE_CAST(nome_orgao AS STRING) nome_orgao,
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
4 changes: 2 additions & 2 deletions models/world_wb_mides/pagamento.sql
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ pago_pb AS (
FROM `basedosdados-staging.world_wb_mides_staging.raw_despesa_rs` AS c
LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao
LEFT JOIN `basedosdados.br_bd_diretorios_brasil.municipio` m ON m.id_municipio = a.id_municipio
WHERE tipo_operacao = 'P' AND (SAFE_CAST(vl_liquidacao AS FLOAT64) >= 0)
WHERE tipo_operacao = 'P' AND (SAFE_CAST(vl_pagamento AS FLOAT64) >= 0)
GROUP BY 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
),
estorno_rs AS (
Expand All @@ -315,7 +315,7 @@ pago_pb AS (
FROM `basedosdados-staging.world_wb_mides_staging.raw_despesa_rs` AS c
LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao
LEFT JOIN `basedosdados.br_bd_diretorios_brasil.municipio` m ON m.id_municipio = a.id_municipio
WHERE tipo_operacao = 'P' AND (SAFE_CAST(vl_liquidacao AS FLOAT64) < 0)
WHERE tipo_operacao = 'P' AND (SAFE_CAST(vl_pagamento AS FLOAT64) < 0)
GROUP BY 1
),
frequencia_rs AS (
Expand Down
Loading

0 comments on commit e599bbe

Please sign in to comment.