From 635f220c87b4ac79db00171e4cbe83afd3af94cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Gusm=C3=A3o?= Date: Fri, 29 Sep 2023 20:12:40 -0300 Subject: [PATCH] feat: br_innmet_bdmep model v2 --- .../br_inmet_bdmep__microdados.sql | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/models/br_inmet_bdmep/br_inmet_bdmep__microdados.sql b/models/br_inmet_bdmep/br_inmet_bdmep__microdados.sql index 7b8f262b..a1e92d4d 100644 --- a/models/br_inmet_bdmep/br_inmet_bdmep__microdados.sql +++ b/models/br_inmet_bdmep/br_inmet_bdmep__microdados.sql @@ -1,6 +1,26 @@ -{{ config(alias='microdados', schema='br_inmet_bdmep') }} +{{ config(alias='microdados', schema='br_inmet_bdmep', + materialized='table', + partition_by={ + "field": "ano", + "data_type": "int64", + "range": { + "start": 2000, + "end": 2023, + "interval": 1} + }, + cluster_by = ["id_estacao"], + 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(CAST(ano AS INT64),CAST(extract(MONTH FROM data) as INT64),1), 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(CAST(ano AS INT64),cast(extract(MONTH FROM data) as INT64),1), MONTH) <= 6)'] ) }} SELECT SAFE_CAST(ano AS INT64) ano, +SAFE_CAST(extract(MONTH FROM SAFE_CAST(data AS DATE)) as INT64) mes, SAFE_CAST(data AS DATE) data, SAFE_CAST(hora AS TIME) hora, SAFE_CAST(id_estacao AS STRING) id_estacao,