Semantic-layer playground. Define metrics once in JSON, query by dimensions and filters, see the SQL the engine would compile. Demonstrates the pattern from Thoughtworks Technology Radar Vol 34 (Trial, April 2026).
Live demo: https://sen.ltd/portfolio/semantic-layer/
- Define-once metric model: name, description, source table, measure (sum / count / count_distinct / avg / min / max), declared dimensions
- Query consumers: pick a metric, group by allowed dimensions, filter by
=/!=/>/</>=/<=/in/not in, optional limit - SQL compiler emits a portable
SELECT … FROM … WHERE … GROUP BY … ORDER BY … LIMITshape - Validator enforces that consumers can only ask for declared dimensions — no random column-joins
- Auto-generated catalog panel shows each metric, its measure, its allowed dimensions
- 3 domain presets: e-commerce orders, SaaS user activity, support tickets
- 20 unit tests covering model validation, query validation, SQL emission, filter rendering, dimension expressions, value formatting
- Zero dependencies, no build step
npm run serve
# → http://localhost:8080npm testcompile.js ← validateModel + validateQuery + compile + describeModel (DOM 非依存、20 tests)
presets.js ← 3 種類のサンプル (model, query) ペア
app.js ← UI グルー(編集 → validate → compile → render catalog + SQL)
compile.js は DOM が登場しない pure module。Node テストで model 検証 / query 検証 / SQL 生成 / フィルタ表現 / 次元式 / リテラル整形 を完全に分岐網羅してから、UI 層は両者の文字列出力を表示するだけ。
- measure: aggregate function (sum / count / count_distinct / avg / min / max) と column
- dimension: 名前のみ (
{ name: "channel" }) または式付き ({ name: "month", expr: "DATE_TRUNC('month', created_at)" }) - source: single table — joins / time-grain expansion / access control は意図的に省略
実プロダクト用は dbt MetricFlow, Cube.dev, Snowflake Semantic Views, Databricks Metric Views を使うべし — このツールは「セマンティックレイヤとは何か」を仕組みで見せる教育用おもちゃ。
MIT. See LICENSE.
