Skip to content

sen-ltd/semantic-layer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

semantic-layer-playground

Demo

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/

Screenshot

特徴

  • 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 … LIMIT shape
  • 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:8080

テスト

npm test

アーキテクチャ

compile.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.

Links

About

In-browser semantic-layer playground from Tech Radar Vol 34 Trial. Define metrics once in JSON, query by dimensions and filters, see the compiled SQL.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors