Semantic Model
How a 0sql project describes tables, fields, expressions and relationships, and what the planner does with them.
Overview
The semantic model is the core of 0sql. It describes warehouse tables as named dimensions and measures with joins between them, so that a query spec naming fields can be planned into one SQL statement for your warehouse.
Critical Rules
Before diving into components, understand these non-negotiable design principles:
Key Components
Tables
Tables define semantic metadata for physical database tables:
- Dimensions: Categorical fields for grouping
- Measures: Aggregatable quantities
- Cost: Query optimization hints
- Partitions: Data availability constraints
Fields
Fields are the building blocks of your semantic model:
- Dimensions: Attributes for grouping and filtering
- Measures: Quantities to aggregate
- Data Types: string, integer, decimal, date, etc.
- Field metadata: descriptions, synonyms and tags, returned by the fields endpoint;
formatanddisplay_type, stored for your client
Expressions
Expressions define how fields query the database:
- SQL: Direct SQL expressions
- Lookups: Dimension field indicators
- Arrays: Multi-value fields
- Primary Keys: Unique identifiers
Relationships
Relationships define how tables join:
- Cardinality: one-to-one, one-to-many, many-to-one
- Join Types: inner (default), left, right
- Join Conditions: SQL expressions
How It Works
- Model Definition: you define tables, fields and relationships in YAML
- Deployment:
zsql deployvalidates the project and ships it to 0sql - Universe Formation: the planner precomputes every join path from every table
- Query Planning: your application POSTs a query spec and a security context; the planner picks tables and paths and writes the SQL
- SQL Returned: the response is one SQL statement in the datasource’s dialect, plus the datasource it targets
- Your application runs it: 0sql never connects to the warehouse
Advanced (in-depth and extra)
The Advanced subsection below covers deeper and optional semantic-model features: exclusions, inclusions, semantic routing, and cost optimization. The core basics (tables, fields, expressions, relationships, imports) are above; Advanced is for more in-depth and extra scenarios.
- Imports: Reuse field definitions across tables
- Partitions: Define data availability constraints
- Snapshot Measures: Point-in-time analysis
- Exclusions: Filter-based measure exclusions
- Inclusions: Multi-level calculations
- Decorators: Temporal, window and contribution transforms applied in the query spec; see Projections
Next Steps
- Read about tables
- Explore dimensions and measures
- Learn about expressions
- Understand relationships
- Go deeper in Advanced