metricflow-sql 0.5.3__tar.gz → 0.5.5__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.5.3 → metricflow_sql-0.5.5}/PKG-INFO +2 -2
- metricflow_sql-0.5.5/pyproject.toml +123 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/compiler.py +4 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/guard.py +7 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/rules/constellation_permissions.py +2 -5
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/rules/expand_constellations.py +39 -9
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/rules/expand_datasets.py +389 -76
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/rules/expand_per.py +217 -13
- metricflow_sql-0.5.5/src/metricflow_sql/compiler/rules/nest_grouped_subqueries.py +125 -0
- metricflow_sql-0.5.5/src/metricflow_sql/compiler/rules/nest_windows.py +125 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/converters/legacy.py +2 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/converters/lookml.py +111 -5
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/objects/base.py +15 -1
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/objects/constellation.py +4 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/objects/dataset.py +9 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/objects/entity.py +1 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/registry/memory.py +93 -21
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/registry/registry.py +15 -4
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/registry/type_resolver.py +15 -6
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/schemas/fragment.schema.json +5 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/schemas/load.py +1 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/schemas/v1/fragment.py +9 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/server/serde.py +1 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/utils/sql.py +83 -12
- metricflow_sql-0.5.3/README.md +0 -3
- metricflow_sql-0.5.3/pyproject.toml +0 -50
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/.gitignore +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/LICENSE +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/PYPI.md +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/catalog/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/catalog/cluster.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/catalog/information_schema.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/catalog/metadata.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/catalog/passthrough.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/catalog/protocols.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/catalog/semantic.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/rules/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/rules/expand_fill.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/rules/expand_metadata.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/rules/isolate_fragments.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/rules/passthrough_tables.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/compiler/table_arguments.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/converters/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/objects/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/objects/reference.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/objects/wiki.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/py.typed +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/registry/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/registry/dao.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/registry/dependency_resolution.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/registry/operation.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/registry/reference_resolution.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/registry/resolved.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/schemas/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/schemas/bundle.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/schemas/generate.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/schemas/markdown.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/schemas/v1/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/server/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/server/app.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/server/compile.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/server/errors.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/server/http.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/server/registry.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/server/serve.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/utils/__init__.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/utils/composed_set.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/utils/normalize.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/src/metricflow_sql/utils/ordered_set.py +0 -0
- {metricflow_sql-0.5.3 → metricflow_sql-0.5.5}/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.5.
|
|
3
|
+
Version: 0.5.5
|
|
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
|
|
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
12
12
|
Requires-Python: >=3.12
|
|
13
13
|
Requires-Dist: jinja2>=3.1
|
|
14
14
|
Requires-Dist: msgspec>=0.19
|
|
15
|
-
Requires-Dist: sqlglot[c]>=30.
|
|
15
|
+
Requires-Dist: sqlglot[c]>=30.33.0
|
|
16
16
|
Requires-Dist: wenmode>=0.15.2
|
|
17
17
|
Provides-Extra: lookml
|
|
18
18
|
Requires-Dist: lkml>=1.3.7; extra == 'lookml'
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "metricflow-sql"
|
|
3
|
+
# A placeholder: a release sets its tag's version, with scripts/set_version.py.
|
|
4
|
+
version = "0.5.5"
|
|
5
|
+
description = "MetricFlow's core semantic layer engine"
|
|
6
|
+
# Its PyPI page: README.md is for this repository.
|
|
7
|
+
readme = "PYPI.md"
|
|
8
|
+
# Fivetran's own, in LICENSE, which no SPDX identifier names.
|
|
9
|
+
license = "LicenseRef-Fivetran"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Programming Language :: Python :: 3",
|
|
13
|
+
"Programming Language :: Python :: 3.12",
|
|
14
|
+
"Programming Language :: Python :: 3.13",
|
|
15
|
+
"Programming Language :: Python :: 3.14",
|
|
16
|
+
]
|
|
17
|
+
dependencies = [
|
|
18
|
+
"jinja2>=3.1",
|
|
19
|
+
"msgspec>=0.19",
|
|
20
|
+
"sqlglot[c]>=30.33.0",
|
|
21
|
+
"wenmode>=0.15.2",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.scripts]
|
|
25
|
+
metricflow-serve = "metricflow_sql.server.serve:main"
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
lookml = [
|
|
29
|
+
"lkml>=1.3.7",
|
|
30
|
+
]
|
|
31
|
+
yaml = [
|
|
32
|
+
"ruamel-yaml>=0.18",
|
|
33
|
+
]
|
|
34
|
+
# With ruamel-yaml, so a server reads every bundle: YAML fragments and pages' frontmatter. The
|
|
35
|
+
# sidecar's executable and the hosted service install this extra.
|
|
36
|
+
server = [
|
|
37
|
+
"ruamel-yaml>=0.18",
|
|
38
|
+
"starlette>=0.47.0",
|
|
39
|
+
"uvicorn>=0.34.0",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Documentation = "https://docs-internal-git-mfsql-dbt-labs.vercel.app/metricflow"
|
|
44
|
+
|
|
45
|
+
[build-system]
|
|
46
|
+
requires = ["hatchling"]
|
|
47
|
+
build-backend = "hatchling.build"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.wheel]
|
|
50
|
+
packages = ["src/metricflow_sql"]
|
|
51
|
+
|
|
52
|
+
# This directory also holds MetricFlow SQL's tests, docs, demos and scripts, for all its packages; the sdist is
|
|
53
|
+
# the library alone.
|
|
54
|
+
[tool.hatch.build.targets.sdist]
|
|
55
|
+
only-include = ["src"]
|
|
56
|
+
|
|
57
|
+
# metricflow-testing brings metricflow-service and every test dependency, so
|
|
58
|
+
# `uv sync --package metricflow-sql` can run each workspace package's suite; and the tools, for all
|
|
59
|
+
# of MetricFlow SQL's packages.
|
|
60
|
+
[dependency-groups]
|
|
61
|
+
dev = [
|
|
62
|
+
"metricflow-testing",
|
|
63
|
+
"mypy>=1.11",
|
|
64
|
+
"pre-commit>=4.0",
|
|
65
|
+
"ruff>=0.14",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[tool.uv.sources]
|
|
69
|
+
metricflow-testing = { workspace = true }
|
|
70
|
+
|
|
71
|
+
# MetricFlow SQL's packages extend this; the rest of the workspace keeps the root's rules.
|
|
72
|
+
[tool.ruff]
|
|
73
|
+
line-length = 100
|
|
74
|
+
target-version = "py312"
|
|
75
|
+
src = [
|
|
76
|
+
"src",
|
|
77
|
+
"../metricflow-service/src",
|
|
78
|
+
"../metricflow-testing/src",
|
|
79
|
+
"../dbt-metricflow/src",
|
|
80
|
+
"../metricflow-sidecar/src",
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
[tool.ruff.lint]
|
|
84
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
85
|
+
# E501 only fires where the formatter cannot reach, so it is always a manual fix.
|
|
86
|
+
ignore = ["E501"]
|
|
87
|
+
|
|
88
|
+
# Shared by MetricFlow SQL's workspace packages, which each check their own `src` and `tests`: each
|
|
89
|
+
# package's suite is a `tests` package, so one run can't hold two. `task mfsql:typecheck` runs them all.
|
|
90
|
+
[tool.mypy]
|
|
91
|
+
python_version = "3.12"
|
|
92
|
+
mypy_path = """$MYPY_CONFIG_FILE_DIR/src:$MYPY_CONFIG_FILE_DIR/../metricflow-service/src:\
|
|
93
|
+
$MYPY_CONFIG_FILE_DIR/../metricflow-testing/src"""
|
|
94
|
+
files = ["src", "tests"]
|
|
95
|
+
strict = true
|
|
96
|
+
pretty = true
|
|
97
|
+
disallow_any_generics = false
|
|
98
|
+
|
|
99
|
+
# pyarrow ships no type information.
|
|
100
|
+
[[tool.mypy.overrides]]
|
|
101
|
+
module = ["pyarrow", "pyarrow.*"]
|
|
102
|
+
ignore_missing_imports = true
|
|
103
|
+
|
|
104
|
+
# boto3 and botocore ship no type information.
|
|
105
|
+
[[tool.mypy.overrides]]
|
|
106
|
+
module = ["boto3", "botocore", "botocore.*"]
|
|
107
|
+
ignore_missing_imports = true
|
|
108
|
+
|
|
109
|
+
# Strawberry types `strawberry.field(...)` as a decorator `Any`.
|
|
110
|
+
[[tool.mypy.overrides]]
|
|
111
|
+
module = "metricflow_service.api.graphql"
|
|
112
|
+
disable_error_code = ["untyped-decorator"]
|
|
113
|
+
|
|
114
|
+
[[tool.mypy.overrides]]
|
|
115
|
+
module = "tests.*"
|
|
116
|
+
disallow_untyped_defs = false
|
|
117
|
+
|
|
118
|
+
# Each package's suite has these settings, apart from the root's: it imports its own helpers as
|
|
119
|
+
# `tests.*`, so runs on its own.
|
|
120
|
+
[tool.pytest.ini_options]
|
|
121
|
+
testpaths = ["tests"]
|
|
122
|
+
pythonpath = ["."]
|
|
123
|
+
addopts = ["--import-mode=importlib"]
|
|
@@ -34,6 +34,8 @@ from metricflow_sql.compiler.rules.expand_fill import expand_fills
|
|
|
34
34
|
from metricflow_sql.compiler.rules.expand_metadata import ENGINE, ExpandMetadataRule
|
|
35
35
|
from metricflow_sql.compiler.rules.expand_per import expand_per
|
|
36
36
|
from metricflow_sql.compiler.rules.isolate_fragments import isolate_fragments
|
|
37
|
+
from metricflow_sql.compiler.rules.nest_grouped_subqueries import nest_grouped_subqueries
|
|
38
|
+
from metricflow_sql.compiler.rules.nest_windows import nest_windows
|
|
37
39
|
from metricflow_sql.compiler.rules.passthrough_tables import name_passthrough_tables
|
|
38
40
|
from metricflow_sql.compiler.table_arguments import bind_table_arguments
|
|
39
41
|
from metricflow_sql.utils.normalize import normalizing_dialect
|
|
@@ -98,6 +100,8 @@ PLANNER_RULES: Sequence[OptimizerFn] = (
|
|
|
98
100
|
ExpandDatasetsRule(),
|
|
99
101
|
expand_per,
|
|
100
102
|
expand_fills,
|
|
103
|
+
nest_grouped_subqueries,
|
|
104
|
+
nest_windows,
|
|
101
105
|
)
|
|
102
106
|
|
|
103
107
|
|
|
@@ -28,6 +28,13 @@ GOVERNED = "governed"
|
|
|
28
28
|
TRUSTED = "trusted"
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
def trust(expression: exp.Expr) -> exp.Expr:
|
|
32
|
+
"""Marks each node of `expression` `TRUSTED`, in place."""
|
|
33
|
+
for node in expression.walk():
|
|
34
|
+
node.meta[TRUSTED] = True
|
|
35
|
+
return expression
|
|
36
|
+
|
|
37
|
+
|
|
31
38
|
class Denied(ValueError):
|
|
32
39
|
"""What a guard raises for something the caller can't use."""
|
|
33
40
|
|
|
@@ -7,7 +7,7 @@ from sqlglot.optimizer.scope import find_in_scope
|
|
|
7
7
|
|
|
8
8
|
from metricflow_sql.compiler.catalog.cluster import Cluster
|
|
9
9
|
from metricflow_sql.compiler.catalog.semantic import SemanticCatalog
|
|
10
|
-
from metricflow_sql.compiler.guard import
|
|
10
|
+
from metricflow_sql.compiler.guard import Guard, trust
|
|
11
11
|
from metricflow_sql.utils.sql import column_path, path_names, table_scopes
|
|
12
12
|
|
|
13
13
|
logger = logging.getLogger(__name__)
|
|
@@ -72,7 +72,4 @@ def trusted_condition(condition: exp.Expr, alias: exp.Identifier) -> exp.Expr:
|
|
|
72
72
|
return column_path(alias.copy(), *(name.copy() for name in path_names(node)))
|
|
73
73
|
return node
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
for node in qualified.walk():
|
|
77
|
-
node.meta[TRUSTED] = True
|
|
78
|
-
return qualified
|
|
75
|
+
return trust(condition.transform(qualify))
|
|
@@ -15,19 +15,27 @@ from sqlglot.optimizer.simplify import simplify_parens
|
|
|
15
15
|
from metricflow_sql.compiler.catalog.cluster import Cluster
|
|
16
16
|
from metricflow_sql.compiler.catalog.protocols import ColumnLike
|
|
17
17
|
from metricflow_sql.compiler.catalog.semantic import SemanticCatalog
|
|
18
|
-
from metricflow_sql.compiler.guard import GOVERNED, TRUSTED, Guard
|
|
18
|
+
from metricflow_sql.compiler.guard import GOVERNED, TRUSTED, Guard, trust
|
|
19
19
|
from metricflow_sql.compiler.rules.constellation_permissions import trusted_condition
|
|
20
|
-
from metricflow_sql.compiler.rules.expand_datasets import
|
|
20
|
+
from metricflow_sql.compiler.rules.expand_datasets import (
|
|
21
|
+
ExpandDatasetsRule,
|
|
22
|
+
bare_relationship_error,
|
|
23
|
+
)
|
|
21
24
|
from metricflow_sql.compiler.rules.expand_per import expand_over
|
|
22
25
|
from metricflow_sql.compiler.table_arguments import TABLE_ARGUMENTS
|
|
23
|
-
from metricflow_sql.objects.base import apply_mask
|
|
26
|
+
from metricflow_sql.objects.base import apply_mask, in_namespace
|
|
24
27
|
from metricflow_sql.objects.constellation import Metric, Role
|
|
25
28
|
from metricflow_sql.objects.dataset import Relationship
|
|
26
29
|
from metricflow_sql.registry.reference_resolution import (
|
|
27
30
|
resolve_metric,
|
|
28
31
|
resolve_metric_references,
|
|
29
32
|
)
|
|
30
|
-
from metricflow_sql.registry.registry import
|
|
33
|
+
from metricflow_sql.registry.registry import (
|
|
34
|
+
ConstellationProxy,
|
|
35
|
+
DatasetTarget,
|
|
36
|
+
EntityTarget,
|
|
37
|
+
Registry,
|
|
38
|
+
)
|
|
31
39
|
from metricflow_sql.utils.sql import (
|
|
32
40
|
column_path,
|
|
33
41
|
group_all_keys,
|
|
@@ -38,6 +46,7 @@ from metricflow_sql.utils.sql import (
|
|
|
38
46
|
normalize_group,
|
|
39
47
|
path_names,
|
|
40
48
|
per_argument,
|
|
49
|
+
ref_target,
|
|
41
50
|
table_scopes,
|
|
42
51
|
)
|
|
43
52
|
|
|
@@ -1167,10 +1176,7 @@ class ExpandConstellationsRule:
|
|
|
1167
1176
|
# TODO: let a bare reference role stand for its key, e.g. `customer IN (SELECT ...)`
|
|
1168
1177
|
# filtering on `customer.c_customer_sk`, or on `ss_customer_sk` without a join.
|
|
1169
1178
|
if is_reference:
|
|
1170
|
-
|
|
1171
|
-
self._fail(
|
|
1172
|
-
ctx, f"Use an attribute of the entity role {name}, e.g. {name}.<attribute>"
|
|
1173
|
-
)
|
|
1179
|
+
self._fail(ctx, self._use_an_attribute(ctx, role, field))
|
|
1174
1180
|
trusted = bool(node.meta.get(TRUSTED))
|
|
1175
1181
|
mask = self._mask(field, ctx) if field is not None and not trusted else None
|
|
1176
1182
|
return _replace(
|
|
@@ -1185,7 +1191,15 @@ class ExpandConstellationsRule:
|
|
|
1185
1191
|
)
|
|
1186
1192
|
return exp.Dot.build([assigned, *path])
|
|
1187
1193
|
|
|
1188
|
-
|
|
1194
|
+
def carry(node: exp.Expr) -> exp.Expr:
|
|
1195
|
+
# What stands for a role a permission reads is the permission's too: a condition
|
|
1196
|
+
# that is only a role, e.g. `where: is_public`, has no other node to tell it by.
|
|
1197
|
+
translated = rewrite(node)
|
|
1198
|
+
if translated is not node and node.meta.get(TRUSTED):
|
|
1199
|
+
trust(translated)
|
|
1200
|
+
return translated
|
|
1201
|
+
|
|
1202
|
+
return expr.transform(carry)
|
|
1189
1203
|
|
|
1190
1204
|
def _dataset(self, fact: exp.Table, ctx: ConstellationContext) -> exp.Table:
|
|
1191
1205
|
"""The dataset of the fact named `fact`, e.g. `events` for `visits`."""
|
|
@@ -1320,6 +1334,22 @@ class ExpandConstellationsRule:
|
|
|
1320
1334
|
return None
|
|
1321
1335
|
return ctx.constellation.get_column(column.this)
|
|
1322
1336
|
|
|
1337
|
+
def _use_an_attribute(
|
|
1338
|
+
self, ctx: ConstellationContext, role: exp.Identifier, field: ColumnLike | None
|
|
1339
|
+
) -> str:
|
|
1340
|
+
"""The error for a bare reference role, naming its target and the target's key."""
|
|
1341
|
+
name = self._sql(ctx, role)
|
|
1342
|
+
fallback = f"Use an attribute of the entity role {name}, e.g. {name}.<attribute>"
|
|
1343
|
+
target = ref_target(field.datatype) if field is not None else None
|
|
1344
|
+
if target is None:
|
|
1345
|
+
return fallback
|
|
1346
|
+
target = in_namespace(target, ctx.constellation.name.args["db"])
|
|
1347
|
+
if (entity := ctx.registry.get_entity(target)) is not None:
|
|
1348
|
+
return bare_relationship_error(role, EntityTarget(entity), ctx.registry.dialect)
|
|
1349
|
+
if (dataset := ctx.registry.get_dataset(target)) is not None:
|
|
1350
|
+
return bare_relationship_error(role, DatasetTarget(dataset), ctx.registry.dialect)
|
|
1351
|
+
return fallback
|
|
1352
|
+
|
|
1323
1353
|
def _sql(self, ctx: ConstellationContext, name: exp.Expr) -> str:
|
|
1324
1354
|
return name.sql(ctx.registry.dialect)
|
|
1325
1355
|
|