Skip to content

data/br_rf_cnpj__socios_legado - #1799

Closed
luizavboas wants to merge 3 commits into
mainfrom
fix/br_rf_cnpj__socios_legado
Closed

luizavboas wants to merge 3 commits into
mainfrom
fix/br_rf_cnpj__socios_legado

Conversation

@luizavboas

@luizavboas luizavboas commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added scheduled data pipelines for Brazilian CNPJ dictionary, company, partner, simplified-registration, and establishment datasets.
    • Increased concurrent download capacity to improve data acquisition performance.
  • Updates

    • Updated company data sourcing and snapshot selection for more consistent reference-date handling.
    • Standardized date formatting across CNPJ pipeline outputs.
  • Bug Fixes

    • Resolved static-analysis warnings in Harvard CBDB data-processing tools without changing runtime behavior.

…râmetro de download_max_parallel de 5 para 15 (era o que estava sendo manualmente inserido nas runs), mudança no padrão de datas no registro de metadados, mudança na query de br_bd_diretorios_brasil__empresa para usar br_rf_cnpj ao invés de br_me_cnpj. Também correções em arquivos com erros do Pyrefly
@luizavboas luizavboas self-assigned this Aug 12, 2026
@luizavboas luizavboas added the table-approve [PR] Dispara Table Approve no merge label Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR migrates the empresa model to RF CNPJ sources, standardizes crawler date formats, increases download concurrency, adds scheduled Prefect 3 flows, and suppresses Pyrefly diagnostics in Harvard CBDB tooling.

Changes

RF CNPJ pipeline

Layer / File(s) Summary
RF CNPJ source migration
models/br_bd_diretorios_brasil/...
The empresa model now reads RF CNPJ tables and uses data_referencia for snapshot selection and company data.
Crawler date and download updates
pipelines/crawler/rf_cnpj/flows.py, pipelines/crawler/rf_cnpj/tasks.py
Crawler date handling now uses YEAR_MONTH. Default download parallelism is 15.
Scheduled RF CNPJ deployments
pipelines/datasets/flows.py
Five Prefect 3 deployments now schedule RF CNPJ table flows and delegate execution to _run_rf_cnpj.

Diagnostic suppression updates

Layer / File(s) Summary
Harvard CBDB Pyrefly suppressions
models/us_harvard_cbdb/code/*
Pyrefly directives suppress missing-import, unknown-name, and assignment diagnostics without changing runtime behavior.
TSE diagnostics configuration closure
models/br_tse_eleicoes/code/python/diagnostics/tier2_overrides.json
The configuration object is closed without changing its values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: deploy-flow, check-metadata

Suggested reviewers: rdahis

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title relates to the CNPJ pipeline but lacks the required bracketed keyword and names only a legacy socios target despite broader changes. Rename the PR with a required keyword, such as [Data] or [Refactor], and summarize the broader br_rf_cnpj pipeline changes.
Description check ⚠️ Warning No pull request description was provided, so all required template sections and validation details are missing. Add the objective, technical changes, data and schema impact, performance, tests, risks, rollback plan, dependencies, and reviewer information.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/br_rf_cnpj__socios_legado

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@luizavboas luizavboas closed this Aug 12, 2026
@luizavboas
luizavboas deleted the fix/br_rf_cnpj__socios_legado branch August 12, 2026 20:26

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
pipelines/crawler/rf_cnpj/tasks.py (1)

57-57: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document download_max_parallel in main.

Add this parameter to the Google-style Args section. State that it limits
concurrent download chunks and defaults to 15.

As per coding guidelines, "**/*.py: Target Python 3.10, enforce Ruff with a
79-character line length, and add Google-Style type hints and docstrings to
functions."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pipelines/crawler/rf_cnpj/tasks.py` at line 57, Document the
download_max_parallel parameter in main’s Google-style Args section, stating
that it limits concurrent download chunks and defaults to 15; keep the
description within the project’s 79-character line limit.

Source: Coding guidelines

pipelines/datasets/flows.py (1)

10-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add type and API documentation for the flow factory.

Add a return annotation and a Google-style docstring to _rf_cnpj_flow. Add a
Google-style docstring to the generated _flow. Document the table, schedule,
and forwarded execution parameters.

As per coding guidelines, "**/*.py: Target Python 3.10, enforce Ruff with a
79-character line length, and add Google-Style type hints and docstrings to
functions."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pipelines/datasets/flows.py` around lines 10 - 29, Update the _rf_cnpj_flow
factory with an explicit return annotation and Google-style docstring describing
the table identifier, schedule, and returned flow. Add a Google-style docstring
to the generated _flow documenting dataset/table settings and all forwarded
execution parameters, including materialization, dbt aliasing, metadata updates,
target, force_run, chunking, folder date, download limits, retries, parallelism,
and timeout; keep formatting within the 79-character limit.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@models/br_bd_diretorios_brasil/br_bd_diretorios_brasil__empresa.sql`:
- Around line 161-162: Update the JOIN condition in the empresa query to match
the status dictionary key `t.chave` against `a.situacao_cadastral` instead of
`a.identificador_matriz_filial`.

---

Nitpick comments:
In `@pipelines/crawler/rf_cnpj/tasks.py`:
- Line 57: Document the download_max_parallel parameter in main’s Google-style
Args section, stating that it limits concurrent download chunks and defaults to
15; keep the description within the project’s 79-character line limit.

In `@pipelines/datasets/flows.py`:
- Around line 10-29: Update the _rf_cnpj_flow factory with an explicit return
annotation and Google-style docstring describing the table identifier, schedule,
and returned flow. Add a Google-style docstring to the generated _flow
documenting dataset/table settings and all forwarded execution parameters,
including materialization, dbt aliasing, metadata updates, target, force_run,
chunking, folder date, download limits, retries, parallelism, and timeout; keep
formatting within the 79-character limit.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f038824-48ef-4785-b79f-189e15264f81

📥 Commits

Reviewing files that changed from the base of the PR and between 267fda2 and c41f8f2.

📒 Files selected for processing (12)
  • models/br_bd_diretorios_brasil/br_bd_diretorios_brasil__empresa.sql
  • models/br_rf_cnpj/br_rf_cnpj__socios_legado.sql
  • models/br_tse_eleicoes/code/python/diagnostics/tier2_overrides.json
  • models/us_harvard_cbdb/code/clean.py
  • models/us_harvard_cbdb/code/gen_architecture.py
  • models/us_harvard_cbdb/code/gen_dbt.py
  • models/us_harvard_cbdb/code/gen_metadata_payload.py
  • models/us_harvard_cbdb/code/schema_spec.py
  • models/us_harvard_cbdb/code/upload.py
  • pipelines/crawler/rf_cnpj/flows.py
  • pipelines/crawler/rf_cnpj/tasks.py
  • pipelines/datasets/flows.py

Comment on lines +161 to 162
`basedosdados.br_rf_cnpj.dicionario` t
on a.identificador_matriz_filial = t.chave

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Join the status dictionary with situacao_cadastral.

Line 162 joins t.chave to a.identificador_matriz_filial. This makes
situacao_cadastral depend on the matrix/branch code. Join
a.situacao_cadastral to t.chave instead.

Proposed fix
         inner join
             `basedosdados.br_rf_cnpj.dicionario` t
-            on a.identificador_matriz_filial = t.chave
+            on a.situacao_cadastral = t.chave
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`basedosdados.br_rf_cnpj.dicionario` t
on a.identificador_matriz_filial = t.chave
`basedosdados.br_rf_cnpj.dicionario` t
on a.situacao_cadastral = t.chave
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@models/br_bd_diretorios_brasil/br_bd_diretorios_brasil__empresa.sql` around
lines 161 - 162, Update the JOIN condition in the empresa query to match the
status dictionary key `t.chave` against `a.situacao_cadastral` instead of
`a.identificador_matriz_filial`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

table-approve [PR] Dispara Table Approve no merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant