-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00428a4
commit 202e7ec
Showing
1 changed file
with
8 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
@@ -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, | ||
|
@@ -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 %} |