Skip to content

Follow-ups from #613 review (Dataplex glossary import paging) #617

Backlog

Description

@caohy1988

A few follow-ups from the review of #613 at 6ae0f61. None of them blocked the PR, but the first one is worth fixing soon.

1. A one-pass page collection can lose its first page. In dataplex_glossary_importer.py, the page reader treats a page collection as restartable whenever iter(pages) is not pages. A wrapper whose __iter__ yields from a stored stream passes that check but can only be walked once. The first page is consumed to classify the shape, then item iteration restarts on the same stream, so everything on page one is silently skipped and the import still succeeds. With two categories on separate pages, only the second one ends up in the YAML, and which one survives depends on page order. Since this drops concepts without any error, I'd prioritize it. A simple fix is to pick the item-or-page interface before consuming anything, or to process the buffered first page plus the rest of the same iterator.

Small synthetic repro:

from itertools import chain
from types import SimpleNamespace as NS

from bigquery_ontology import load_ontology_from_string
from bigquery_ontology.dataplex_glossary_importer import import_dataplex_glossary

G = "projects/demo-project/locations/us-central1/glossaries/retail"

class Pages:
    def __init__(self, batches):
        self.stream = iter(batches)
    def __iter__(self):
        yield from self.stream

class Listing:
    def __init__(self, batches):
        self.pages = Pages(batches)
    def __iter__(self):
        return chain.from_iterable(self.pages)

def categories(request):
    return Listing([[{"name": G + "/categories/" + n, "parent": G}]
                    for n in ("customer", "sales")])

client = NS(get_glossary=lambda request: {"name": G},
            list_glossary_categories=categories,
            list_glossary_terms=lambda request: [])
yaml_text, _ = import_dataplex_glossary(G, glossary_client=client)
print([e.name for e in load_ontology_from_string(yaml_text).entities])
# expected ['category_customer', 'category_sales'], got ['category_sales']

2. A later page marked with unreachable locations isn't checked on every path. When a reusable collection starts with a plain page, the reader goes straight to flattened items and never looks at a later page's unreachable_locations. On the single-use path it checks the page wrapper, but google.api_core.page_iterator.GRPCIterator keeps the service response (and its unreachable_locations) on Page.raw_page, so that isn't seen either. In both cases a listing where a later page says e.g. us-east1 was unreachable imports as a success. This only affects injected clients; the generated Dataplex pager exposes the response fields directly and is handled correctly. Moderately important since it lets a partial listing look complete. Checking every page, including raw_page when present, before yielding its items (for both the category and term calls) should cover it.

3. Minor: parser-level errors under --json are still plain text. Missing required arguments exit 2 with plain usage text even with --json. This is pre-existing and CLI-wide (other gm subcommands behave the same), and the docs now call it out, so it's low priority unless we want uniform machine-readable usage errors across the CLI.

Activity

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