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

Staging/add alvaras db #26

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
dfa7184
feat: add alvaras pipeline
PedroSiqueira1 Oct 4, 2024
6df61e5
Dummy commit
PedroSiqueira1 Oct 4, 2024
326db8a
fix: add flow to init
PedroSiqueira1 Oct 4, 2024
cdbbde6
fix: change host
PedroSiqueira1 Oct 8, 2024
bfd8756
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
7e42c52
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Oct 8, 2024
4d549a8
fix: Add flow to init
PedroSiqueira1 Oct 8, 2024
5580386
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
e39fd16
fix: change import alvaras
PedroSiqueira1 Oct 8, 2024
a0a2d83
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
de33d84
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Oct 8, 2024
beb7ced
fix: change import flows
PedroSiqueira1 Oct 8, 2024
9b85edc
fix: Change default parameter to use infisical and not vault
PedroSiqueira1 Oct 8, 2024
3ea347e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
01a559e
fix: Add / before path
PedroSiqueira1 Oct 8, 2024
8eba84a
Merge branch 'staging/add_alvaras_db' of https://github.com/prefeitur…
PedroSiqueira1 Oct 8, 2024
2335290
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
b95bfbb
feat: add dim query
PedroSiqueira1 Oct 8, 2024
1baca3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
5f2dcac
fix: Change to SQL Server
PedroSiqueira1 Oct 8, 2024
04145ff
fix: Change host
PedroSiqueira1 Oct 8, 2024
82e7d3c
fix: change host again
PedroSiqueira1 Oct 8, 2024
29b2bc8
fix: try new host
PedroSiqueira1 Oct 9, 2024
25e6703
fix: change host to ip
PedroSiqueira1 Oct 9, 2024
4795189
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Oct 9, 2024
6e21759
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Oct 10, 2024
1b0a9d8
fix: Add DDL and change credentials
PedroSiqueira1 Oct 10, 2024
5a02021
fix: change query
PedroSiqueira1 Oct 10, 2024
236c9de
fix: add ; after query
PedroSiqueira1 Oct 10, 2024
c62a479
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Oct 10, 2024
d84194c
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Oct 11, 2024
d43075e
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Oct 11, 2024
62b86ed
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Oct 11, 2024
e3207e2
fix: Add cast to flow
PedroSiqueira1 Oct 14, 2024
26c5437
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2024
064ca4c
fix: change float type
PedroSiqueira1 Oct 15, 2024
ff850dd
feat: Add more tables
PedroSiqueira1 Oct 15, 2024
1165fe7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 15, 2024
69a8eb5
fix: Remove casts and add fact tabkes
PedroSiqueira1 Oct 15, 2024
1aa51a5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 15, 2024
e820589
feat: add models
PedroSiqueira1 Oct 15, 2024
d46a06e
fix: Change folder name
PedroSiqueira1 Oct 15, 2024
feaf43b
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Oct 30, 2024
2a73a89
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Nov 1, 2024
7e52b60
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Nov 4, 2024
007726b
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Nov 4, 2024
665b514
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Nov 5, 2024
fbd6bd5
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Nov 6, 2024
5307701
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Nov 10, 2024
52b0a5c
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Nov 14, 2024
7a5277e
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Nov 26, 2024
2a6a2b1
Merge branch 'main' into staging/add_alvaras_db
mergify[bot] Dec 4, 2024
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
1 change: 1 addition & 0 deletions pipelines/alvaras/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pipelines.alvaras.dump_db.flows import * # noqa
50 changes: 50 additions & 0 deletions pipelines/alvaras/dump_db/flows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Database dumping flows for alvaras.
"""

from copy import deepcopy

from prefect.run_configs import KubernetesRun
from prefect.storage import GCS
from prefeitura_rio.pipelines_templates.dump_db.flows import flow as dump_sql_flow
from prefeitura_rio.pipelines_utils.prefect import set_default_parameters
from prefeitura_rio.pipelines_utils.state_handlers import (
handler_initialize_sentry,
handler_inject_bd_credentials,
)

from pipelines.alvaras.dump_db.schedules import (
alvaras_infra_daily_update_schedule,
)
from pipelines.constants import constants

rj_iplanrio_alvaras_flow = deepcopy(dump_sql_flow)
rj_iplanrio_alvaras_flow.state_handlers = [
handler_inject_bd_credentials,
handler_initialize_sentry,
]
rj_iplanrio_alvaras_flow.name = "IPLANRIO: Alvaras - Ingerir tabelas de banco SQL"
rj_iplanrio_alvaras_flow.storage = GCS(constants.GCS_FLOWS_BUCKET.value)

rj_iplanrio_alvaras_flow.run_config = KubernetesRun(
image=constants.DOCKER_IMAGE.value,
labels=[
constants.RJ_IPLANRIO_AGENT_LABEL.value, # label do agente
],
)

alvaras_default_parameters = {
"db_database": "DW_BI_ALVARAS",
"db_host": "10.70.15.11",
"db_port": "1433",
"db_type": "sql_server",
"dataset_id": "alvaras",
"infisical_secret_path": "/db-alvaras",
}

rj_iplanrio_alvaras_flow = set_default_parameters(
rj_iplanrio_alvaras_flow,
default_parameters=alvaras_default_parameters,
)

rj_iplanrio_alvaras_flow.schedule = alvaras_infra_daily_update_schedule
249 changes: 249 additions & 0 deletions pipelines/alvaras/dump_db/schedules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
"""
Schedules for the database dump pipeline.
"""

from datetime import datetime, timedelta

import pytz
from prefect.schedules import Schedule
from prefeitura_rio.pipelines_utils.io import untuple_clocks as untuple
from prefeitura_rio.pipelines_utils.prefect import generate_dump_db_schedules

from pipelines.constants import constants

#####################################
#
# Alvaras Schedules
#
#####################################

_alvaras_infra_query = {
"fact_fatoalvaras": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_Alvara,
Quantidade,
ID_AtvProcesso,
ID_CAE, ID_CNAE,
ID_DiaDeferimento,
ID_DiaSolicitacao,
ID_DiaTaxaPagamen,
ID_Direcionamento,
ID_TipoContribuint,
ID_TipoSolicitacao
FROM DW_BI_ALVARAS.dbo.FACT_FatoAlvaras;
""",
},
"fact_fatocp": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_AtvProcesso,
Quantidade_cp,
ID_CAE,
ID_CNAE,
ID_Consulta,
ID_DiaInicial,
ID_Direcionamento,
ID_TipoContribuint,
ID_TipoSolicitacao
FROM DW_BI_ALVARAS.dbo.FACT_FatoCP;
""",
},
"fact_fatodatacarga": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
DataCarga
FROM DW_BI_ALVARAS.dbo.FACT_FatoDataCarga;
""",
},
"tab_alvara": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_Alvara,
DSC_Alvara,
DSC_Endereco,
DSC_Bairro,
DSC_Zoneamento,
DSC_IRLF,
DSC_TipoAnalise,
DSC_TempoRespDia,
DSC_StatusIntermediario,
DSC_StatusCPL,
DSC_TempoRespMinuto,
DSC_TipoAlvara,
DSC_TaxaOriginal,
DSC_TaxaMulta,
DSC_TaxaMora,
DSC_TaxaTotal,
DSC_IsentoTaxa,
DSC_Numero,
DSC_AlvaraLiberado
FROM DW_BI_ALVARAS.dbo.TAB_ALVARA;
""",
},
"tab_atvprocesso": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_AtvProcesso,
DSC_AtvProcesso,
DSC_RespAtividade,
DSC_RefAtividade
FROM DW_BI_ALVARAS.dbo.TAB_AtvProcesso;
""",
},
"tab_cae": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_CAE,
DSC_CAE,
ID_TipoAtividade,
DSC_TipoAtividade
FROM DW_BI_ALVARAS.dbo.TAB_CAE;
""",
},
"tab_cnae": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_CNAE,
DSC_CNAE
FROM DW_BI_ALVARAS.dbo.TAB_CNAE;
""",
},
"tab_cnae_tmp": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_CNAE,
DSC_CNAE
FROM DW_BI_ALVARAS.dbo.TAB_CNAE_TMP;
""",
},
"tab_consulta": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_Consulta,
DSC_Consulta,
DSC_Endereco_cp,
DSC_Bairro_cp,
DSC_Zoneamento_cp,
DSC_CodeConsulta,
DSC_IRLF_cp,
DSC_StatusCPL_cp,
DSC_TipoAnalise_cp,
DSC_Status_cp
FROM DW_BI_ALVARAS.dbo.TAB_Consulta;
""",
},
"tab_direcionamento": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_Direcionamento,
DSC_Direcionamento
FROM DW_BI_ALVARAS.dbo.TAB_Direcionamento;
""",
},
"tab_tipocontribuinte_tipocontribuint": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_TipoContribuint,
DSC_TipoContribuint
FROM DW_BI_ALVARAS.dbo.TAB_TipoContribuinte_TipoContribuint;
""",
},
"tab_tiposolicitacao": {
"biglake_table": True,
"materialize_after_dump": True,
"materialization_mode": "prod",
"materialize_to_datario": False,
"dump_to_gcs": False,
"dump_mode": "overwrite",
"execute_query": """
SELECT
ID_TipoSolicitacao,
DSC_TipoSolicitacao
FROM DW_BI_ALVARAS.dbo.TAB_TipoSolicitacao;
""",
},
}

alvaras_infra_clocks = generate_dump_db_schedules(
interval=timedelta(days=1),
start_date=datetime(2022, 3, 21, 2, 0, tzinfo=pytz.timezone("America/Sao_Paulo")),
labels=[
constants.RJ_IPLANRIO_AGENT_LABEL.value,
],
db_database="DW_BI_ALVARAS",
db_host="10.70.15.11",
db_port="1433",
db_type="sql_server",
dataset_id="alvaras",
infisical_secret_path="/db-alvaras",
table_parameters=_alvaras_infra_query,
)

alvaras_infra_daily_update_schedule = Schedule(clocks=untuple(alvaras_infra_clocks))
1 change: 1 addition & 0 deletions pipelines/flows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Imports all flows for every project so we can register all of them."""

from pipelines.alvaras import *
from pipelines.painel_obras import *
from pipelines.processorio import *
from pipelines.sici import *
Expand Down
7 changes: 4 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions queries/models/alvaras/fact_fatoalvaras.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SELECT
SAFE_CAST(ID_Alvara AS STRING) AS ID_Alvara,
SAFE_CAST(Quantidade AS FLOAT64) AS Quantidade,
SAFE_CAST(ID_AtvProcesso AS STRING) AS ID_AtvProcesso,
SAFE_CAST(ID_CAE AS STRING) AS ID_CAE,
SAFE_CAST(ID_CNAE AS STRING) AS ID_CNAE,
SAFE_CAST(ID_DiaDeferimento AS STRING) AS ID_DiaDeferimento,
SAFE_CAST(ID_DiaSolicitacao AS STRING) AS ID_DiaSolicitacao,
SAFE_CAST(ID_DiaTaxaPagamen AS STRING) AS ID_DiaTaxaPagamen,
SAFE_CAST(ID_Direcionamento AS STRING) AS ID_Direcionamento,
SAFE_CAST(ID_TipoContribuint AS STRING) AS ID_TipoContribuint,
SAFE_CAST(ID_TipoSolicitacao AS STRING) AS ID_TipoSolicitacao

FROM `rj-iplanrio.alvaras_staging.fact_fatoalvaras`
12 changes: 12 additions & 0 deletions queries/models/alvaras/fact_fatocp.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SELECT
SAFE_CAST(ID_AtvProcesso AS STRING) AS ID_AtvProcesso,
SAFE_CAST(Quantidade_cp AS FLOAT64) AS Quantidade_cp,
SAFE_CAST(ID_CAE AS STRING) AS ID_CAE,
SAFE_CAST(ID_CNAE AS STRING) AS ID_CNAE,
SAFE_CAST(ID_Consulta AS STRING) AS ID_Consulta,
SAFE_CAST(ID_DiaInicial AS STRING) AS ID_DiaInicial,
SAFE_CAST(ID_Direcionamento AS STRING) AS ID_Direcionamento,
SAFE_CAST(ID_TipoContribuint AS STRING) AS ID_TipoContribuint,
SAFE_CAST(ID_TipoSolicitacao AS STRING) AS ID_TipoSolicitacao

FROM `rj-iplanrio.alvaras_staging.fact_fatocp`
22 changes: 22 additions & 0 deletions queries/models/alvaras/tab_alvara.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
SELECT
SAFE_CAST(ID_Alvara AS STRING) AS ID_Alvara,
SAFE_CAST(DSC_Alvara AS STRING) AS DSC_Alvara,
SAFE_CAST(DSC_Endereco AS STRING) AS DSC_Endereco,
SAFE_CAST(DSC_Bairro AS STRING) AS DSC_Bairro,
SAFE_CAST(DSC_Zoneamento AS STRING) AS DSC_Zoneamento,
SAFE_CAST(DSC_IRLF AS STRING) AS DSC_IRLF,
SAFE_CAST(DSC_TipoAnalise AS STRING) AS DSC_TipoAnalise,
SAFE_CAST(DSC_TempoRespDia AS FLOAT64) AS DSC_TempoRespDia,
SAFE_CAST(DSC_StatusIntermediario AS STRING) AS DSC_StatusIntermediario,
SAFE_CAST(DSC_StatusCPL AS STRING) AS DSC_StatusCPL,
SAFE_CAST(DSC_TempoRespMinuto AS FLOAT64) AS DSC_TempoRespMinuto,
SAFE_CAST(DSC_TipoAlvara AS STRING) AS DSC_TipoAlvara,
SAFE_CAST(DSC_TaxaOriginal AS FLOAT64) AS DSC_TaxaOriginal,
SAFE_CAST(DSC_TaxaMulta AS FLOAT64) AS DSC_TaxaMulta,
SAFE_CAST(DSC_TaxaMora AS FLOAT64) AS DSC_TaxaMora,
SAFE_CAST(DSC_TaxaTotal AS FLOAT64) AS DSC_TaxaTotal,
SAFE_CAST(DSC_IsentoTaxa AS STRING) AS DSC_IsentoTaxa,
SAFE_CAST(DSC_Numero AS FLOAT64) AS DSC_Numero,
SAFE_CAST(DSC_AlvaraLiberado AS STRING) AS DSC_AlvaraLiberado

FROM `rj-iplanrio.alvaras_staging.tab_alvara`
7 changes: 7 additions & 0 deletions queries/models/alvaras/tab_atvprocesso.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT
SAFE_CAST(ID_AtvProcesso AS STRING) AS ID_AtvProcesso,
SAFE_CAST(DSC_AtvProcesso AS STRING) AS DSC_AtvProcesso,
SAFE_CAST(DSC_RespAtividade AS STRING) AS DSC_RespAtividade,
SAFE_CAST(DSC_RefAtividade AS STRING) AS DSC_RefAtividade

FROM `rj-iplanrio.alvaras_staging.tab_atvprocesso`
Loading
Loading