pytrilogy 0.0.1.116__tar.gz → 0.0.1.117__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.
Potentially problematic release.
This version of pytrilogy might be problematic. Click here for more details.
- {pytrilogy-0.0.1.116/pytrilogy.egg-info → pytrilogy-0.0.1.117}/PKG-INFO +1 -1
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117/pytrilogy.egg-info}/PKG-INFO +1 -1
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/pytrilogy.egg-info/SOURCES.txt +1 -0
- pytrilogy-0.0.1.117/tests/test_datatypes.py +13 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/__init__.py +1 -1
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/functions.py +5 -4
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/models.py +28 -8
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/optimization.py +19 -19
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/optimizations/predicate_pushdown.py +22 -5
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/base.py +5 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/presto.py +3 -1
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/parsing/parse_engine.py +12 -2
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/parsing/render.py +5 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/parsing/trilogy.lark +5 -3
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/LICENSE.md +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/README.md +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/pyproject.toml +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/pytrilogy.egg-info/dependency_links.txt +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/pytrilogy.egg-info/entry_points.txt +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/pytrilogy.egg-info/requires.txt +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/pytrilogy.egg-info/top_level.txt +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/setup.cfg +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/setup.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_declarations.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_derived_concepts.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_discovery_nodes.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_environment.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_functions.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_imports.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_metadata.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_models.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_multi_join_assignments.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_parsing.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_partial_handling.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_query_processing.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_select.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_statements.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_undefined_concept.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/tests/test_where_clause.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/compiler.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/constants.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/__init__.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/constants.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/enums.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/env_processor.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/environment_helpers.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/ergonomics.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/exceptions.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/graph_models.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/internal.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/optimizations/__init__.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/optimizations/base_optimization.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/optimizations/inline_constant.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/optimizations/inline_datasource.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/__init__.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/concept_strategies_v3.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/graph_utils.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/__init__.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/basic_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/common.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/concept_merge_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/filter_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/group_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/group_to_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/multiselect_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/node_merge_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/rowset_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/select_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/unnest_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/window_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/nodes/__init__.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/nodes/base_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/nodes/filter_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/nodes/group_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/nodes/merge_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/nodes/select_node_v2.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/nodes/unnest_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/nodes/window_node.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/utility.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/query_processor.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/__init__.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/bigquery.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/common.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/config.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/duckdb.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/enums.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/postgres.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/snowflake.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/dialect/sql_server.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/engine.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/executor.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/hooks/__init__.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/hooks/base_hook.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/hooks/graph_hook.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/hooks/query_debugger.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/metadata/__init__.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/parser.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/parsing/__init__.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/parsing/common.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/parsing/config.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/parsing/exceptions.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/parsing/helpers.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/py.typed +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/scripts/__init__.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/scripts/trilogy.py +0 -0
- {pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/utility.py +0 -0
|
@@ -8,6 +8,7 @@ pytrilogy.egg-info/dependency_links.txt
|
|
|
8
8
|
pytrilogy.egg-info/entry_points.txt
|
|
9
9
|
pytrilogy.egg-info/requires.txt
|
|
10
10
|
pytrilogy.egg-info/top_level.txt
|
|
11
|
+
tests/test_datatypes.py
|
|
11
12
|
tests/test_declarations.py
|
|
12
13
|
tests/test_derived_concepts.py
|
|
13
14
|
tests/test_discovery_nodes.py
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from trilogy.core.models import (
|
|
2
|
+
NumericType,
|
|
3
|
+
)
|
|
4
|
+
from trilogy.parsing.parse_engine import (
|
|
5
|
+
parse_text,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_numeric():
|
|
10
|
+
env, _ = parse_text(
|
|
11
|
+
"const order_id numeric(12,2); const rounded <- cast(order_id as numeric(15,2));"
|
|
12
|
+
)
|
|
13
|
+
assert env.concepts["order_id"].datatype == NumericType(precision=12, scale=2)
|
|
@@ -9,6 +9,7 @@ from trilogy.core.models import (
|
|
|
9
9
|
ListType,
|
|
10
10
|
StructType,
|
|
11
11
|
MapType,
|
|
12
|
+
NumericType,
|
|
12
13
|
)
|
|
13
14
|
from trilogy.core.enums import FunctionType, Purpose, Granularity, DatePart
|
|
14
15
|
from trilogy.core.exceptions import InvalidSyntaxException
|
|
@@ -21,7 +22,9 @@ def create_function_derived_concept(
|
|
|
21
22
|
namespace: str,
|
|
22
23
|
operator: FunctionType,
|
|
23
24
|
arguments: list[Concept],
|
|
24
|
-
output_type: Optional[
|
|
25
|
+
output_type: Optional[
|
|
26
|
+
DataType | ListType | StructType | MapType | NumericType
|
|
27
|
+
] = None,
|
|
25
28
|
output_purpose: Optional[Purpose] = None,
|
|
26
29
|
) -> Concept:
|
|
27
30
|
purpose = (
|
|
@@ -56,9 +59,7 @@ def argument_to_purpose(arg) -> Purpose:
|
|
|
56
59
|
return Purpose.PROPERTY
|
|
57
60
|
elif isinstance(arg, Concept):
|
|
58
61
|
return arg.purpose
|
|
59
|
-
elif isinstance(arg, (int, float, str, bool, list)):
|
|
60
|
-
return Purpose.CONSTANT
|
|
61
|
-
elif isinstance(arg, DataType):
|
|
62
|
+
elif isinstance(arg, (int, float, str, bool, list, NumericType, DataType)):
|
|
62
63
|
return Purpose.CONSTANT
|
|
63
64
|
elif isinstance(arg, DatePart):
|
|
64
65
|
return Purpose.CONSTANT
|
|
@@ -105,7 +105,9 @@ def get_concept_arguments(expr) -> List["Concept"]:
|
|
|
105
105
|
return output
|
|
106
106
|
|
|
107
107
|
|
|
108
|
-
ALL_TYPES = Union[
|
|
108
|
+
ALL_TYPES = Union[
|
|
109
|
+
"DataType", "MapType", "ListType", "NumericType", "StructType", "Concept"
|
|
110
|
+
]
|
|
109
111
|
|
|
110
112
|
NAMESPACED_TYPES = Union[
|
|
111
113
|
"WindowItem",
|
|
@@ -176,6 +178,19 @@ class DataType(Enum):
|
|
|
176
178
|
return self
|
|
177
179
|
|
|
178
180
|
|
|
181
|
+
class NumericType(BaseModel):
|
|
182
|
+
precision: int = 20
|
|
183
|
+
scale: int = 5
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def data_type(self):
|
|
187
|
+
return DataType.NUMERIC
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def value(self):
|
|
191
|
+
return self.data_type.value
|
|
192
|
+
|
|
193
|
+
|
|
179
194
|
class ListType(BaseModel):
|
|
180
195
|
model_config = ConfigDict(frozen=True)
|
|
181
196
|
type: ALL_TYPES
|
|
@@ -192,7 +207,9 @@ class ListType(BaseModel):
|
|
|
192
207
|
return self.data_type.value
|
|
193
208
|
|
|
194
209
|
@property
|
|
195
|
-
def value_data_type(
|
|
210
|
+
def value_data_type(
|
|
211
|
+
self,
|
|
212
|
+
) -> DataType | StructType | MapType | ListType | NumericType:
|
|
196
213
|
if isinstance(self.type, Concept):
|
|
197
214
|
return self.type.datatype
|
|
198
215
|
return self.type
|
|
@@ -270,7 +287,7 @@ def empty_grain() -> Grain:
|
|
|
270
287
|
|
|
271
288
|
class Concept(Namespaced, SelectGrain, BaseModel):
|
|
272
289
|
name: str
|
|
273
|
-
datatype: DataType | ListType | StructType | MapType
|
|
290
|
+
datatype: DataType | ListType | StructType | MapType | NumericType
|
|
274
291
|
purpose: Purpose
|
|
275
292
|
metadata: Optional[Metadata] = Field(
|
|
276
293
|
default_factory=lambda: Metadata(description=None, line_number=None),
|
|
@@ -790,12 +807,12 @@ class LooseConceptList(BaseModel):
|
|
|
790
807
|
class Function(Namespaced, SelectGrain, BaseModel):
|
|
791
808
|
operator: FunctionType
|
|
792
809
|
arg_count: int = Field(default=1)
|
|
793
|
-
output_datatype: DataType | ListType | StructType | MapType
|
|
810
|
+
output_datatype: DataType | ListType | StructType | MapType | NumericType
|
|
794
811
|
output_purpose: Purpose
|
|
795
812
|
valid_inputs: Optional[
|
|
796
813
|
Union[
|
|
797
|
-
Set[DataType | ListType | StructType],
|
|
798
|
-
List[Set[DataType | ListType | StructType]],
|
|
814
|
+
Set[DataType | ListType | StructType | NumericType],
|
|
815
|
+
List[Set[DataType | ListType | StructType] | NumericType],
|
|
799
816
|
]
|
|
800
817
|
] = None
|
|
801
818
|
arguments: Sequence[
|
|
@@ -808,6 +825,7 @@ class Function(Namespaced, SelectGrain, BaseModel):
|
|
|
808
825
|
str,
|
|
809
826
|
DataType,
|
|
810
827
|
ListType,
|
|
828
|
+
NumericType,
|
|
811
829
|
DatePart,
|
|
812
830
|
"Parenthetical",
|
|
813
831
|
CaseWhen,
|
|
@@ -1499,7 +1517,7 @@ class DatasourceMetadata(BaseModel):
|
|
|
1499
1517
|
|
|
1500
1518
|
class MergeStatement(Namespaced, BaseModel):
|
|
1501
1519
|
concepts: List[Concept]
|
|
1502
|
-
datatype: DataType | ListType | StructType | MapType
|
|
1520
|
+
datatype: DataType | ListType | StructType | MapType | NumericType
|
|
1503
1521
|
|
|
1504
1522
|
@cached_property
|
|
1505
1523
|
def concepts_lcl(self):
|
|
@@ -3498,7 +3516,7 @@ def list_to_wrapper(args):
|
|
|
3498
3516
|
return ListWrapper(args, type=types[0])
|
|
3499
3517
|
|
|
3500
3518
|
|
|
3501
|
-
def arg_to_datatype(arg) -> DataType | ListType | StructType | MapType:
|
|
3519
|
+
def arg_to_datatype(arg) -> DataType | ListType | StructType | MapType | NumericType:
|
|
3502
3520
|
if isinstance(arg, Function):
|
|
3503
3521
|
return arg.output_datatype
|
|
3504
3522
|
elif isinstance(arg, Concept):
|
|
@@ -3511,6 +3529,8 @@ def arg_to_datatype(arg) -> DataType | ListType | StructType | MapType:
|
|
|
3511
3529
|
return DataType.STRING
|
|
3512
3530
|
elif isinstance(arg, float):
|
|
3513
3531
|
return DataType.FLOAT
|
|
3532
|
+
elif isinstance(arg, NumericType):
|
|
3533
|
+
return arg
|
|
3514
3534
|
elif isinstance(arg, ListWrapper):
|
|
3515
3535
|
return ListType(type=arg.type)
|
|
3516
3536
|
elif isinstance(arg, AggregateWrapper):
|
|
@@ -50,7 +50,9 @@ def is_direct_return_eligible(
|
|
|
50
50
|
if isinstance(select, (PersistStatement, MultiSelectStatement)):
|
|
51
51
|
return False
|
|
52
52
|
derived_concepts = [
|
|
53
|
-
c
|
|
53
|
+
c
|
|
54
|
+
for c in cte.source.output_concepts + cte.source.hidden_concepts
|
|
55
|
+
if c not in cte.source.input_concepts
|
|
54
56
|
]
|
|
55
57
|
eligible = True
|
|
56
58
|
conditions = (
|
|
@@ -90,26 +92,9 @@ def sort_select_output(cte: CTE, query: SelectStatement | MultiSelectStatement):
|
|
|
90
92
|
|
|
91
93
|
def optimize_ctes(
|
|
92
94
|
input: list[CTE], root_cte: CTE, select: SelectStatement | MultiSelectStatement
|
|
93
|
-
):
|
|
95
|
+
) -> list[CTE]:
|
|
94
96
|
complete = False
|
|
95
97
|
REGISTERED_RULES: list["OptimizationRule"] = []
|
|
96
|
-
|
|
97
|
-
if CONFIG.optimizations.datasource_inlining:
|
|
98
|
-
REGISTERED_RULES.append(InlineDatasource())
|
|
99
|
-
if CONFIG.optimizations.predicate_pushdown:
|
|
100
|
-
REGISTERED_RULES.append(PredicatePushdown())
|
|
101
|
-
if CONFIG.optimizations.constant_inlining:
|
|
102
|
-
REGISTERED_RULES.append(InlineConstant())
|
|
103
|
-
loops = 0
|
|
104
|
-
while not complete and (loops <= MAX_OPTIMIZATION_LOOPS):
|
|
105
|
-
actions_taken = False
|
|
106
|
-
for rule in REGISTERED_RULES:
|
|
107
|
-
for cte in input:
|
|
108
|
-
inverse_map = gen_inverse_map(input)
|
|
109
|
-
actions_taken = rule.optimize(cte, inverse_map)
|
|
110
|
-
complete = not actions_taken
|
|
111
|
-
loops += 1
|
|
112
|
-
|
|
113
98
|
if CONFIG.optimizations.direct_return and is_direct_return_eligible(
|
|
114
99
|
root_cte, select
|
|
115
100
|
):
|
|
@@ -127,5 +112,20 @@ def optimize_ctes(
|
|
|
127
112
|
root_cte.condition = select.where_clause.conditional
|
|
128
113
|
root_cte.requires_nesting = False
|
|
129
114
|
sort_select_output(root_cte, select)
|
|
115
|
+
if CONFIG.optimizations.datasource_inlining:
|
|
116
|
+
REGISTERED_RULES.append(InlineDatasource())
|
|
117
|
+
if CONFIG.optimizations.predicate_pushdown:
|
|
118
|
+
REGISTERED_RULES.append(PredicatePushdown())
|
|
119
|
+
if CONFIG.optimizations.constant_inlining:
|
|
120
|
+
REGISTERED_RULES.append(InlineConstant())
|
|
121
|
+
loops = 0
|
|
122
|
+
while not complete and (loops <= MAX_OPTIMIZATION_LOOPS):
|
|
123
|
+
actions_taken = False
|
|
124
|
+
for rule in REGISTERED_RULES:
|
|
125
|
+
for cte in input:
|
|
126
|
+
inverse_map = gen_inverse_map(input)
|
|
127
|
+
actions_taken = actions_taken or rule.optimize(cte, inverse_map)
|
|
128
|
+
complete = not actions_taken
|
|
129
|
+
loops += 1
|
|
130
130
|
|
|
131
131
|
return filter_irrelevant_ctes(input, root_cte)
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/optimizations/predicate_pushdown.py
RENAMED
|
@@ -2,8 +2,8 @@ from trilogy.core.models import (
|
|
|
2
2
|
CTE,
|
|
3
3
|
Conditional,
|
|
4
4
|
BooleanOperator,
|
|
5
|
+
Datasource,
|
|
5
6
|
)
|
|
6
|
-
from trilogy.constants import logger
|
|
7
7
|
from trilogy.core.optimizations.base_optimization import OptimizationRule
|
|
8
8
|
|
|
9
9
|
|
|
@@ -48,16 +48,31 @@ class PredicatePushdown(OptimizationRule):
|
|
|
48
48
|
candidates = cte.condition.decompose()
|
|
49
49
|
else:
|
|
50
50
|
candidates = [cte.condition]
|
|
51
|
-
|
|
51
|
+
self.log(f"Have {len(candidates)} candidates to try to push down")
|
|
52
52
|
for candidate in candidates:
|
|
53
53
|
conditions = {x.address for x in candidate.concept_arguments}
|
|
54
54
|
for parent_cte in cte.parent_ctes:
|
|
55
|
+
if is_child_of(cte.condition, parent_cte.condition):
|
|
56
|
+
continue
|
|
55
57
|
materialized = {k for k, v in parent_cte.source_map.items() if v != []}
|
|
58
|
+
# if it's a root datasource, we can filter on _any_ of the output concepts
|
|
59
|
+
if parent_cte.is_root_datasource:
|
|
60
|
+
extra_check = {
|
|
61
|
+
x.address
|
|
62
|
+
for x in parent_cte.source.datasources[0].output_concepts
|
|
63
|
+
}
|
|
64
|
+
if conditions.issubset(extra_check):
|
|
65
|
+
for x in conditions:
|
|
66
|
+
if x not in materialized:
|
|
67
|
+
materialized.add(x)
|
|
68
|
+
parent_cte.source_map[x] = [
|
|
69
|
+
parent_cte.source.datasources[0].name
|
|
70
|
+
]
|
|
56
71
|
if conditions.issubset(materialized):
|
|
57
72
|
if all(
|
|
58
73
|
[
|
|
59
74
|
is_child_of(candidate, child.condition)
|
|
60
|
-
for child in inverse_map
|
|
75
|
+
for child in inverse_map.get(parent_cte.name, [])
|
|
61
76
|
]
|
|
62
77
|
):
|
|
63
78
|
self.log(
|
|
@@ -73,14 +88,16 @@ class PredicatePushdown(OptimizationRule):
|
|
|
73
88
|
parent_cte.condition = candidate
|
|
74
89
|
optimized = True
|
|
75
90
|
else:
|
|
76
|
-
|
|
91
|
+
self.log(
|
|
92
|
+
f"conditions {conditions} not subset of parent {parent_cte.name} parent has {materialized} "
|
|
93
|
+
)
|
|
77
94
|
|
|
78
95
|
if all(
|
|
79
96
|
[
|
|
80
97
|
is_child_of(cte.condition, parent_cte.condition)
|
|
81
98
|
for parent_cte in cte.parent_ctes
|
|
82
99
|
]
|
|
83
|
-
):
|
|
100
|
+
) and not any([isinstance(x, Datasource) for x in cte.source.datasources]):
|
|
84
101
|
self.log("All parents have same filter, removing filter")
|
|
85
102
|
cte.condition = None
|
|
86
103
|
optimized = True
|
|
@@ -46,6 +46,7 @@ from trilogy.core.models import (
|
|
|
46
46
|
ImportStatement,
|
|
47
47
|
RawSQLStatement,
|
|
48
48
|
ProcessedRawSQLStatement,
|
|
49
|
+
NumericType,
|
|
49
50
|
)
|
|
50
51
|
from trilogy.core.query_processor import process_query, process_persist
|
|
51
52
|
from trilogy.dialect.common import render_join
|
|
@@ -97,6 +98,7 @@ DATATYPE_MAP = {
|
|
|
97
98
|
DataType.INTEGER: "int",
|
|
98
99
|
DataType.FLOAT: "float",
|
|
99
100
|
DataType.BOOL: "bool",
|
|
101
|
+
DataType.NUMERIC: "numeric",
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
|
|
@@ -334,6 +336,7 @@ class BaseDialect:
|
|
|
334
336
|
Parenthetical,
|
|
335
337
|
AggregateWrapper,
|
|
336
338
|
MagicConstants,
|
|
339
|
+
NumericType,
|
|
337
340
|
ListType,
|
|
338
341
|
ListWrapper[int],
|
|
339
342
|
ListWrapper[str],
|
|
@@ -439,6 +442,8 @@ class BaseDialect:
|
|
|
439
442
|
return str(e.value)
|
|
440
443
|
elif isinstance(e, DatePart):
|
|
441
444
|
return str(e.value)
|
|
445
|
+
elif isinstance(e, NumericType):
|
|
446
|
+
return f"{self.DATATYPE_MAP[DataType.NUMERIC]}({e.precision},{e.scale})"
|
|
442
447
|
elif isinstance(e, MagicConstants):
|
|
443
448
|
if e == MagicConstants.NULL:
|
|
444
449
|
return "null"
|
|
@@ -4,6 +4,7 @@ from jinja2 import Template
|
|
|
4
4
|
|
|
5
5
|
from trilogy.core.enums import FunctionType, WindowType
|
|
6
6
|
from trilogy.dialect.base import BaseDialect
|
|
7
|
+
from trilogy.core.models import DataType
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
WINDOW_FUNCTION_MAP: Mapping[WindowType, Callable[[Any, Any, Any], str]] = {}
|
|
@@ -26,7 +27,7 @@ FUNCTION_MAP = {
|
|
|
26
27
|
FunctionType.WEEK: lambda x: f"EXTRACT(WEEK from {x[0]})",
|
|
27
28
|
FunctionType.QUARTER: lambda x: f"EXTRACT(QUARTER from {x[0]})",
|
|
28
29
|
# math
|
|
29
|
-
FunctionType.DIVIDE: lambda x: f"
|
|
30
|
+
FunctionType.DIVIDE: lambda x: f"{x[0]}/{x[1]}",
|
|
30
31
|
FunctionType.DATE_ADD: lambda x: f"DATE_ADD('{x[1]}', {x[2]}, {x[0]})",
|
|
31
32
|
FunctionType.CURRENT_DATE: lambda x: "CURRENT_DATE",
|
|
32
33
|
FunctionType.CURRENT_DATETIME: lambda x: "CURRENT_TIMESTAMP",
|
|
@@ -80,6 +81,7 @@ class PrestoDialect(BaseDialect):
|
|
|
80
81
|
}
|
|
81
82
|
QUOTE_CHARACTER = '"'
|
|
82
83
|
SQL_TEMPLATE = SQL_TEMPLATE
|
|
84
|
+
DATATYPE_MAP = {**BaseDialect.DATATYPE_MAP, DataType.NUMERIC: "DECIMAL"}
|
|
83
85
|
|
|
84
86
|
|
|
85
87
|
class TrinoDialect(PrestoDialect):
|
|
@@ -103,6 +103,7 @@ from trilogy.core.models import (
|
|
|
103
103
|
RowsetDerivationStatement,
|
|
104
104
|
LooseConceptList,
|
|
105
105
|
list_to_wrapper,
|
|
106
|
+
NumericType,
|
|
106
107
|
)
|
|
107
108
|
from trilogy.parsing.exceptions import ParseError
|
|
108
109
|
from trilogy.utility import string_to_hash
|
|
@@ -309,7 +310,9 @@ class ParseToObjects(Transformer):
|
|
|
309
310
|
|
|
310
311
|
@v_args(meta=True)
|
|
311
312
|
def struct_type(self, meta: Meta, args) -> StructType:
|
|
312
|
-
final: list[
|
|
313
|
+
final: list[
|
|
314
|
+
DataType | MapType | ListType | StructType | NumericType | Concept
|
|
315
|
+
] = []
|
|
313
316
|
for arg in args:
|
|
314
317
|
if not isinstance(arg, (DataType, ListType, StructType)):
|
|
315
318
|
new = self.environment.concepts.__getitem__( # type: ignore
|
|
@@ -323,12 +326,17 @@ class ParseToObjects(Transformer):
|
|
|
323
326
|
def list_type(self, args) -> ListType:
|
|
324
327
|
return ListType(type=args[0])
|
|
325
328
|
|
|
326
|
-
def
|
|
329
|
+
def numeric_type(self, args) -> NumericType:
|
|
330
|
+
return NumericType(precision=args[0], scale=args[1])
|
|
331
|
+
|
|
332
|
+
def data_type(self, args) -> DataType | ListType | StructType | NumericType:
|
|
327
333
|
resolved = args[0]
|
|
328
334
|
if isinstance(resolved, StructType):
|
|
329
335
|
return resolved
|
|
330
336
|
elif isinstance(resolved, ListType):
|
|
331
337
|
return resolved
|
|
338
|
+
elif isinstance(resolved, NumericType):
|
|
339
|
+
return resolved
|
|
332
340
|
return DataType(args[0].lower())
|
|
333
341
|
|
|
334
342
|
def array_comparison(self, args) -> ComparisonOperator:
|
|
@@ -1551,6 +1559,8 @@ class ParseToObjects(Transformer):
|
|
|
1551
1559
|
DataType.STRING,
|
|
1552
1560
|
DataType.FLOAT,
|
|
1553
1561
|
DataType.NUMBER,
|
|
1562
|
+
DataType.NUMERIC,
|
|
1563
|
+
DataType.BOOL,
|
|
1554
1564
|
},
|
|
1555
1565
|
arg_count=2,
|
|
1556
1566
|
)
|
|
@@ -39,6 +39,7 @@ from trilogy.core.models import (
|
|
|
39
39
|
AlignClause,
|
|
40
40
|
AlignItem,
|
|
41
41
|
RawSQLStatement,
|
|
42
|
+
NumericType,
|
|
42
43
|
)
|
|
43
44
|
from trilogy.core.enums import Modifier
|
|
44
45
|
|
|
@@ -172,6 +173,10 @@ class Renderer:
|
|
|
172
173
|
def _(self, arg: DataType):
|
|
173
174
|
return arg.value
|
|
174
175
|
|
|
176
|
+
@to_string.register
|
|
177
|
+
def _(self, arg: "NumericType"):
|
|
178
|
+
return f"""Numeric({arg.precision},{arg.scale})"""
|
|
179
|
+
|
|
175
180
|
@to_string.register
|
|
176
181
|
def _(self, arg: ListWrapper):
|
|
177
182
|
return "[" + ", ".join([self.to_string(x) for x in arg]) + "]"
|
|
@@ -280,12 +280,14 @@
|
|
|
280
280
|
|
|
281
281
|
SHORTHAND_MODIFIER: "~"
|
|
282
282
|
|
|
283
|
-
struct_type: "struct" "<" ((data_type | IDENTIFIER) ",")* (data_type | IDENTIFIER) ","? ">"
|
|
283
|
+
struct_type: "struct"i "<" ((data_type | IDENTIFIER) ",")* (data_type | IDENTIFIER) ","? ">"
|
|
284
284
|
|
|
285
|
-
list_type: "list" "<" data_type ">"
|
|
285
|
+
list_type: "list"i "<" data_type ">"
|
|
286
286
|
|
|
287
|
+
numeric_type: "numeric"i "(" int_lit "," int_lit ")"
|
|
287
288
|
|
|
288
|
-
|
|
289
|
+
|
|
290
|
+
!data_type: "string"i | "number"i | "numeric"i | "map"i | "list"i | "array"i | "any"i | "int"i | "bigint"i | "date"i | "datetime"i | "timestamp"i | "float"i | "bool"i | numeric_type | struct_type | list_type
|
|
289
291
|
|
|
290
292
|
PURPOSE: "key"i | "metric"i | CONST
|
|
291
293
|
PROPERTY: "property"i
|
|
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
|
|
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
|
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/concept_strategies_v3.py
RENAMED
|
File without changes
|
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/__init__.py
RENAMED
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/basic_node.py
RENAMED
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/common.py
RENAMED
|
File without changes
|
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/filter_node.py
RENAMED
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/group_node.py
RENAMED
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/group_to_node.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/rowset_node.py
RENAMED
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/select_node.py
RENAMED
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/unnest_node.py
RENAMED
|
File without changes
|
{pytrilogy-0.0.1.116 → pytrilogy-0.0.1.117}/trilogy/core/processing/node_generators/window_node.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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|