feat(analytics): dataset semantic layer (ADR-0021) — schema, compiler, RLS, REST#1643
Merged
Conversation
…, RLS, REST Implements the analytics `dataset` semantic layer end-to-end on the backend. spec: - New `dataset` metadata type (ui/dataset.zod.ts): object + include relationships + declared dimensions/measures + derived measures, with superRefine validation. - Registered across the 7 surfaces (type-schemas, plugin enum + registry with loadOrder 55, collection maps, engine metadataArrayKeys, stack). - StrategyContext contract: context-aware `getReadScope` (returns FilterCondition) + `getAllowedRelationships`; `IAnalyticsService.query/generateSql` take an optional ExecutionContext. service-analytics: - dataset → Cube compiler: resolves `include` relationships to TARGET TABLES via a RelationshipResolver and emits cube.joins (fixes lookup-field-name ≠ table-name, e.g. `account` → `crm_account`); D-C relationship allowlist. - DatasetExecutor: filter combination, measure-scoped filters, derived-measure evaluation (ratio/sum/difference/product), compareTo time-shift. - NativeSQLStrategy D-C hardening: per-object tenant/RLS read scope injected on the base AND every joined table; reject joins not backed by a declared relationship. - read-scope-sql: fail-closed FilterCondition → alias-qualified parameterized SQL. - Plugin: context-bound read-scope per request; auto-bridge to a `security` service's getReadFilter; relationshipResolver from the data engine's object schema. rest: POST /api/v1/analytics/dataset/query (inline draft or saved name), threads ExecutionContext for tenant/RLS scoping; D-C errors → 400. cli: `analytics` is now an always-on built-in capability so the dataset/analytics endpoints exist even when an app declares no cubes. Verified live (app-crm, SqlDriver): cross-object "revenue by account.industry" returns correct rows with the right JOIN; D-C guard → 400; single-object path OK. Tests: service-analytics 85, rest analytics 6, spec dataset+contracts 240. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Jun 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the analytics
datasetsemantic layer (ADR-0021) end-to-end on the backend.spec: new
datasetmetadata type (object + include relationships + dimensions/measures + derived measures) registered across the 7 surfaces; context-awaregetReadScope/getAllowedRelationshipson StrategyContext;IAnalyticsService.query/generateSqltake an optional ExecutionContext.service-analytics: dataset→Cube compiler (resolves
includeto TARGET TABLES, fixing lookup-field-name ≠ table-name, e.g.account→crm_account); DatasetExecutor (filters, measure-scoped filters, derived measures, compareTo); NativeSQLStrategy D-C hardening (per-object tenant/RLS scope on base + joined tables; reject undeclared joins); fail-closed FilterCondition→SQL compiler; plugin wires context-bound read-scope + relationshipResolver.rest:
POST /api/v1/analytics/dataset/query(inline draft or saved name), threads ExecutionContext; D-C errors → 400.cli:
analyticsis now an always-on built-in capability.Verified live (app-crm, SqlDriver): cross-object
revenue by account.industry→ correct rows + correctLEFT JOIN "crm_account" "account"; D-C guard → 400; single-object path OK. Tests: service-analytics 85, rest analytics 6, spec dataset+contracts 240.Pairs with objectui PR #1570 (Studio designer + preview);
.objectui-shapins that commit.Follow-up (separate, security-reviewed): SecurityPlugin to expose
getReadFilterso multi-org cross-object analytics auto-scopes in production.🤖 Generated with Claude Code