Skip to content

Commit

Permalink
incremental
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielle-carv committed Oct 6, 2023
1 parent 00428a4 commit 202e7ec
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions models/br_me_cnpj/estabelecimentos.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{
config(
schema='br_me_cnpj',
materialized='table',
materialized='incremental',
partition_by={
"field": "data",
"data_type": "date",
Expand All @@ -17,8 +17,8 @@
GRANT TO ("group:[email protected]", "group:[email protected]")
FILTER USING (EXTRACT(YEAR from data) = EXTRACT(YEAR from CURRENT_DATE()))' ])
}}

SELECT
WITH cnpj_estabelecimentos AS
(SELECT
SAFE_CAST(data AS DATE) data,
SAFE_CAST(lpad(cnpj,14,"0") AS STRING) cnpj,
SAFE_CAST(lpad(cnpj_basico, 8, '0') AS STRING) cnpj_basico,
Expand Down Expand Up @@ -54,5 +54,8 @@ SELECT
SAFE_CAST(data_situacao_especial AS DATE) data_situacao_especial
FROM basedosdados-staging.br_me_cnpj_staging.estabelecimentos a
LEFT JOIN basedosdados.br_bd_diretorios_brasil.municipio b
ON a.id_municipio_rf = b.id_municipio_rf

ON a.id_municipio_rf = b.id_municipio_rf)
SELECT * FROM cnpj_estabelecimentos
{% if is_incremental() %}
WHERE data > (SELECT MAX(data) FROM {{ this }} )
{% endif %}

0 comments on commit 202e7ec

Please sign in to comment.