dbt-metricflow-sql 0.3.3__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/PKG-INFO +1 -3
  2. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/README.md +30 -30
  3. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/pyproject.toml +1 -4
  4. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/cli.py +29 -5
  5. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/fragment.schema.json +50 -38
  6. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/llms-full.txt +485 -338
  7. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/plugin.py +63 -24
  8. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/semantics.py +199 -82
  9. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/server.py +47 -0
  10. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/sl_config.py +31 -10
  11. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/uv.lock +1 -5
  12. dbt_metricflow_sql-0.3.3/src/dbt_metricflow_sql/legacy.py +0 -1286
  13. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/.gitignore +0 -0
  14. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/LICENSE +0 -0
  15. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/PYPI.md +0 -0
  16. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/__init__.py +0 -0
  17. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/client.py +0 -0
  18. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/dependencies.py +0 -0
  19. {dbt_metricflow_sql-0.3.3 → dbt_metricflow_sql-0.5.0}/src/dbt_metricflow_sql/docs.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: dbt-metricflow-sql
3
- Version: 0.3.3
3
+ Version: 0.5.0
4
4
  Summary: dbt v1 plugin for MetricFlow
5
5
  Project-URL: Documentation, https://docs-internal-git-mfsql-dbt-labs.vercel.app/metricflow
6
6
  License-Expression: LicenseRef-Fivetran
@@ -9,8 +9,6 @@ Classifier: Programming Language :: Python :: 3
9
9
  Requires-Python: >=3.9
10
10
  Requires-Dist: dbt-core>=1.9
11
11
  Requires-Dist: jsonschema>=4.19
12
- Provides-Extra: compat
13
- Requires-Dist: sqlglot>=30.27; extra == 'compat'
14
12
  Provides-Extra: sidecar
15
13
  Requires-Dist: metricflow-sql-sidecar; extra == 'sidecar'
16
14
  Description-Content-Type: text/markdown
@@ -32,8 +32,8 @@ its stdin closes.
32
32
 
33
33
  ## Semantics
34
34
 
35
- Declare semantics in schema files: `datasets`, `entities`, `constellations` and `pages` at the
36
- root, and dataset fields on models, seeds, snapshots and source tables. They're the objects of a
35
+ Declare semantics in schema files: `datasets`, `entities`, `constellations` and `pages` under the
36
+ `semantics` key, and dataset fields on models, seeds, snapshots and source tables. They're the objects of a
37
37
  [v1 fragment](../metricflow-sql/src/metricflow_sql/schemas/v1/fragment.py), whose named
38
38
  collections are dbt-style lists of objects with a `name`:
39
39
 
@@ -50,23 +50,24 @@ models:
50
50
  - name: customers
51
51
  dataset: true # a dataset of nothing but its columns
52
52
 
53
- datasets:
54
- - name: refunds
55
- source: ref('refunds') # or source('<source>', '<table>')
56
-
57
- constellations:
58
- - name: sales
59
- roles:
60
- - name: customer
61
- datatype: REF(customer)
62
- metrics:
63
- - name: revenue
64
- expr: AGG(orders.revenue)
65
- assignments:
66
- - dataset: orders
67
- roles:
68
- - name: customer
69
- expr: customer
53
+ semantics:
54
+ datasets:
55
+ - name: refunds
56
+ source: ref('refunds') # or source('<source>', '<table>')
57
+
58
+ constellations:
59
+ - name: sales
60
+ roles:
61
+ - name: customer
62
+ datatype: REF(customer)
63
+ metrics:
64
+ - name: revenue
65
+ expr: AGG(orders.revenue)
66
+ facts:
67
+ - dataset: orders
68
+ roles:
69
+ - name: customer
70
+ expr: customer
70
71
  ```
71
72
 
72
73
  A node is a dataset, named after it, if it sets `calculations`, `relationships`, `parameters` or
@@ -193,25 +194,24 @@ warns of keys it doesn't know as custom ones; the plugin declares these to it.
193
194
 
194
195
  ## Legacy MetricFlow
195
196
 
196
- To try MetricFlow on a project's legacy semantic models and metrics, without rewriting them, install
197
- the plugin with its `compat` extra, and turn on legacy compatibility:
198
-
199
- ```sh
200
- pip install 'dbt-metricflow-sql[compat]'
201
- ```
197
+ To try MetricFlow on a project's legacy semantic models and metrics, without rewriting them, set
198
+ `metricflow_convert_legacy`:
202
199
 
203
200
  ```yaml
204
201
  # dbt_project.yml
205
202
  vars:
206
- metricflow_legacy_compatibility: true
203
+ metricflow_convert_legacy: true
207
204
  ```
208
205
 
209
206
  Parse then converts the project's legacy semantics, as dbt writes them to
210
207
  `semantic_manifest.json`, into one more fragment of the bundle, `legacy_semantic_manifest.json`,
211
- next to the fragments of its MetricFlow semantics. Its objects are in the `legacy` namespace, so
212
- they don't collide with the project's own, e.g. a semantic model `orders` is the dataset
213
- `legacy.orders`, beside a MetricFlow dataset `orders`. Every metric is a metric of one
214
- constellation, `legacy.metrics`:
208
+ next to the fragments of its MetricFlow semantics. The MetricFlow server converts them, run as
209
+ `metricflow-serve convert-legacy` (see `metricflow_sql.converters.legacy`), so with it set, parse
210
+ needs the `sidecar` extra, or the `metricflow_server` var, as compiling MetricFlow models does.
211
+
212
+ The fragment's objects are in the `legacy` namespace, so they don't collide with the project's
213
+ own, e.g. a semantic model `orders` is the dataset `legacy.orders`, beside a MetricFlow dataset
214
+ `orders`. Every metric is a metric of one constellation, `legacy.metrics`:
215
215
 
216
216
  ```sql
217
217
  SELECT DATE_TRUNC('month', metric_time), customer.region, AGG(revenue)
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "dbt-metricflow-sql"
3
3
  # A placeholder: a release sets its tag's version, with scripts/set_version.py.
4
- version = "0.3.3"
4
+ version = "0.5.0"
5
5
  description = "dbt v1 plugin for MetricFlow"
6
6
  # Its PyPI page: README.md is for this repository.
7
7
  readme = "PYPI.md"
@@ -25,9 +25,6 @@ dbtsl = "dbt_metricflow_sql.cli:main"
25
25
  # The MetricFlow server it runs by default, which needs no Python of its own: only projects with
26
26
  # MetricFlow models run one.
27
27
  sidecar = ["metricflow-sql-sidecar"]
28
- # Legacy compatibility, `metricflow_legacy_compatibility`, which writes the warehouse's SQL for
29
- # legacy MetricFlow's aggregations, e.g. a percentile.
30
- compat = ["sqlglot>=30.27"]
31
28
 
32
29
  [project.urls]
33
30
  Documentation = "https://docs-internal-git-mfsql-dbt-labs.vercel.app/metricflow"
@@ -43,9 +43,11 @@ import click
43
43
  from dbt.adapters.factory import get_adapter_by_type
44
44
  from dbt.cli.flags import Flags
45
45
  from dbt.cli.main import cli, dbtRunner
46
- from dbt.config.runtime import RuntimeConfig
46
+ from dbt.config.project import Project
47
+ from dbt.config.runtime import RuntimeConfig, UnsetProfile, load_project
47
48
  from dbt.contracts.graph.manifest import Manifest
48
49
  from dbt.events.logging import setup_event_logger
50
+ from dbt.exceptions import DbtProjectError
49
51
  from dbt.flags import set_flags
50
52
  from dbt_common.clients.system import get_env
51
53
  from dbt_common.context import set_invocation_context
@@ -82,7 +84,7 @@ def main(argv: Sequence[str] | None = None) -> int:
82
84
  if args.command == DOCS:
83
85
  return _docs(args.page, args.all)
84
86
  if args.command == sl_config.CONFIG:
85
- return sl_config.run(args, _load_config)
87
+ return sl_config.run(args, _load_project_config)
86
88
  reader: _Reader | None = (
87
89
  _local_reader(args.dbt_args, args.dialect)
88
90
  if args.local
@@ -340,8 +342,30 @@ def _remote_reader(dbt_args: Sequence[str], dialect: str | None = None) -> _Remo
340
342
  def _load_config(dbt_args: Sequence[str]) -> RuntimeConfig:
341
343
  """
342
344
  The project's and profile's config, as `dbt parse` with `dbt_args` would load it, without
343
- parsing the project: only what dbt's preflight sets up first, i.e. its flags, the environment
344
- `env_var()` reads, and its event logger, quiet but for errors.
345
+ parsing the project (see `_preflight`).
346
+ """
347
+ return RuntimeConfig.from_args(_preflight(dbt_args))
348
+
349
+
350
+ def _load_project_config(dbt_args: Sequence[str]) -> Project:
351
+ """
352
+ The project's and profile's config (see `_load_config`), else, with no profile named as the
353
+ project's, the project's alone, without a target.
354
+ """
355
+ flags = _preflight(dbt_args)
356
+ try:
357
+ return RuntimeConfig.from_args(flags)
358
+ except DbtProjectError:
359
+ # dbt Cloud's CLI's users have no `profiles.yml`, and `dbtsl config` needs no
360
+ # credentials. A project that's itself invalid fails here again.
361
+ profile = UnsetProfile() # type: ignore[no-untyped-call]
362
+ return load_project(flags.PROJECT_DIR, bool(flags.VERSION_CHECK), profile, flags.VARS)
363
+
364
+
365
+ def _preflight(dbt_args: Sequence[str]) -> Flags:
366
+ """
367
+ The flags of `dbt parse` with `dbt_args`, set up as dbt's preflight sets them first, with the
368
+ environment `env_var()` reads, and its event logger, quiet but for errors.
345
369
  """
346
370
  args = ["parse", "--quiet", *dbt_args]
347
371
  context = cli.make_context(cli.name, list(args))
@@ -351,7 +375,7 @@ def _load_config(dbt_args: Sequence[str]) -> RuntimeConfig:
351
375
  set_invocation_context(get_env())
352
376
  set_flags(flags) # type: ignore[no-untyped-call]
353
377
  setup_event_logger(flags)
354
- return RuntimeConfig.from_args(flags)
378
+ return flags
355
379
 
356
380
 
357
381
  def _local_reader(dbt_args: Sequence[str], dialect: str | None = None) -> _LocalReader | None:
@@ -35,7 +35,7 @@
35
35
  "type": "object"
36
36
  },
37
37
  "name": {
38
- "description": "The name of the role, unique among the dataset's assignments.",
38
+ "description": "The name of the role, unique among the fact's roles.",
39
39
  "type": "string"
40
40
  }
41
41
  },
@@ -219,14 +219,6 @@
219
219
  "additionalProperties": false,
220
220
  "description": "A group of fact tables connected by conformed dimensions.\n\nConstellations capture higher-order business domains and enable\nmulti-fact queries. Constellations can include configuration from other\nconstellations.",
221
221
  "properties": {
222
- "assignments": {
223
- "default": [],
224
- "description": "How datasets provide roles, by dataset.",
225
- "items": {
226
- "$ref": "#/$defs/DatasetAssignment"
227
- },
228
- "type": "array"
229
- },
230
222
  "description": {
231
223
  "anyOf": [
232
224
  {
@@ -238,6 +230,14 @@
238
230
  ],
239
231
  "default": null
240
232
  },
233
+ "facts": {
234
+ "default": [],
235
+ "description": "The datasets of the constellation, and the roles they provide.",
236
+ "items": {
237
+ "$ref": "#/$defs/Fact"
238
+ },
239
+ "type": "array"
240
+ },
241
241
  "imports": {
242
242
  "default": [],
243
243
  "description": "Other constellations to import fields from.",
@@ -380,33 +380,6 @@
380
380
  "title": "Dataset",
381
381
  "type": "object"
382
382
  },
383
- "DatasetAssignment": {
384
- "additionalProperties": false,
385
- "description": "The roles a dataset provides.",
386
- "properties": {
387
- "dataset": {
388
- "description": "The name of the dataset, unique among the constellation's.",
389
- "type": "string"
390
- },
391
- "meta": {
392
- "default": {},
393
- "type": "object"
394
- },
395
- "roles": {
396
- "default": [],
397
- "description": "How the dataset provides each role.",
398
- "items": {
399
- "$ref": "#/$defs/Assignment"
400
- },
401
- "type": "array"
402
- }
403
- },
404
- "required": [
405
- "dataset"
406
- ],
407
- "title": "DatasetAssignment",
408
- "type": "object"
409
- },
410
383
  "DatasetSource": {
411
384
  "additionalProperties": false,
412
385
  "description": "A physical table, or a query.",
@@ -583,6 +556,45 @@
583
556
  "title": "EntityKeyColumn",
584
557
  "type": "object"
585
558
  },
559
+ "Fact": {
560
+ "additionalProperties": false,
561
+ "description": "A dataset of the constellation, and the roles it provides.",
562
+ "properties": {
563
+ "alias": {
564
+ "anyOf": [
565
+ {
566
+ "type": "string"
567
+ },
568
+ {
569
+ "type": "null"
570
+ }
571
+ ],
572
+ "default": null,
573
+ "description": "The name metrics read the dataset by, e.g. `AGG(visits.count)`, unique among the constellation's facts. Defaults to the dataset's name."
574
+ },
575
+ "dataset": {
576
+ "description": "The name of the dataset.",
577
+ "type": "string"
578
+ },
579
+ "meta": {
580
+ "default": {},
581
+ "type": "object"
582
+ },
583
+ "roles": {
584
+ "default": [],
585
+ "description": "How the dataset provides each role.",
586
+ "items": {
587
+ "$ref": "#/$defs/Assignment"
588
+ },
589
+ "type": "array"
590
+ }
591
+ },
592
+ "required": [
593
+ "dataset"
594
+ ],
595
+ "title": "Fact",
596
+ "type": "object"
597
+ },
586
598
  "Fragment": {
587
599
  "additionalProperties": false,
588
600
  "description": "A piece of a bundle's semantic graph: the fragments of a bundle are merged into it.\n\nDatasets, entities and constellations are named like a warehouse's tables: `sales.orders` is\n`orders` in the `sales` namespace, and a name without a namespace is in `public`. A reference\nwithout a namespace, e.g. a relationship's `entity: customer`, is in the namespace of the\nobject that declares it. A dataset and a constellation can't share a name.",
@@ -852,7 +864,7 @@
852
864
  "default": null
853
865
  },
854
866
  "expr": {
855
- "description": "A SQL expression, where qualified columns reference fields from datasets and unqualified columns reference other metrics or roles.",
867
+ "description": "A SQL expression, where qualified columns reference fields of the constellation's facts, by alias, e.g. `orders.revenue`, and unqualified columns reference other metrics or roles.",
856
868
  "type": "string"
857
869
  },
858
870
  "label": {
@@ -1070,7 +1082,7 @@
1070
1082
  "description": "How a relationship binds one of its target's fields.",
1071
1083
  "properties": {
1072
1084
  "expr": {
1073
- "description": "A SQL expression, relative to the dataset.",
1085
+ "description": "A SQL expression, relative to the dataset. `:name` passes on a key the dataset itself was joined by, e.g. `:as_of`.",
1074
1086
  "type": "string"
1075
1087
  },
1076
1088
  "meta": {