metricflow-sql 0.3.2__tar.gz → 0.3.3__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 (62) hide show
  1. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/PKG-INFO +1 -1
  2. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/pyproject.toml +1 -1
  3. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/converters/lookml.py +55 -7
  4. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/.gitignore +0 -0
  5. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/LICENSE +0 -0
  6. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/PYPI.md +0 -0
  7. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/README.md +0 -0
  8. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/__init__.py +0 -0
  9. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/__init__.py +0 -0
  10. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/__init__.py +0 -0
  11. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/cluster.py +0 -0
  12. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/information_schema.py +0 -0
  13. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/metadata.py +0 -0
  14. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/passthrough.py +0 -0
  15. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/protocols.py +0 -0
  16. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/semantic.py +0 -0
  17. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/compiler.py +0 -0
  18. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/__init__.py +0 -0
  19. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_constellations.py +0 -0
  20. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_datasets.py +0 -0
  21. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_metadata.py +0 -0
  22. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_per.py +0 -0
  23. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/isolate_fragments.py +0 -0
  24. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/passthrough_tables.py +0 -0
  25. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/table_arguments.py +0 -0
  26. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/converters/__init__.py +0 -0
  27. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/__init__.py +0 -0
  28. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/base.py +0 -0
  29. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/constellation.py +0 -0
  30. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/dataset.py +0 -0
  31. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/entity.py +0 -0
  32. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/reference.py +0 -0
  33. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/wiki.py +0 -0
  34. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/py.typed +0 -0
  35. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/__init__.py +0 -0
  36. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/memory.py +0 -0
  37. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/operation.py +0 -0
  38. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/reference_resolution.py +0 -0
  39. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/registry.py +0 -0
  40. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/type_resolver.py +0 -0
  41. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/__init__.py +0 -0
  42. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/bundle.py +0 -0
  43. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/fragment.schema.json +0 -0
  44. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/generate.py +0 -0
  45. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/load.py +0 -0
  46. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/markdown.py +0 -0
  47. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/v1/__init__.py +0 -0
  48. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/v1/fragment.py +0 -0
  49. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/__init__.py +0 -0
  50. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/app.py +0 -0
  51. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/compile.py +0 -0
  52. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/errors.py +0 -0
  53. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/http.py +0 -0
  54. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/registry.py +0 -0
  55. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/serde.py +0 -0
  56. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/serve.py +0 -0
  57. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/__init__.py +0 -0
  58. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/composed_set.py +0 -0
  59. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/normalize.py +0 -0
  60. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/ordered_set.py +0 -0
  61. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/sql.py +0 -0
  62. {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/template.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: metricflow-sql
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: MetricFlow's core semantic layer engine
5
5
  Project-URL: Documentation, https://docs-internal-git-mfsql-dbt-labs.vercel.app/metricflow
6
6
  License-Expression: LicenseRef-Fivetran
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "metricflow-sql"
3
3
  # A placeholder: a release sets its tag's version, with scripts/set_version.py.
4
- version = "0.3.2"
4
+ version = "0.3.3"
5
5
  description = "MetricFlow's core semantic layer engine"
6
6
  # Its PyPI page: README.md is for this repository.
7
7
  readme = "PYPI.md"
@@ -74,6 +74,8 @@ _DIALECT = "bigquery"
74
74
  _LOOKML_DIALECT = "trino"
75
75
  # Stands in for a reference while LookML's SQL parses, e.g. `${accounts.region}`.
76
76
  _PLACEHOLDER = "__lookml_{}"
77
+ # Stands in for a joined view's field in a join key's field, until it moves to the join's `on`.
78
+ _JOINED_PLACEHOLDER = "__joined_{}"
77
79
 
78
80
 
79
81
  type _Template = Callable[[exp.Expr], exp.Expr]
@@ -441,8 +443,12 @@ class _Converter:
441
443
 
442
444
  def inline(self, view: str, target: str, name: str) -> exp.Expr:
443
445
  """A reference expanded to its columns, since join keys can't read calculations."""
444
- resolved, _, template = self.name(target, name)
445
- return template(self.dimension(target, self.definition(target, resolved)[1], self.inline))
446
+ return self.expand(target, name, self.inline)
447
+
448
+ def expand(self, view: str, name: str, resolve: _Resolve) -> exp.Expr:
449
+ """The field's SQL on its view's columns, with its references what `resolve` makes of them."""
450
+ resolved, _, template = self.name(view, name)
451
+ return template(self.dimension(view, self.definition(view, resolved)[1], resolve))
446
452
 
447
453
  def parameters(self, view: str) -> dict[str, tuple[str, dict[str, Any]]]:
448
454
  """The parameters `view`'s LookML reads, by name: the Liquid Looker renders as their
@@ -523,18 +529,60 @@ class _Converter:
523
529
  sources: [{dataset: accounts, on: ":revenue__account_id = account_id"}]
524
530
 
525
531
  and the relationship key `[{name: revenue__account_id, expr: account_id}]` on `revenue`.
532
+
533
+ A key's field that reads the joined view, e.g. `coalesce(${TABLE}.day, ${accounts.day})`,
534
+ can't be a key, which reads only its own dataset: `on` reads it instead, with a key for each
535
+ of its columns and parameters, e.g. `coalesce(:revenue__day, day)`.
526
536
  """
527
537
  view = join["name"]
528
538
  key: dict[str, exp.Expr] = {}
529
539
 
540
+ def add_key(name: str, expr: exp.Expr) -> exp.Expr:
541
+ """`:name`, or a name apart from another key's, e.g. a field and a column `day`."""
542
+ key_name, suffix = name, 1
543
+ while key.get(key_name, expr) != expr:
544
+ suffix += 1
545
+ key_name = f"{name}_{suffix}"
546
+ key[key_name] = expr
547
+ return exp.var(f":{key_name}")
548
+
530
549
  def bind(_: str, target: str, name: str) -> exp.Expr:
531
550
  if target == view:
532
551
  return self.inline(view, view, name)
533
- # Named apart from `accounts.account_id`, which reads the joined row, NULL when the
534
- # join doesn't match.
535
- key_name = f"{target}__{name}"
536
- key[key_name] = self.inline(target, target, name)
537
- return exp.var(f":{key_name}")
552
+ joined: dict[str, exp.Expr] = {}
553
+
554
+ def read_joined(_: str, reference: str, field_name: str) -> exp.Expr:
555
+ if reference != view:
556
+ return self.expand(reference, field_name, read_joined)
557
+ placeholder = _JOINED_PLACEHOLDER.format(len(joined))
558
+ joined[placeholder] = self.inline(view, view, field_name)
559
+ return exp.var(f":{placeholder}")
560
+
561
+ sql = self.expand(target, name, read_joined)
562
+ if not joined:
563
+ # Named apart from `accounts.account_id`, which reads the joined row, NULL when
564
+ # the join doesn't match.
565
+ return add_key(f"{target}__{name}", sql)
566
+
567
+ def bind_parent(node: exp.Expr) -> exp.Expr:
568
+ # The joined dataset has neither the parent's columns nor its parameters, e.g.
569
+ # `:since`.
570
+ if isinstance(node, exp.Column):
571
+ return add_key(f"{target}__{node.name}", node.copy())
572
+ # A parameter is `:since`; a bare `Var` is a keyword, e.g. `MONTH`.
573
+ parameter = node.name.removeprefix(":") if isinstance(node, exp.Var) else None
574
+ if parameter and parameter != node.name and parameter not in joined:
575
+ return add_key(f"{target}__{parameter}", node.copy())
576
+ return node
577
+
578
+ sql = sql.transform(bind_parent)
579
+ return sql.transform(
580
+ lambda node: (
581
+ joined.get(node.name.removeprefix(":"), node)
582
+ if isinstance(node, exp.Var)
583
+ else node
584
+ )
585
+ )
538
586
 
539
587
  on = self.translate(view, join["sql_on"], bind)
540
588
  entity = {
File without changes
File without changes
File without changes