You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ossie.apache.org by "jbonofre (via GitHub)" <gi...@apache.org> on 2026/09/12 05:40:30 UTC
Re: [PR] feat(converters): add Ataccama ONE → OSI catalog importer [ossie]
jbonofre commented on code in PR #174:
URL: https://github.com/apache/ossie/pull/174#discussion_r3995265680
##########
converters/ataccama/tests/test_ataccama_to_osi.py:
##########
@@ -0,0 +1,326 @@
+"""Tests for the Ataccama -> OSI conversion (offline, using a recorded fixture).
+
+Fixture items: BANK_TRANSACTIONS (a warehouse table with terms, DATE columns, and
+rich DQ results) and aggregation (a derived output with no locations and a 0% DQ case).
+"""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+
+import pytest
+import yaml
+from jsonschema import Draft202012Validator
+
+from ataccama_osi.ataccama_to_osi import (
+ OSI_VERSION,
+ _dataset_dq,
+ _dataset_dq_warning,
+ _quality_summary,
+ ataccama_to_osi,
+ attribute_to_field,
+ build_source,
+ flatten_richtext,
+)
+from ataccama_osi.models import CatalogAttribute, CatalogItem, CatalogItemBundle, CatalogLocation
+
+FIXTURE = Path(__file__).parent / "fixtures" / "ataccama_bundles.json"
+SCHEMA = Path(__file__).parents[3] / "core-spec" / "osi-schema.json"
Review Comment:
This test loads `core-spec/osi-schema.json`, but this file was renamed to `ossie-schema.json`.
Could you please fix the name?
##########
converters/ataccama/pyproject.toml:
##########
@@ -0,0 +1,44 @@
+[project]
Review Comment:
The ASF header is missing.
##########
converters/ataccama/tests/test_ataccama_to_osi.py:
##########
@@ -0,0 +1,326 @@
+"""Tests for the Ataccama -> OSI conversion (offline, using a recorded fixture).
Review Comment:
The ASF header is missing here.
##########
converters/ataccama/pyproject.toml:
##########
@@ -0,0 +1,44 @@
+[project]
+name = "ataccama-osi"
+version = "0.2.0.dev0"
+description = "Importer from Ataccama ONE catalog metadata to the OSI semantic model"
+authors = [{name = "Ataccama", email = "support@ataccama.com"}]
+readme = "README.md"
+requires-python = ">=3.12"
+dependencies = [
+ "pyyaml>=6.0.1",
+ "requests>=2.31.0",
+]
+
+[project.scripts]
+ataccama-to-osi = "ataccama_osi.cli:main"
+
+[dependency-groups]
+dev = [
Review Comment:
`jsonschema` is imported unconditionally in `test_ataccama_to_osi.py` but isn't declared as a dependency here.
Following the README `uv sync --group dev && uv run pyest` fails at collection with `ModuleNotFoundError: No module named 'jsonschema'`.
Can you please add the appropriate dependency group?
##########
converters/ataccama/src/ataccama_osi/ataccama_to_osi.py:
##########
@@ -0,0 +1,416 @@
+"""Convert Ataccama ONE catalog metadata to an OSI semantic model.
+
+Scope: the caller supplies one or more catalog items (as :class:`CatalogItemBundle`s);
+each becomes an OSI dataset, and the collection becomes a single OSI semantic model.
+
+Mapping summary (see README for the full table and known limitations):
+ CatalogItem -> dataset (name, source, description, ai_context, custom_extensions)
+ CatalogAttribute -> field (name, ANSI_SQL identifier expression, dimension.is_time,
+ description, ai_context, custom_extensions)
+ Term / termAssignments -> ai_context.synonyms + ATACCAMA custom_extension
+"""
+
+from __future__ import annotations
+
+import json
+from typing import Any
+
+from ataccama_osi.models import CatalogAttribute, CatalogItem, CatalogItemBundle, Term
+
+OSI_VERSION = "0.2.0.dev0"
+VENDOR = "ATACCAMA"
+
+# Ataccama semantic data types that represent points in time.
+TIME_DATA_TYPES = {"DATE", "DATETIME", "TIMESTAMP", "TIME"}
+
+
+# --- helpers -------------------------------------------------------------
+
+
+def flatten_richtext(value: Any) -> str | None:
+ """Flatten an Ataccama description into plain text.
+
+ Descriptions arrive either as a plain string or as Slate rich-text JSON, e.g.
+ ``[{"type": "paragraph", "children": [{"text": "..."}]}]`` (sometimes as a JSON
+ string). Returns ``None`` when there is no usable text.
+ """
+ if value is None:
+ return None
+ if isinstance(value, str):
+ stripped = value.strip()
+ if not stripped:
+ return None
+ # Rich text is occasionally delivered as a JSON-encoded string.
+ if stripped[0] in "[{":
+ try:
+ return flatten_richtext(json.loads(stripped))
+ except (ValueError, TypeError):
+ return stripped
+ return stripped
+
+ def collect(node: Any, out: list[str]) -> None:
+ if isinstance(node, dict):
+ text = node.get("text")
+ if isinstance(text, str):
+ out.append(text)
+ for child in node.get("children", []) or []:
+ collect(child, out)
+ elif isinstance(node, list):
+ for child in node:
+ collect(child, out)
+
+ parts: list[str] = []
+ collect(value, parts)
+ text = "".join(parts).strip()
+ return text or None
+
+
+def _unique_name(desired: str, used: set[str], *, fallback: str) -> str:
+ """Return a name unique within ``used`` (OSI requires unique dataset/field names)."""
+ base = desired.strip() or fallback
+ candidate = base
+ n = 2
+ while candidate in used:
+ candidate = f"{base}_{n}"
+ n += 1
+ used.add(candidate)
+ return candidate
+
+
+def _sql_identifier(name: str) -> str:
+ """Quote a column name as an ANSI SQL identifier (names may contain spaces/punctuation)."""
+ escaped = name.replace('"', '""')
+ return f'"{escaped}"'
+
+
+def build_source(item: CatalogItem) -> str:
+ """Best-effort physical source reference.
+
+ The Catalog API does not expose ``database.schema.table``; it only gives a
+ folder-name hierarchy (``locations``, leaf-first) plus the item name. We build a
+ dotted namespace from the reversed locations followed by the item name. The
+ authoritative connection/source URNs are preserved in custom_extensions.
+ """
+ parts = [loc.name for loc in reversed(item.locations) if loc.name]
+ parts.append(item.name)
+ return ".".join(parts) if parts else item.name
+
+
+def _terms_ai_context(term_urns: list[str], terms: dict[str, Term]) -> dict[str, Any] | None:
+ """Build an ai_context object from assigned business terms."""
+ synonyms: list[str] = []
+ instructions: list[str] = []
+ for urn in term_urns:
+ term = terms.get(urn)
+ if not term:
+ continue
+ if term.name and term.name not in synonyms:
+ synonyms.append(term.name)
+ desc = flatten_richtext(term.description)
+ if desc:
+ instructions.append(f"{term.name}: {desc}" if term.name else desc)
+ ctx: dict[str, Any] = {}
+ if instructions:
+ ctx["instructions"] = " ".join(instructions)
+ if synonyms:
+ ctx["synonyms"] = synonyms
+ return ctx or None
+
+
+def _ataccama_extension(data: dict[str, Any]) -> dict[str, str]:
+ """Wrap Ataccama-specific metadata as an OSI custom_extension entry."""
+ return {"vendor_name": VENDOR, "data": json.dumps(data, sort_keys=True)}
+
+
+# --- data quality ---
+
+
+def _quality_summary(overall_quality: dict[str, Any] | None) -> dict[str, Any] | None:
+ """Turn an OverallQuality {passedCount, failedCount} into a compact summary.
+
+ ``pass_rate_pct`` is Ataccama's overall quality expressed as a percentage
+ (passed / (passed + failed)). The DQ API returns only counts, not a preformatted
+ percentage, so the converter formats it; the underlying counts are Ataccama's own.
+ """
+ if not overall_quality:
+ return None
+ passed = overall_quality.get("passedCount") or 0
+ failed = overall_quality.get("failedCount") or 0
+ total = passed + failed
+ summary: dict[str, Any] = {"passed": passed, "failed": failed}
+ if total:
+ summary["pass_rate_pct"] = round(passed / total * 100, 1)
+ return summary
+
+
+def _dataset_dq(dq_results: dict[str, Any] | None, threshold_pct: float | None = None) -> dict[str, Any] | None:
+ """Build the dataset-level DQ block from a raw DqResults payload.
+
+ ``threshold_pct`` is the monitor's configured overall pass/fail bar (from the
+ monitor config). When present alongside a pass rate, ``below_threshold`` records
+ whether the data is under that bar — the same pass/fail state shown in Ataccama.
+ """
+ if not dq_results:
+ return None
+ dq = _quality_summary(dq_results.get("overallQuality")) or {}
+
+ if threshold_pct is not None:
+ dq["threshold_pct"] = threshold_pct
+ if "pass_rate_pct" in dq:
+ dq["below_threshold"] = dq["pass_rate_pct"] < threshold_pct
Review Comment:
`below_threshold` compares the rounded `pass_rate_pct` against `threshold_pct` rather than the raw ratio, so results near a rounding boundary get misclassified.
Maybe we should compare the unrounded ratio instead, and only round for display?
##########
converters/ataccama/src/ataccama_osi/ataccama_to_osi.py:
##########
@@ -0,0 +1,416 @@
+"""Convert Ataccama ONE catalog metadata to an OSI semantic model.
Review Comment:
ASF header is missing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ossie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org