yuqi1129 commented on code in PR #14239:
URL: https://github.com/apache/gravitino/pull/14239#discussion_r4561535654


##########
design-docs/glossary-design.md:
##########
@@ -0,0 +1,1265 @@
+<!--
+  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)`        
       |

Review Comment:
   Agreed. The final design now uses a unified `(term_id, target_type, 
target_id, deleted_at)` key, with every key column NOT NULL. TABLE and COLUMN 
use their own stable IDs; the binding-specific METRIC target type uses the 
existing metric_id rather than the containing model ID plus a metric name. This 
supersedes my earlier empty-string marker proposal: metric_name is no longer 
stored in the binding key.
   
   T11.12 requires direct storage-layer duplicate, NULL-key and 
soft-delete/rebind checks on H2, MySQL and PostgreSQL. T11.17 adds long-name 
and removed/reintroduced metric identity cases, so old bindings cannot reappear 
under a reused name. REST/MCP may still accept model/name inputs and resolve 
them to IDs.
   
   Design update: 
[`aef393733d`](https://github.com/apache/gravitino/pull/14239/commits/aef393733daa27bc95266b96bcdea06097ec0ad3).
 These are design and test requirements, not a claim that the runtime 
implementation has shipped.



-- 
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]

Reply via email to