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

[dbt] br_cvm #271

Merged
merged 5 commits into from
Sep 20, 2023
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
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',
folhesgabriel marked this conversation as resolved.
Show resolved Hide resolved
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
folhesgabriel marked this conversation as resolved.
Show resolved Hide resolved
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
Loading