quantilica-cli 0.21.2__tar.gz → 0.21.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/CHANGELOG.md +12 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/PKG-INFO +1 -1
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/pyproject.toml +1 -1
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/catalog.py +51 -10
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_catalog_cli.py +68 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/.githooks/pre-commit +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/.githooks/pre-push +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/.github/workflows/public-hygiene.yml +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/.github/workflows/publish.yml +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/.github/workflows/test.yml +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/.gitignore +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/LICENSE +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/README.md +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/__init__.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/cli.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/docs.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/health.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/lake.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/manifests.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/registry.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/sdk.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/sources.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/cli/ui.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/src/quantilica/py.typed +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/__init__.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/conftest.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/lake_build_fakes.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/lake_fixtures.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_catalog_registro.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_catalog_sigla.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_cli_apelidos.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_docs_cli.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_health.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_lake_cli.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_manifests.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_package_hygiene.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_registry_cli.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_sdk.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_sdk_backfill.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_sdk_force_probe.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_sdk_mes_string.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_sdk_onda_a2.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_sdk_sync_exit.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_sources.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_sources_registro.py +0 -0
- {quantilica_cli-0.21.2 → quantilica_cli-0.21.4}/tests/test_ui.py +0 -0
|
@@ -7,6 +7,18 @@ e este projeto adere ao [Semantic Versioning](https://semver.org/lang/pt-BR/).
|
|
|
7
7
|
|
|
8
8
|
## [Não lançado]
|
|
9
9
|
|
|
10
|
+
## [0.21.4] - 2026-11-14
|
|
11
|
+
|
|
12
|
+
### Alterado
|
|
13
|
+
|
|
14
|
+
- Lotes do `quantilica catalog sync` de até 90 MB (antes 4 MB): o portal 1.1.2 aceita 100 MiB na rota de sync. O lake atual volta a ir num envio só.
|
|
15
|
+
|
|
16
|
+
## [0.21.3] - 2026-11-13
|
|
17
|
+
|
|
18
|
+
### Corrigido
|
|
19
|
+
|
|
20
|
+
- `quantilica catalog sync` deixa fora do catálogo, com aviso, a coluna cujo nome o portal recusa (vazio, acima de 128 caracteres ou com caractere de controle) e tira o NUL dos valores da amostra (o jsonb não o aceita). No lake de 13/11/2026 eram 23 colunas de 20 datasets da ANP, ANAC e INEP, convertidas com delimitador ou codificação errados.
|
|
21
|
+
|
|
10
22
|
## [0.21.2] - 2026-11-13
|
|
11
23
|
|
|
12
24
|
### Corrigido
|
|
@@ -34,13 +34,32 @@ console = Console()
|
|
|
34
34
|
err_console = Console(stderr=True)
|
|
35
35
|
|
|
36
36
|
|
|
37
|
+
# Tamanho de catalog.column.nome no portal.
|
|
38
|
+
NOME_COLUNA_MAX = 128
|
|
39
|
+
_CONTROLE = re.compile(r"[\x00-\x1f\x7f]")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _motivo_nome_invalido(nome: str) -> str | None:
|
|
43
|
+
"""Por que o portal recusaria este nome de coluna (``None`` se aceita)."""
|
|
44
|
+
if not nome.strip():
|
|
45
|
+
return "sem nome"
|
|
46
|
+
if _CONTROLE.search(nome):
|
|
47
|
+
return "caractere de controle"
|
|
48
|
+
if len(nome.strip()) > NOME_COLUNA_MAX:
|
|
49
|
+
return f"mais de {NOME_COLUNA_MAX} caracteres"
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
|
|
37
53
|
def _sanitize_value(val: Any) -> Any:
|
|
38
54
|
"""Converte valores Python/Arrow em tipos primitivos compatíveis com JSON."""
|
|
39
55
|
if val is None:
|
|
40
56
|
return None
|
|
41
57
|
if isinstance(val, bool):
|
|
42
58
|
return val
|
|
43
|
-
if isinstance(val,
|
|
59
|
+
if isinstance(val, str):
|
|
60
|
+
# O jsonb do Postgres não aceita \u0000.
|
|
61
|
+
return val.replace("\x00", "")
|
|
62
|
+
if isinstance(val, (int, float)):
|
|
44
63
|
return val
|
|
45
64
|
if isinstance(val, decimal.Decimal):
|
|
46
65
|
return float(val)
|
|
@@ -48,11 +67,11 @@ def _sanitize_value(val: Any) -> Any:
|
|
|
48
67
|
return val.isoformat()
|
|
49
68
|
if isinstance(val, bytes):
|
|
50
69
|
try:
|
|
51
|
-
return val.decode("utf-8")
|
|
70
|
+
return val.decode("utf-8").replace("\x00", "")
|
|
52
71
|
except UnicodeDecodeError:
|
|
53
72
|
return val.hex()
|
|
54
73
|
if isinstance(val, dict):
|
|
55
|
-
return {str(k): _sanitize_value(v) for k, v in val.items()}
|
|
74
|
+
return {str(k).replace("\x00", ""): _sanitize_value(v) for k, v in val.items()}
|
|
56
75
|
if isinstance(val, (list, tuple, set)):
|
|
57
76
|
return [_sanitize_value(x) for x in val]
|
|
58
77
|
if hasattr(val, "as_py"):
|
|
@@ -280,9 +299,31 @@ def _extract_dataset_metadata(
|
|
|
280
299
|
|
|
281
300
|
pf = pq.ParquetFile(first_parquet)
|
|
282
301
|
schema = pf.schema_arrow
|
|
283
|
-
|
|
302
|
+
# Nome de coluna que o portal não aceita (vazio, acima de 128 caracteres
|
|
303
|
+
# ou com caractere de controle) fica fora do catálogo, do esquema e da
|
|
304
|
+
# amostra, com aviso. No lake de 13/11/2026: cabeçalho com delimitador
|
|
305
|
+
# sobrando no fim (nome vazio), CSV lido com o delimitador errado (o
|
|
306
|
+
# cabeçalho inteiro vira um nome) e UTF-16 lido como latin-1 (NUL).
|
|
307
|
+
invalidos: dict[str, str] = {}
|
|
308
|
+
for f in schema:
|
|
309
|
+
motivo = _motivo_nome_invalido(f.name)
|
|
310
|
+
if motivo:
|
|
311
|
+
invalidos[f.name] = motivo
|
|
312
|
+
if invalidos:
|
|
313
|
+
logger.warning(
|
|
314
|
+
"%s: %d coluna(s) fora do catálogo por nome inválido (%s); "
|
|
315
|
+
"reveja a conversão do dataset.",
|
|
316
|
+
full_id,
|
|
317
|
+
len(invalidos),
|
|
318
|
+
", ".join(sorted(set(invalidos.values()))),
|
|
319
|
+
)
|
|
320
|
+
schema_arrow_json = {
|
|
321
|
+
f.name: str(f.type) for f in schema if f.name not in invalidos
|
|
322
|
+
}
|
|
284
323
|
|
|
285
324
|
for field in schema:
|
|
325
|
+
if field.name in invalidos:
|
|
326
|
+
continue
|
|
286
327
|
if field.name not in partition_keys:
|
|
287
328
|
columns.append(
|
|
288
329
|
{
|
|
@@ -304,7 +345,7 @@ def _extract_dataset_metadata(
|
|
|
304
345
|
table = table.slice(0, sample_size)
|
|
305
346
|
# Serialização segura para JSON
|
|
306
347
|
pydict = table.to_pydict()
|
|
307
|
-
keys =
|
|
348
|
+
keys = [k for k in pydict if k not in invalidos]
|
|
308
349
|
for idx in range(table.num_rows):
|
|
309
350
|
row: dict[str, Any] = {}
|
|
310
351
|
for k in keys:
|
|
@@ -493,11 +534,11 @@ def send_catalog_payload(
|
|
|
493
534
|
raise RuntimeError(f"Erro de conexão com o portal em {url}: {exc}") from exc
|
|
494
535
|
|
|
495
536
|
|
|
496
|
-
# O portal
|
|
497
|
-
#
|
|
498
|
-
#
|
|
499
|
-
# do que veio nos anteriores.
|
|
500
|
-
LOTE_MAX_BYTES =
|
|
537
|
+
# O portal aceita até 100 MiB em /admin/catalog/sync (desde a 1.1.2; antes, 5 MiB)
|
|
538
|
+
# e o Cloudflare corta em 100 MB. Lotes de até 90 MB: o lake inteiro (8,5 MB em
|
|
539
|
+
# 13/11/2026) vai num lote só, e a divisão por fonte fica para quando crescer. O
|
|
540
|
+
# sync do portal é upsert: lotes não apagam nada do que veio nos anteriores.
|
|
541
|
+
LOTE_MAX_BYTES = 90_000_000
|
|
501
542
|
|
|
502
543
|
|
|
503
544
|
def _tamanho_json(obj: Any) -> int:
|
|
@@ -431,3 +431,71 @@ def test_sync_envia_em_lotes_e_soma_as_respostas(monkeypatch):
|
|
|
431
431
|
total = catalog_mod._somar_respostas(respostas)
|
|
432
432
|
assert total["counts"]["datasets"] == 9
|
|
433
433
|
assert total["lotes"] == len(lotes)
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def test_coluna_sem_nome_fica_fora_do_catalogo(tmp_path: Path) -> None:
|
|
437
|
+
"""Parquet com coluna de nome vazio (CSV com ';' sobrando) não quebra o sync."""
|
|
438
|
+
import pyarrow as pa
|
|
439
|
+
import pyarrow.parquet as pq
|
|
440
|
+
|
|
441
|
+
from quantilica.cli.catalog import extract_catalog_payload
|
|
442
|
+
|
|
443
|
+
dataset_dir = tmp_path / "anp" / "multas"
|
|
444
|
+
dataset_dir.mkdir(parents=True)
|
|
445
|
+
(dataset_dir / "_dataset.json").write_text(
|
|
446
|
+
json.dumps({"source_id": "anp", "dataset_id": "multas"}), encoding="utf-8"
|
|
447
|
+
)
|
|
448
|
+
tbl = pa.table({"auto": ["123"], "": [None]})
|
|
449
|
+
pq.write_table(tbl, dataset_dir / "part.parquet")
|
|
450
|
+
|
|
451
|
+
payload = extract_catalog_payload(tmp_path, sample_size=5)
|
|
452
|
+
nomes = [c["nome"] for c in payload["columns"]]
|
|
453
|
+
assert nomes == ["auto"]
|
|
454
|
+
amostra = payload["samples"][0]
|
|
455
|
+
assert all(k for linha in amostra["linhas_amostra"] for k in linha)
|
|
456
|
+
assert "" not in amostra["schema_arrow_json"]
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def test_coluna_com_nome_longo_fica_fora_do_catalogo(tmp_path: Path) -> None:
|
|
460
|
+
"""Cabeçalho inteiro virando nome de coluna (delimitador errado) não quebra o sync."""
|
|
461
|
+
import pyarrow as pa
|
|
462
|
+
import pyarrow.parquet as pq
|
|
463
|
+
|
|
464
|
+
from quantilica.cli.catalog import NOME_COLUNA_MAX, extract_catalog_payload
|
|
465
|
+
|
|
466
|
+
dataset_dir = tmp_path / "anp" / "producao-mar"
|
|
467
|
+
dataset_dir.mkdir(parents=True)
|
|
468
|
+
(dataset_dir / "_dataset.json").write_text(
|
|
469
|
+
json.dumps({"source_id": "anp", "dataset_id": "producao-mar"}), encoding="utf-8"
|
|
470
|
+
)
|
|
471
|
+
longo = ",".join(f"campo_{i}" for i in range(40))
|
|
472
|
+
assert len(longo) > NOME_COLUNA_MAX
|
|
473
|
+
pq.write_table(
|
|
474
|
+
pa.table({"ano": ["2026"], longo: ["a,b"]}), dataset_dir / "p.parquet"
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
payload = extract_catalog_payload(tmp_path, sample_size=5)
|
|
478
|
+
assert [c["nome"] for c in payload["columns"]] == ["ano"]
|
|
479
|
+
assert len(payload["datasets"]) == 1
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def test_nul_em_nome_e_amostra_nao_chega_ao_portal(tmp_path: Path) -> None:
|
|
483
|
+
"""UTF-16 lido como latin-1 deixa NUL nos nomes e valores; o Postgres recusa."""
|
|
484
|
+
import pyarrow as pa
|
|
485
|
+
import pyarrow.parquet as pq
|
|
486
|
+
|
|
487
|
+
from quantilica.cli.catalog import extract_catalog_payload
|
|
488
|
+
|
|
489
|
+
dataset_dir = tmp_path / "anp" / "comercializacao-gn"
|
|
490
|
+
dataset_dir.mkdir(parents=True)
|
|
491
|
+
(dataset_dir / "_dataset.json").write_text(
|
|
492
|
+
json.dumps({"source_id": "anp", "dataset_id": "comercializacao-gn"}),
|
|
493
|
+
encoding="utf-8",
|
|
494
|
+
)
|
|
495
|
+
tbl = pa.table({"\x00A\x00n\x00o\x00": ["1"], "uf": ["S\x00P"]})
|
|
496
|
+
pq.write_table(tbl, dataset_dir / "p.parquet")
|
|
497
|
+
|
|
498
|
+
payload = extract_catalog_payload(tmp_path, sample_size=5)
|
|
499
|
+
assert [c["nome"] for c in payload["columns"]] == ["uf"]
|
|
500
|
+
assert "\x00" not in json.dumps(payload["samples"]).replace("\\u0000", "\x00")
|
|
501
|
+
assert payload["samples"][0]["linhas_amostra"] == [{"uf": "SP"}]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|