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.
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/PKG-INFO +1 -1
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/pyproject.toml +1 -1
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/converters/lookml.py +55 -7
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/.gitignore +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/LICENSE +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/PYPI.md +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/README.md +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/cluster.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/information_schema.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/metadata.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/passthrough.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/protocols.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/semantic.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/compiler.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_constellations.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_datasets.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_metadata.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_per.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/isolate_fragments.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/passthrough_tables.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/table_arguments.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/converters/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/base.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/constellation.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/dataset.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/entity.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/reference.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/objects/wiki.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/py.typed +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/memory.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/operation.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/reference_resolution.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/registry.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/type_resolver.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/bundle.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/fragment.schema.json +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/generate.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/load.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/markdown.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/v1/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/v1/fragment.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/app.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/compile.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/errors.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/http.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/registry.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/serde.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/server/serve.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/__init__.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/composed_set.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/normalize.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/ordered_set.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/sql.py +0 -0
- {metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/utils/template.py +0 -0
|
@@ -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.
|
|
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
|
-
|
|
445
|
-
|
|
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
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/__init__.py
RENAMED
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/cluster.py
RENAMED
|
File without changes
|
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/metadata.py
RENAMED
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/passthrough.py
RENAMED
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/protocols.py
RENAMED
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/catalog/semantic.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_datasets.py
RENAMED
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_metadata.py
RENAMED
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/expand_per.py
RENAMED
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/rules/isolate_fragments.py
RENAMED
|
File without changes
|
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/compiler/table_arguments.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/registry/reference_resolution.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metricflow_sql-0.3.2 → metricflow_sql-0.3.3}/src/metricflow_sql/schemas/fragment.schema.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|