pytrilogy 0.0.1.102__py3-none-any.whl
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.
Potentially problematic release.
This version of pytrilogy might be problematic. Click here for more details.
- pytrilogy-0.0.1.102.dist-info/LICENSE.md +19 -0
- pytrilogy-0.0.1.102.dist-info/METADATA +277 -0
- pytrilogy-0.0.1.102.dist-info/RECORD +77 -0
- pytrilogy-0.0.1.102.dist-info/WHEEL +5 -0
- pytrilogy-0.0.1.102.dist-info/entry_points.txt +2 -0
- pytrilogy-0.0.1.102.dist-info/top_level.txt +1 -0
- trilogy/__init__.py +8 -0
- trilogy/compiler.py +0 -0
- trilogy/constants.py +30 -0
- trilogy/core/__init__.py +0 -0
- trilogy/core/constants.py +3 -0
- trilogy/core/enums.py +270 -0
- trilogy/core/env_processor.py +33 -0
- trilogy/core/environment_helpers.py +156 -0
- trilogy/core/ergonomics.py +187 -0
- trilogy/core/exceptions.py +23 -0
- trilogy/core/functions.py +320 -0
- trilogy/core/graph_models.py +55 -0
- trilogy/core/internal.py +37 -0
- trilogy/core/models.py +3145 -0
- trilogy/core/processing/__init__.py +0 -0
- trilogy/core/processing/concept_strategies_v3.py +603 -0
- trilogy/core/processing/graph_utils.py +44 -0
- trilogy/core/processing/node_generators/__init__.py +25 -0
- trilogy/core/processing/node_generators/basic_node.py +71 -0
- trilogy/core/processing/node_generators/common.py +239 -0
- trilogy/core/processing/node_generators/concept_merge.py +152 -0
- trilogy/core/processing/node_generators/filter_node.py +83 -0
- trilogy/core/processing/node_generators/group_node.py +92 -0
- trilogy/core/processing/node_generators/group_to_node.py +99 -0
- trilogy/core/processing/node_generators/merge_node.py +148 -0
- trilogy/core/processing/node_generators/multiselect_node.py +189 -0
- trilogy/core/processing/node_generators/rowset_node.py +130 -0
- trilogy/core/processing/node_generators/select_node.py +328 -0
- trilogy/core/processing/node_generators/unnest_node.py +37 -0
- trilogy/core/processing/node_generators/window_node.py +85 -0
- trilogy/core/processing/nodes/__init__.py +76 -0
- trilogy/core/processing/nodes/base_node.py +251 -0
- trilogy/core/processing/nodes/filter_node.py +49 -0
- trilogy/core/processing/nodes/group_node.py +110 -0
- trilogy/core/processing/nodes/merge_node.py +326 -0
- trilogy/core/processing/nodes/select_node_v2.py +198 -0
- trilogy/core/processing/nodes/unnest_node.py +54 -0
- trilogy/core/processing/nodes/window_node.py +34 -0
- trilogy/core/processing/utility.py +278 -0
- trilogy/core/query_processor.py +331 -0
- trilogy/dialect/__init__.py +0 -0
- trilogy/dialect/base.py +679 -0
- trilogy/dialect/bigquery.py +80 -0
- trilogy/dialect/common.py +43 -0
- trilogy/dialect/config.py +55 -0
- trilogy/dialect/duckdb.py +83 -0
- trilogy/dialect/enums.py +95 -0
- trilogy/dialect/postgres.py +86 -0
- trilogy/dialect/presto.py +82 -0
- trilogy/dialect/snowflake.py +82 -0
- trilogy/dialect/sql_server.py +89 -0
- trilogy/docs/__init__.py +0 -0
- trilogy/engine.py +48 -0
- trilogy/executor.py +242 -0
- trilogy/hooks/__init__.py +0 -0
- trilogy/hooks/base_hook.py +37 -0
- trilogy/hooks/graph_hook.py +24 -0
- trilogy/hooks/query_debugger.py +133 -0
- trilogy/metadata/__init__.py +0 -0
- trilogy/parser.py +10 -0
- trilogy/parsing/__init__.py +0 -0
- trilogy/parsing/common.py +176 -0
- trilogy/parsing/config.py +5 -0
- trilogy/parsing/exceptions.py +2 -0
- trilogy/parsing/helpers.py +1 -0
- trilogy/parsing/parse_engine.py +1951 -0
- trilogy/parsing/render.py +483 -0
- trilogy/py.typed +0 -0
- trilogy/scripts/__init__.py +0 -0
- trilogy/scripts/trilogy.py +127 -0
- trilogy/utility.py +31 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
from trilogy.core.models import (
|
|
2
|
+
AggregateWrapper,
|
|
3
|
+
Concept,
|
|
4
|
+
Function,
|
|
5
|
+
Grain,
|
|
6
|
+
Purpose,
|
|
7
|
+
Metadata,
|
|
8
|
+
FilterItem,
|
|
9
|
+
ListWrapper,
|
|
10
|
+
WindowItem,
|
|
11
|
+
)
|
|
12
|
+
from typing import List, Tuple
|
|
13
|
+
from trilogy.core.functions import (
|
|
14
|
+
function_args_to_output_purpose,
|
|
15
|
+
FunctionType,
|
|
16
|
+
arg_to_datatype,
|
|
17
|
+
)
|
|
18
|
+
from trilogy.utility import unique
|
|
19
|
+
from trilogy.core.enums import PurposeLineage
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_purpose_and_keys(
|
|
23
|
+
purpose: Purpose | None, args: Tuple[Concept, ...] | None
|
|
24
|
+
) -> Tuple[Purpose, Tuple[Concept, ...] | None]:
|
|
25
|
+
local_purpose = purpose or function_args_to_output_purpose(args)
|
|
26
|
+
if local_purpose in (Purpose.PROPERTY, Purpose.METRIC) and args:
|
|
27
|
+
keys = concept_list_to_keys(args)
|
|
28
|
+
else:
|
|
29
|
+
keys = None
|
|
30
|
+
return local_purpose, keys
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def concept_list_to_keys(concepts: Tuple[Concept, ...]) -> Tuple[Concept, ...]:
|
|
34
|
+
final_keys: List[Concept] = []
|
|
35
|
+
for concept in concepts:
|
|
36
|
+
if concept.keys:
|
|
37
|
+
final_keys += concept_list_to_keys(concept.keys)
|
|
38
|
+
elif concept.purpose != Purpose.PROPERTY:
|
|
39
|
+
final_keys.append(concept)
|
|
40
|
+
return tuple(unique(final_keys, "address"))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def constant_to_concept(
|
|
44
|
+
parent: ListWrapper | int | float | str,
|
|
45
|
+
name: str,
|
|
46
|
+
namespace: str,
|
|
47
|
+
purpose: Purpose | None = None,
|
|
48
|
+
metadata: Metadata | None = None,
|
|
49
|
+
) -> Concept:
|
|
50
|
+
const_function: Function = Function(
|
|
51
|
+
operator=FunctionType.CONSTANT,
|
|
52
|
+
output_datatype=arg_to_datatype(parent),
|
|
53
|
+
output_purpose=Purpose.CONSTANT,
|
|
54
|
+
arguments=[parent],
|
|
55
|
+
)
|
|
56
|
+
return Concept(
|
|
57
|
+
name=name,
|
|
58
|
+
datatype=const_function.output_datatype,
|
|
59
|
+
purpose=Purpose.CONSTANT,
|
|
60
|
+
lineage=const_function,
|
|
61
|
+
grain=const_function.output_grain,
|
|
62
|
+
namespace=namespace,
|
|
63
|
+
metadata=metadata,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def function_to_concept(parent: Function, name: str, namespace: str) -> Concept:
|
|
68
|
+
pkeys = []
|
|
69
|
+
for x in parent.arguments:
|
|
70
|
+
pkeys += [
|
|
71
|
+
x
|
|
72
|
+
for x in parent.concept_arguments
|
|
73
|
+
if not x.derivation == PurposeLineage.CONSTANT
|
|
74
|
+
]
|
|
75
|
+
grain = Grain()
|
|
76
|
+
for x in pkeys:
|
|
77
|
+
grain += x.grain
|
|
78
|
+
|
|
79
|
+
key_grain = []
|
|
80
|
+
for x in pkeys:
|
|
81
|
+
if x.keys:
|
|
82
|
+
key_grain += [*x.keys]
|
|
83
|
+
else:
|
|
84
|
+
key_grain.append(x)
|
|
85
|
+
keys = tuple(Grain(components=key_grain).components_copy)
|
|
86
|
+
if not pkeys:
|
|
87
|
+
purpose = Purpose.CONSTANT
|
|
88
|
+
else:
|
|
89
|
+
purpose = parent.output_purpose
|
|
90
|
+
return Concept(
|
|
91
|
+
name=name,
|
|
92
|
+
datatype=parent.output_datatype,
|
|
93
|
+
purpose=purpose,
|
|
94
|
+
lineage=parent,
|
|
95
|
+
namespace=namespace,
|
|
96
|
+
grain=grain,
|
|
97
|
+
keys=keys,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def filter_item_to_concept(
|
|
102
|
+
parent: FilterItem,
|
|
103
|
+
name: str,
|
|
104
|
+
namespace: str,
|
|
105
|
+
purpose: Purpose | None = None,
|
|
106
|
+
metadata: Metadata | None = None,
|
|
107
|
+
) -> Concept:
|
|
108
|
+
|
|
109
|
+
return Concept(
|
|
110
|
+
name=name,
|
|
111
|
+
datatype=parent.content.datatype,
|
|
112
|
+
purpose=parent.content.purpose,
|
|
113
|
+
lineage=parent,
|
|
114
|
+
metadata=metadata,
|
|
115
|
+
namespace=namespace,
|
|
116
|
+
# filtered copies cannot inherit keys
|
|
117
|
+
keys=None,
|
|
118
|
+
grain=(
|
|
119
|
+
parent.content.grain
|
|
120
|
+
if parent.content.purpose == Purpose.PROPERTY
|
|
121
|
+
else Grain()
|
|
122
|
+
),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def window_item_to_concept(
|
|
127
|
+
parent: WindowItem,
|
|
128
|
+
name: str,
|
|
129
|
+
namespace: str,
|
|
130
|
+
purpose: Purpose | None = None,
|
|
131
|
+
metadata: Metadata | None = None,
|
|
132
|
+
) -> Concept:
|
|
133
|
+
local_purpose, keys = get_purpose_and_keys(purpose, (parent.content,))
|
|
134
|
+
if parent.order_by:
|
|
135
|
+
grain = parent.over + [parent.content.output]
|
|
136
|
+
for item in parent.order_by:
|
|
137
|
+
grain += [item.expr.output]
|
|
138
|
+
else:
|
|
139
|
+
grain = parent.over + [parent.content.output]
|
|
140
|
+
return Concept(
|
|
141
|
+
name=name,
|
|
142
|
+
datatype=parent.content.datatype,
|
|
143
|
+
purpose=local_purpose,
|
|
144
|
+
lineage=parent,
|
|
145
|
+
metadata=metadata,
|
|
146
|
+
# filters are implicitly at the grain of the base item
|
|
147
|
+
grain=Grain(components=grain),
|
|
148
|
+
namespace=namespace,
|
|
149
|
+
keys=keys,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def agg_wrapper_to_concept(
|
|
154
|
+
parent: AggregateWrapper,
|
|
155
|
+
namespace: str,
|
|
156
|
+
name: str,
|
|
157
|
+
metadata: Metadata | None = None,
|
|
158
|
+
purpose: Purpose | None = None,
|
|
159
|
+
) -> Concept:
|
|
160
|
+
local_purpose, keys = get_purpose_and_keys(
|
|
161
|
+
Purpose.METRIC, tuple(parent.by) if parent.by else None
|
|
162
|
+
)
|
|
163
|
+
# anything grouped to a grain should be a property
|
|
164
|
+
# at that grain
|
|
165
|
+
aggfunction = parent.function
|
|
166
|
+
out = Concept(
|
|
167
|
+
name=name,
|
|
168
|
+
datatype=aggfunction.output_datatype,
|
|
169
|
+
purpose=Purpose.METRIC,
|
|
170
|
+
metadata=metadata,
|
|
171
|
+
lineage=parent,
|
|
172
|
+
grain=Grain(components=parent.by) if parent.by else Grain(),
|
|
173
|
+
namespace=namespace,
|
|
174
|
+
keys=tuple(parent.by) if parent.by else keys,
|
|
175
|
+
)
|
|
176
|
+
return out
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|