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_anp_precos_combustiveis #293

Merged
merged 1 commit into from
Sep 14, 2023
Merged
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
@@ -1,7 +1,7 @@
{{ config(
alias='microdados',
schema='br_anp_precos_combustiveis',
materialized='table',
materialized='incremental',
partition_by={
"field": "ano",
"data_type": "int64",
Expand All @@ -11,9 +11,18 @@
"interval": 1}
},
cluster_by = ["id_municipio", "sigla_uf"],
labels = {'project_id': 'basedosdados-dev'})
}}

labels = {'project_id': 'basedosdados-dev'},
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(CURRENT_DATE(),DATE(data_coleta), week) > 6)',
'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter
ON {{this}}
GRANT TO ("group:[email protected]", "group:[email protected]")
FILTER USING (EXTRACT(YEAR from data_coleta) = EXTRACT(YEAR from CURRENT_DATE()))'])}}
WITH tabela_teste AS (
SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
Expand All @@ -29,5 +38,8 @@ INITCAP(produto) AS produto,
SAFE_CAST(unidade_medida AS STRING) unidade_medida,
SAFE_CAST(preco_compra AS FLOAT64) preco_compra,
SAFE_CAST(preco_venda AS FLOAT64) preco_venda
FROM basedosdados-dev.br_anp_precos_combustiveis_staging.microdados AS t
WHERE DATE(data_coleta) <= DATE_SUB(CURRENT_DATE, INTERVAL 6 WEEK)
FROM basedosdados-dev.br_anp_precos_combustiveis_staging.microdados AS t)
SELECT * FROM tabela_teste
{% if is_incremental() %}
WHERE data_coleta> (SELECT MAX(data_coleta) FROM {{ this }} )
{% endif %}
Loading