yuqi1129 commented on code in PR #14239: URL: https://github.com/apache/gravitino/pull/14239#discussion_r4512464289
########## design-docs/glossary-design.md: ########## @@ -0,0 +1,812 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> + +# Design: Business Glossary + +| Version | Author | Date | Status | +| ------- | ------ | ---------- | ------ | +| 0.6 | Qi Yu | 2026-11-09 | Draft | + +## Background + +Gravitino knows where data lives: catalogs, schemas and tables. With Domains +(apache/gravitino#13867), it also knows the business area of the data. But it does not know what a +business word means. Words like "Active Customer" or "Net Revenue" are defined in wikis and BI +tools. Each user and each agent maps the word to tables and metrics in its own way. Nobody owns the +definition. + +A business glossary solves this. It is a managed list of **terms**. Each term has a definition, +synonyms, an owner and a status. Terms are grouped by domain and by a parent-child hierarchy. A term +is linked to the columns, tables and metrics behind it. An agent can look up a word from a question, +find the approved term, and follow its links to the data. + +The glossary is built in two steps. **Step 1** is this design: terms, relations, bindings, status, +privileges on the metalake, APIs and agent lookup. **Step 2** adds review of changes, version +history and grants on domains. Implementation Steps lists what each step contains. + +## Goals + +1. **Term object**: a `GlossaryTerm` under the metalake. It has a name, definition, synonyms, owner, + status, domains, documentation links, properties and an optional source reference. There is no + glossary container. Domains and the term hierarchy group the terms. Terms can carry tags through + the existing tag APIs. +2. **Hierarchy**: a term can have several broader (parent) terms, in any domain. Narrower (child) + terms come from the other side. `RELATED` links two terms both ways. The server rejects cycles. +3. **Bindings**: a term can be linked to catalogs, schemas, tables, views, columns, filesets, + topics and models (where the data is), and to semantic-model metrics (what is computed from it). + A term lists its objects, and an object lists its terms. A binding never gives access to data. +4. **Domains**: a term belongs to zero or more domains. A domain is optional when a term is + created. In Step 1, domains group and filter terms. They do not change who can see or manage a + term. +5. **Status**: `DRAFT`, `APPROVED` or `DEPRECATED`. New terms are `APPROVED`. Anyone who can edit a + term can set its status, in the create or update call. There are no transition rules. Agents + only see `APPROVED` terms. +6. **Privileges**: `VIEW_DEFINITION`, `CREATE_DEFINITION` and `MANAGE_DEFINITIONS`, granted on the + metalake. Deny wins over allow. REST and MCP use the same rules. +7. **Revisions**: every content change increases the revision number of the term, and is audited. + There are no content snapshots and no history API in Step 1. +8. **APIs**: REST, Java and Python clients, read-only MCP tools, events and audit. Each view of the + glossary page needs one or two REST calls. An agent can look up all business words of a question + in one call. + +## Non-Goals + +1. **Approval workflow, version history and grants on domains**: these come in Step 2 (see + Implementation Steps). In Step 1, edits take effect at once. Step 2 plugs in through + `TermChangeHandler` (see Status and versions). +2. **Bulk import and export, connectors to other glossaries, SKOS export**: these tools can use the + REST API and the source reference. +3. **Ranked, fuzzy or semantic lookup in Step 1**: Step 1 only matches names and synonyms exactly + (ignoring case and extra spaces). This is enough for words that the glossary defines. Better + matching can come later without an API change: `matchedBy` can get new values (for example + `FUZZY` or `SEMANTIC`) and a score, and `resolve_business_term` keeps the same input and output. +4. **Access through terms**: a term or a binding never gives or blocks access to data. Terms have + no policies. +5. **Agent writes and the UI itself**: the MCP tools are read-only. The UI uses the REST API. Web UI + support lists the calls for each part of the page. + +## Usage Scenario + +1. An admin with `MANAGE_DEFINITIONS` on the metalake creates term `Customer` in domain Sales. New + terms are `APPROVED`, so users with `VIEW_DEFINITION` can see it at once. +2. An analyst with `CREATE_DEFINITION` on the metalake creates `Active Customer` with status + `DRAFT`, so agents do not use it yet. Its broader term is `Customer` and its synonym is + `active user`. The analyst links it to column `dw.sales.customers.is_active` (Implemented by). +3. When the definition is ready, the analyst sets `Active Customer` to `APPROVED`. The analyst owns + this term, so the analyst can edit it and set its status. The analyst cannot edit `Customer`. +4. The owner of semantic model `dw.sales.sales_model` links its metric `active_customers` to + `Active Customer`. The term now shows the metric under Used by. +5. A user asks an agent for "net revenue from VIP active users last month". The agent picks the + business words and calls `resolve_business_term(["net revenue", "VIP", "active user"])` once: + - `active user` returns `Active Customer` (matched by synonym), with its column and metric. + `net revenue` returns `Net revenue`, with its metric. The result only contains what the user + can read. + - `VIP` has no match. The agent asks the user what VIP means. It does not guess a column. + + Then the agent loads the table or the semantic model with the existing tools. The full flow is + in Agent integration. +6. Later the term is replaced. The owner or the admin sets it to `DEPRECATED`, and agents stop + seeing it. Then the admin deletes it. + +## Design + +### Data model + +``` +GlossaryTerm { id, name, definition, synonyms[], status: DRAFT | APPROVED | DEPRECATED, + links[{label, url}], sourceRef?, properties, currentVersion, audit_info } + // tags: the existing tag relation tables +TermRelation { fromTermId, toTermId, type: BROADER | RELATED, audit_info } +TermDomain { termId, domainId, audit_info } // Option A in Domain membership +TermBinding { termId, objectId, objectType, metricName?, audit_info } +TermVersion { termId, version, state, snapshot, audit_info } // created now; rows from Step 2 +``` + +| Table | Unique key | Other index | +| ---------------------------- | ------------------------------------------------------------------------------ | ---------------------------------------- | +| `glossary_term_meta` | `(metalake_id, name_key, deleted_at)`, `(metalake_id, source_ref, deleted_at)` | | +| `glossary_term_synonym` | `(term_id, synonym_key, deleted_at)` | `(metalake_id, synonym_key, deleted_at)` | +| `glossary_term_rel` | `(from_term_id, to_term_id, rel_type, deleted_at)` | `(to_term_id, rel_type)` | +| `glossary_term_domain_rel` | `(term_id, domain_id, deleted_at)` | `(domain_id)` | +| `glossary_term_binding` | `(term_id, object_type, object_id, metric_name, deleted_at)` | `(object_type, object_id)` | +| `glossary_term_version_info` | `(term_id, version, deleted_at)` | `(term_id, state)` | + +- The tables are added to the H2, MySQL and PostgreSQL schemas and to the `upgrade-1.3.0-to-2.0.0` + scripts. +- **Normalized key**: `key(s)` trims `s`, turns each run of spaces into one space, and lower-cases + it (`Locale.ROOT`). Names, synonyms and lookups all use `key()`, so they compare the same way. +- **Names** are unique in a metalake by `name_key = key(name)`. So `Churn` and `churn` are the same + name on every database. Responses return the name as the user typed it. Names follow the tag and + domain rules: up to 128 characters, and `/` is allowed (URL-encoded in paths). +- **Synonyms** are stored one per row, with `synonym_key = key(synonym)`. Two terms can share a + synonym. A synonym cannot be the name of another term. The server checks this in both + directions: when a synonym is added, and when a term is created or renamed (400). +- **Documentation links** (a label and a URL) are shown on the term page. They are stored in a JSON + column of `glossary_term_meta`. No query reads inside them. +- **Source reference** is optional. When set, it is unique in the metalake. It records where an + imported term came from, in the form `<system>:<id>`, for example + `datahub:urn:li:glossaryTerm:Customer`. A new import can then update the term instead of creating + a copy. A term without a source reference was created in Gravitino. +- `MetadataObject.Type.GLOSSARY_TERM` is added for owners, tags, events and audit. Privileges + **cannot be granted on a single term**: the role APIs reject them. +- Terms, relations and bindings are not cached. Every request reads the store, the same as for + domains. + +### Relations + +- `BROADER` is stored on the child. A → B means "A is a kind of B". Narrower terms are not stored; + the server finds them from the `BROADER` rows. `RELATED` is stored once per pair (with + `from_term_id < to_term_id`) and shows on both terms. +- Setting the broader or related term of A only changes A. The caller needs the edit privilege on A + and `VIEW_DEFINITION` on the other term. +- **Cycle check**: adding A → B fails with 400 if B already reaches A through `BROADER` links. The + server walks up from B, level by level, under the hierarchy lock (see Locking). A term cannot be + its own parent. +- **Depth limit**: a `BROADER` chain has at most 20 levels. A new link that makes a chain longer Review Comment: This is an estimated value. The query time will be very large with a big level number. Currently, I do not have a concrete result about which one is the max value we supported -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
