diff --git a/models/br_mg_belohorizonte_smfa_iptu/br_mg_belohorizonte_smfa_iptu__dicionario.sql b/models/br_mg_belohorizonte_smfa_iptu/br_mg_belohorizonte_smfa_iptu__dicionario.sql new file mode 100644 index 00000000..4e1de3b9 --- /dev/null +++ b/models/br_mg_belohorizonte_smfa_iptu/br_mg_belohorizonte_smfa_iptu__dicionario.sql @@ -0,0 +1,10 @@ +{{ config(alias='dicionario', schema='br_mg_belohorizonte_smfa_iptu') }} + + +SELECT +SAFE_CAST(id_tabela AS STRING) id_tabela, +SAFE_CAST(nome_coluna AS STRING) nome_coluna, +SAFE_CAST(chave AS STRING) chave, +SAFE_CAST(cobertura_temporal AS STRING) cobertura_temporal, +SAFE_CAST(valor AS STRING) valor +FROM basedosdados-dev.br_mg_belohorizonte_smfa_iptu_staging.dicionario AS t \ No newline at end of file diff --git a/models/br_mg_belohorizonte_smfa_iptu/br_mg_belohorizonte_smfa_iptu__iptu.sql b/models/br_mg_belohorizonte_smfa_iptu/br_mg_belohorizonte_smfa_iptu__iptu.sql index 4b95ad6e..f735ba6d 100644 --- a/models/br_mg_belohorizonte_smfa_iptu/br_mg_belohorizonte_smfa_iptu__iptu.sql +++ b/models/br_mg_belohorizonte_smfa_iptu/br_mg_belohorizonte_smfa_iptu__iptu.sql @@ -1,16 +1,18 @@ {{ config( alias='iptu', schema='br_mg_belohorizonte_smfa_iptu', - materialized='incremental', + materialized='table', partition_by={ - "field": "mes", + "field": "ano", "data_type": "int64", - "granularity": "month"}, + "range": { + "start": 2022, + "end": 2023, + "interval": 1} + }, cluster_by=['tipo_construtivo', 'tipo_ocupacao', 'tipologia'], labels = {'project_id' : 'basedosdados-dev'} -) }} - -WITH iptu AS ( +)}} SELECT SAFE_CAST(ano AS INT64) ano, SAFE_CAST(mes AS INT64) mes, @@ -37,12 +39,8 @@ SAFE_CAST(indicador_agua AS BOOL) indicador_agua, SAFE.ST_GEOGFROMTEXT(poligono) poligono, SAFE_CAST(fracao_ideal AS FLOAT64) fracao_ideal, SAFE_CAST(area_terreno AS FLOAT64) area_terreno, -SAFE_CAST(area_construida AS FLOAT64) area_construida, -FROM basedosdados-dev.br_mg_belohorizonte_smfa_iptu_staging.iptu AS t) -SELECT * FROM iptu - -{% if is_incremental() %} - -WHERE ano > (SELECT max(ano) FROM {{ this }}) and mes > (SELECT max(mes) FROM {{ this }}) - -{% endif %} \ No newline at end of file +SAFE_CAST(area_construida AS FLOAT64) area_construida +FROM basedosdados-dev.br_mg_belohorizonte_smfa_iptu_staging.iptu AS t +-- {% if is_incremental() %} +-- WHERE CONCAT(ano,mes) > (SELECT MAX(CONCAT(ano,mes)) FROM {{ this }} ) +-- {% endif %} \ No newline at end of file diff --git a/models/br_mg_belohorizonte_smfa_iptu/schema.yml b/models/br_mg_belohorizonte_smfa_iptu/schema.yml index f2192020..ac79e009 100644 --- a/models/br_mg_belohorizonte_smfa_iptu/schema.yml +++ b/models/br_mg_belohorizonte_smfa_iptu/schema.yml @@ -1,9 +1,13 @@ version: 2 models: - - name: br_mg_belohorizonte_smfa_iptu_iptu + - name: br_mg_belohorizonte_smfa_iptu__iptu description: Dados referente ao cadastro do IPTU na cidade de Belo Horizonte columns: + - name: ano + description: Ano + - name: mes + description: Mês - name: indice_cadastral description: Os imóveis, para inscrição no Cadastro Imobiliário, foram codificados através de sua associação a um código alfanumérico denominado índice cadastral, composto de 15 dígitos. - name: lote @@ -51,4 +55,18 @@ models: - name: area_terreno description: Área do terreno - name: area_construida - description: Área construida \ No newline at end of file + description: Área construida + + - name: br_mg_belohorizonte_smfa_iptu__iptu_dicionario + description: "Dicionário de dados da tabela de IPTU da cidade de Belo Horizonte" + columns: + - name: id_coluna + description: ID da coluna + - name: nome_coluna + description: Nome da coluna + - name: chave + description: Chave + - name: cobertura_temporal + description: Cobertura temporal + - name: valor + description: Valor \ No newline at end of file