Skip to content

feat(ontology): import Knowledge Catalog (Dataplex) Business Glossaries via gm import-dataplex-glossary #612

Backlog

Description

@seoeunbae

Summary

Add a gm import-dataplex-glossary command to bigquery_ontology (backed by an optional bigquery-agent-analytics[dataplex] extra) that imports a Google Cloud Knowledge Catalog (formerly Dataplex Universal Catalog) Business Glossary via the GA dataplex.googleapis.com v1 API directly into a validated, SKOS-aligned ontology.yaml.

Once imported, the generated ontology plugs directly into gm validate, gm compile --emit-concept-index, and OntologyRuntime / LabelSynonymResolver without requiring teams to maintain separate OWL/Turtle files.

Motivation

Today gm provides validate, compile, scaffold, and import-owl, where import-owl reads local RDF/Turtle or RDF/XML files. In practice, many BigQuery and ADK teams already govern their enterprise domain vocabulary in Knowledge Catalog Business Glossaries (Glossary → GlossaryCategory → GlossaryTerm, plus synonym / related / definition EntryLinks).

With PR #92 (gm compile --emit-concept-index), Issue #58 (OntologyRuntime + LabelSynonymResolver), and PR #579 (OntologyRuntime SKOS traversal and skos:topConceptOf parity), the downstream taxonomy and entity-resolution surface is already in place. Adding a read-only Dataplex Business Glossary importer bridges enterprise glossaries straight into BigQuery concept indexes and trace entity resolution.

(Naming note: using dataplex for the CLI subcommand, optional extra, module, and provenance annotation namespace aligns with Google Cloud's GA API dataplex.googleapis.com, IAM roles roles/dataplex.catalogViewer, and Python client google-cloud-dataplex.)

Proposed CLI & Behavior

gm import-dataplex-glossary \
  projects/<project>/locations/<location>/glossaries/<glossary_id> \
  [--ontology-name <name>] \
  [--include-links] \
  [--include-definitions] \
  [--max-links-per-term 100] \
  [-o ontology.yaml] \
  [--json]

Mapping to bigquery_ontology / OntologyRuntime

All emitted entities are abstract: true (matching the SKOS-only output of gm import-owl, which already compiles cleanly with gm compile --emit-concept-index):

Dataplex Business Glossary Resource (dataplex.googleapis.com/v1) Emitted ontology.yaml Downstream concept_index / OntologyRuntime
Glossary Root ontology, description, annotations["dataplex:glossary"], annotations["dataplex:uid"] Concept scheme identifier
GlossaryCategory / GlossaryTerm Abstract Entity (abstract: true, description) Always included in concept_index
display_name (non-blank) annotations["skos:prefLabel"] label_kind="pref" (outranks synonym)
Resource ID (category_id / term_id) annotations["skos:notation"] label_kind="notation" + lookup_by_notation()
parent == glossary.name skos:topConceptOf + skos:inScheme schemes_for() / in_scheme() (PR #579 parity)
parent == <category.name> skos:inScheme + abstract skos_broader relationship broader() / narrower() traversal
entryLinkTypes/synonym (intra-glossary, with --include-links) Mutual skos:altLabel + abstract skos_exactMatch relationship Resolvable via LabelSynonymResolver; aligns with #140
entryLinkTypes/related (intra-glossary, with --include-links) Deduplicated abstract skos_related relationship Symmetric related() traversal
entryLinkTypes/definition (with --include-definitions) annotations["dataplex:defined_assets"] Preserves linked BigQuery table/column references
Cross-glossary links, orphan parents, and sanitized identifier renames Preserved as annotations (skos:exactMatch / skos:relatedMatch) + reported in stderr summary Exact parity with import-owl's drop-summary contract

Dependencies, IAM, and Safety

  • Optional dependency: Add dataplex = ["google-cloud-dataplex>=2.13.0"] to pyproject.toml, lazy-imported inside src/bigquery_ontology/dataplex_glossary_importer.py (mirrors owl = ["rdflib>=7.0"]; missing extra exits cleanly with code 2 and cli-missing-dependency).
  • Read-only IAM: Requires only roles/dataplex.catalogViewer (no writes to Knowledge Catalog).
  • Bounded RPCs: CatalogServiceClient.lookup_entry_links is opt-in (--include-links / --include-definitions) and paginated with --max-links-per-term (respecting the API's page_size <= 10 limit) to avoid unexpected N+1 latency on large glossaries.
  • Deterministic output: Entities, relationships, and annotations are deterministically sorted so repeated imports produce byte-identical YAML and stable compile_fingerprint values.
  • Hermetic tests: All unit, CLI, validation, determinism, and OntologyRuntime / concept_index parity tests run offline against fake client protocols (no GCP credentials required in CI).

Non-Goals

Activity

  1. caohy1988 commented on Nov 26, 2026

    @caohy1988
    Collaborator

    Thanks for the detailed write-up, and for following up on #579. A read-only glossary importer fits well next to gm import-owl, and the mapping you describe works with what's on main today: an ontology in that shape (abstract entities with skos:prefLabel / skos:notation / skos:inScheme / skos:topConceptOf annotations plus abstract broader/related relationships) validates, compiles, and broader, narrower, related, schemes_for and in_scheme behave the way the issue expects. I'd treat it as a welcome enhancement rather than anything urgent.

    A few details need adjusting before it turns into a PR:

    • CatalogServiceClient.lookup_entry_links first shipped in google-cloud-dataplex 2.17.0, so >=2.13.0 is too low for the link flags. 2.12.0+ is enough for the glossary, category and term reads.
    • The YAML won't plug into gm compile or OntologyRuntime on its own, since both take a binding (and --emit-concept-index needs a destination table). An entity-less binding does work, but the output then starts with a CREATE PROPERTY GRAPH that has no node tables. That looks like a gap on our side, but the issue and docs should show the actual supported path from a small nested glossary to usable index rows.
    • import-owl doesn't sanitize identifiers (name collisions are an error) and only emits hierarchy edges whose endpoints it knows, so the sanitize/rename and orphan-parent reporting would be new behavior rather than parity.

    Two open questions:

    1. What is each entity name derived from, what's the sanitizing rule, and how are collisions handled, given categories and terms have separate ID spaces? Building names from the full resource identity, keeping the raw leaf ID as the notation, and testing a category and term that normalize to the same name would settle this.
    2. Link lookups run per term, return at most 10 per page, are quota-limited and location-scoped, and can redact targets the caller can't read even with catalog viewer access. How will the importer report a truncated, failed or redacted lookup instead of writing a file that looks complete? A silent --max-links-per-term cap would also undercut the byte-identical output goal.

    Suggested direction: start with a focused PR covering the glossary, categories, terms, labels and hierarchy, with the mapping as a pure function separate from the API calls and fake-client tests that shuffle and repeat pages to prove output and fingerprints stay stable. Links and definition assets can follow as a separate change. Happy to review it.

  2. seoeunbae commented on Nov 26, 2026

    @seoeunbae
    ContributorAuthor

    Thanks @caohy1988, this was very helpful. The first PR is up: #613. It covers the glossary, categories, terms, labels and hierarchy, with the mapping as a pure function (map_dataplex_glossary) separate from the API wrapper, and tests that shuffle and repeat pages and compare the YAML and compile_fingerprint. It needs only google-cloud-dataplex>=2.12.0. The user manual walks a small nested glossary through to concept-index rows (companion binding, --concept-index-table, and the bare CREATE PROPERTY GRAPH header), and the docs say plainly that sanitizing, renaming and orphan-parent reporting are new behavior compared with import-owl.

    On your two questions:

    1. Entity names are the kind plus the resource ID: category_<id> or term_<id>, with every character outside [A-Za-z0-9_] replaced by _. Within one glossary that is the full resource identity, because records from another project, location or glossary are rejected. If two resources of the same kind still collide (terms/net-revenue and terms/net_revenue), both get a _<first 8 hex digits of sha256(raw ID)> suffix, so names do not depend on API order. The raw leaf ID stays in skos:notation and the resource name in dataplex:resource. A category and a term that normalize alike are covered by a test.
    2. Links are not in this PR, so nothing can be silently truncated here. The follow-up will report truncated, failed and redacted lookups explicitly, and will not add a silent per-term cap, since that would break byte-identical output.

    One thing to confirm: I read "labels" as the SKOS labels (display name to skos:prefLabel, resource ID to skos:notation). The Dataplex resource labels key/value map is not imported. Tell me if you want it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions