GoogleCloudPlatform / GoogleCloudPlatform/BigQuery-Agent-Analytics-SDK
feat: implement inheritance (extends) compilation support
- Dominant language
- Python
- Stars
- 47
- Forks
- 21
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 33
Description
## Summary
The ontology YAML schema supports `extends` on entities and relationships for modeling type hierarchies (`Person extends Party`). The loader validates inheritance rules (property/key inheritance, covariant endpoint narrowing, cycle detection), but the v0 compiler rejects any ontology that uses `extends`.
This creates a confusing UX gap: `gm validate` succeeds, then `gm compile` fails.
## What needs to happen
The compiler needs a **lowering strategy** to translate inheritance into BigQuery `CREATE PROPERTY GRAPH` DDL. The compiler code (`graph_ddl_compiler.py:_reject_extends`) identifies three candidate strategies:
1. **Fan-out** — materialize one node table per concrete entity type, duplicating inherited properties into each table.
2. **Union view** — create a view that unions all subtypes under the parent label.
3. **Label-referenced edges** — use multiple labels per node table to represent the type hierarchy.
Each has trade-offs around query patterns, data duplication, and DDL complexity.
## Current state
- **Loader (`ontology_loader.py`)**: Fully validates `extends` — unique names, no cycles, no property/key redeclaration, covariant endpoint narrowing, cardinality inheritance.
- **Binding loader (`binding_loader.py`)**: Handles inherited properties correctly (effective property coverage includes inherited ones).
- **Compiler (`graph_ddl_compiler.py`)**: Rejects `extends` at `_reject_extends()` with `compile-validation` error.
- **User manual**: Documents `extends` as "under development" and advises users to define entities independently.
## Design questions to resolve
1. Which lowering strategy to use (fan-out, union-view, label-referenced, or something else)?
2. Should `gm validate` warn when `extends` is used, given compilation will fail?
3. The cardinality inheritance rule is unusually strict — a child cannot introduce cardinality when the parent has none. Should this be relaxed?
4. Property redeclaration is forbidden even for adding annotations or narrowing descriptions. Should refinement (without type changes) be allowed?
Contributor guide
Assessment
This issue has not been assessed yet.