industrial-model 0.1.31__tar.gz → 0.1.33__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.
- {industrial_model-0.1.31 → industrial_model-0.1.33}/PKG-INFO +1 -1
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/__init__.py +3 -1
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/aggregation_mapper.py +15 -11
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/filter_mapper.py +32 -5
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/optimizer.py +1 -1
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/query_mapper.py +25 -6
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/search_mapper.py +6 -6
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/engines/engine.py +1 -1
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/models/entities.py +2 -2
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/statements/__init__.py +63 -22
- {industrial_model-0.1.31 → industrial_model-0.1.33}/pyproject.toml +1 -1
- {industrial_model-0.1.31 → industrial_model-0.1.33}/.gitignore +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/README.md +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/__init__.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/models.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/query_result_mapper.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/sort_mapper.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/upsert_mapper.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/utils.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/view_mapper.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/config.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/constants.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/engines/__init__.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/engines/async_engine.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/models/__init__.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/models/base.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/models/schemas.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/py.typed +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/queries/__init__.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/queries/models.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/queries/params.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/queries/utils.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/statements/expressions.py +0 -0
- {industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/utils.py +0 -0
{industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/__init__.py
RENAMED
|
@@ -92,7 +92,9 @@ class CogniteAdapter:
|
|
|
92
92
|
next_cursor = query_result.cursors.get(view_external_id)
|
|
93
93
|
data.extend(page_result)
|
|
94
94
|
|
|
95
|
-
last_page =
|
|
95
|
+
last_page = (
|
|
96
|
+
len(page_result) < statement.get_values().limit or not next_cursor
|
|
97
|
+
)
|
|
96
98
|
next_cursor_ = None if last_page else next_cursor
|
|
97
99
|
cognite_query.cursors = {view_external_id: next_cursor_}
|
|
98
100
|
|
|
@@ -43,29 +43,33 @@ class AggregationMapper:
|
|
|
43
43
|
|
|
44
44
|
root_view = self._view_mapper.get_view(root_node)
|
|
45
45
|
|
|
46
|
+
statement_values = statement.get_values()
|
|
46
47
|
filters_ = (
|
|
47
|
-
filters.And(
|
|
48
|
-
|
|
48
|
+
filters.And(
|
|
49
|
+
*self._filter_mapper.map(statement_values.where_clauses, root_view)
|
|
50
|
+
)
|
|
51
|
+
if statement_values.where_clauses
|
|
49
52
|
else None
|
|
50
53
|
)
|
|
54
|
+
aggregation_property = statement_values.aggregation_property.property
|
|
51
55
|
metric_aggregation: MetricAggregation | None = None
|
|
52
56
|
if statement.aggregate == "avg":
|
|
53
|
-
metric_aggregation = Avg(
|
|
57
|
+
metric_aggregation = Avg(aggregation_property)
|
|
54
58
|
elif statement.aggregate == "min":
|
|
55
|
-
metric_aggregation = Min(
|
|
59
|
+
metric_aggregation = Min(aggregation_property)
|
|
56
60
|
elif statement.aggregate == "max":
|
|
57
|
-
metric_aggregation = Max(
|
|
61
|
+
metric_aggregation = Max(aggregation_property)
|
|
58
62
|
elif statement.aggregate == "sum":
|
|
59
|
-
metric_aggregation = Sum(
|
|
63
|
+
metric_aggregation = Sum(aggregation_property)
|
|
60
64
|
elif statement.aggregate == "count":
|
|
61
|
-
metric_aggregation = Count(
|
|
65
|
+
metric_aggregation = Count(aggregation_property)
|
|
62
66
|
|
|
63
67
|
if metric_aggregation is None:
|
|
64
|
-
raise ValueError(f"Unsupported aggregate function: {statement.
|
|
68
|
+
raise ValueError(f"Unsupported aggregate function: {statement.aggregate}")
|
|
65
69
|
|
|
66
70
|
group_by_columns = (
|
|
67
|
-
[prop.property for prop in
|
|
68
|
-
if
|
|
71
|
+
[prop.property for prop in statement_values.group_by_properties]
|
|
72
|
+
if statement_values.group_by_properties is not None
|
|
69
73
|
else statement.entity.get_group_by_fields()
|
|
70
74
|
)
|
|
71
75
|
return AggregationQuery(
|
|
@@ -73,5 +77,5 @@ class AggregationMapper:
|
|
|
73
77
|
metric_aggregation=metric_aggregation,
|
|
74
78
|
filters=filters_,
|
|
75
79
|
group_by_columns=group_by_columns,
|
|
76
|
-
limit=
|
|
80
|
+
limit=statement_values.limit,
|
|
77
81
|
)
|
|
@@ -2,12 +2,17 @@ from datetime import date, datetime
|
|
|
2
2
|
from typing import Any
|
|
3
3
|
|
|
4
4
|
import cognite.client.data_classes.filters as cdf_filters
|
|
5
|
-
from cognite.client.data_classes.data_modeling import
|
|
5
|
+
from cognite.client.data_classes.data_modeling import (
|
|
6
|
+
EdgeConnection,
|
|
7
|
+
MappedProperty,
|
|
8
|
+
View,
|
|
9
|
+
)
|
|
6
10
|
|
|
7
11
|
from industrial_model.cognite_adapters.utils import get_property_ref
|
|
8
12
|
from industrial_model.models.entities import InstanceId
|
|
9
13
|
from industrial_model.statements import (
|
|
10
14
|
BoolExpression,
|
|
15
|
+
Column,
|
|
11
16
|
Expression,
|
|
12
17
|
LeafExpression,
|
|
13
18
|
)
|
|
@@ -26,15 +31,37 @@ class FilterMapper:
|
|
|
26
31
|
result: list[cdf_filters.Filter] = []
|
|
27
32
|
for expression in expressions:
|
|
28
33
|
if isinstance(expression, BoolExpression):
|
|
29
|
-
result.append(self.
|
|
34
|
+
result.append(self._to_cdf_filter_bool(expression, root_view))
|
|
30
35
|
elif isinstance(expression, LeafExpression):
|
|
31
|
-
result.append(self.
|
|
36
|
+
result.append(self._to_cdf_filter_leaf(expression, root_view))
|
|
32
37
|
else:
|
|
33
38
|
cls_name = expression.__class__.__name__
|
|
34
39
|
raise ValueError(f"Expression not implemented {cls_name}")
|
|
35
40
|
return result
|
|
36
41
|
|
|
37
|
-
def
|
|
42
|
+
def map_edges(
|
|
43
|
+
self,
|
|
44
|
+
edges_expressions: list[tuple[Column, list[Expression]]],
|
|
45
|
+
root_view: View,
|
|
46
|
+
nested_separator: str,
|
|
47
|
+
) -> dict[str, list[cdf_filters.Filter]]:
|
|
48
|
+
result_dict: dict[str, list[cdf_filters.Filter]] = {}
|
|
49
|
+
|
|
50
|
+
for column, expressions in edges_expressions:
|
|
51
|
+
view_property = root_view.properties.get(column.property)
|
|
52
|
+
if not isinstance(view_property, EdgeConnection):
|
|
53
|
+
raise ValueError(f"Property {column.property} is not an edge")
|
|
54
|
+
|
|
55
|
+
filters = self.map(
|
|
56
|
+
expressions,
|
|
57
|
+
self._view_mapper.get_view(view_property.source.external_id),
|
|
58
|
+
)
|
|
59
|
+
result_key = root_view.external_id + nested_separator + column.property
|
|
60
|
+
result_dict.setdefault(result_key, []).extend(filters)
|
|
61
|
+
|
|
62
|
+
return result_dict
|
|
63
|
+
|
|
64
|
+
def _to_cdf_filter_bool(
|
|
38
65
|
self, expression: BoolExpression, root_view: View
|
|
39
66
|
) -> cdf_filters.Filter:
|
|
40
67
|
arguments = self.map(expression.filters, root_view)
|
|
@@ -48,7 +75,7 @@ class FilterMapper:
|
|
|
48
75
|
|
|
49
76
|
raise NotImplementedError(f"Operator {self.operator} not implemented")
|
|
50
77
|
|
|
51
|
-
def
|
|
78
|
+
def _to_cdf_filter_leaf(
|
|
52
79
|
self,
|
|
53
80
|
expression: LeafExpression,
|
|
54
81
|
root_view: View,
|
|
@@ -45,27 +45,36 @@ class QueryMapper:
|
|
|
45
45
|
|
|
46
46
|
filters_: list[filters.Filter] = [filters.HasData(views=[root_view_id])]
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
statement_values = statement.get_values()
|
|
49
|
+
filters_.extend(
|
|
50
|
+
self._filter_mapper.map(statement_values.where_clauses, root_view)
|
|
51
|
+
)
|
|
49
52
|
|
|
50
53
|
with_: dict[str, ResultSetExpression] = {
|
|
51
54
|
root_node: NodeResultSetExpression(
|
|
52
55
|
filter=filters.And(*filters_),
|
|
53
|
-
sort=self._sort_mapper.map(
|
|
54
|
-
limit=
|
|
56
|
+
sort=self._sort_mapper.map(statement_values.sort_clauses, root_view),
|
|
57
|
+
limit=statement_values.limit,
|
|
55
58
|
)
|
|
56
59
|
}
|
|
57
60
|
select_: dict[str, Select] = {}
|
|
58
61
|
|
|
59
62
|
relations = get_schema_properties(statement.entity, NESTED_SEP, root_node)
|
|
60
63
|
|
|
64
|
+
edge_filters = self._filter_mapper.map_edges(
|
|
65
|
+
statement_values.where_edge_clauses, root_view, NESTED_SEP
|
|
66
|
+
)
|
|
67
|
+
|
|
61
68
|
properties = self._include_statements(
|
|
62
|
-
root_node, root_view, relations, with_, select_
|
|
69
|
+
root_node, root_view, relations, edge_filters, with_, select_
|
|
63
70
|
)
|
|
64
71
|
|
|
65
72
|
select_[root_node] = self._get_select(root_view_id, properties)
|
|
66
73
|
|
|
67
74
|
return CogniteQuery(
|
|
68
|
-
with_=with_,
|
|
75
|
+
with_=with_,
|
|
76
|
+
select=select_,
|
|
77
|
+
cursors={root_node: statement_values.cursor},
|
|
69
78
|
)
|
|
70
79
|
|
|
71
80
|
def _get_select(self, view_id: ViewId, properties: list[str]) -> Select:
|
|
@@ -80,6 +89,7 @@ class QueryMapper:
|
|
|
80
89
|
key: str,
|
|
81
90
|
view: View,
|
|
82
91
|
relations_to_include: list[str] | None,
|
|
92
|
+
edge_filters: dict[str, list[filters.Filter]],
|
|
83
93
|
with_: dict[str, ResultSetExpression],
|
|
84
94
|
select_: dict[str, Select],
|
|
85
95
|
) -> list[str]:
|
|
@@ -101,6 +111,7 @@ class QueryMapper:
|
|
|
101
111
|
property_key,
|
|
102
112
|
self._view_mapper.get_view(property.source.external_id),
|
|
103
113
|
relations_to_include,
|
|
114
|
+
edge_filters,
|
|
104
115
|
with_,
|
|
105
116
|
select_,
|
|
106
117
|
)
|
|
@@ -121,6 +132,7 @@ class QueryMapper:
|
|
|
121
132
|
property_key,
|
|
122
133
|
self._view_mapper.get_view(property.source.external_id),
|
|
123
134
|
relations_to_include,
|
|
135
|
+
edge_filters,
|
|
124
136
|
with_,
|
|
125
137
|
select_,
|
|
126
138
|
)
|
|
@@ -139,10 +151,16 @@ class QueryMapper:
|
|
|
139
151
|
elif isinstance(property, EdgeConnection) and property.source:
|
|
140
152
|
edge_property_key = f"{property_key}{NESTED_SEP}{EDGE_MARKER}"
|
|
141
153
|
|
|
154
|
+
edge_filter = edge_filters.get(property_key)
|
|
155
|
+
|
|
142
156
|
with_[edge_property_key] = EdgeResultSetExpression(
|
|
143
157
|
from_=key,
|
|
144
158
|
max_distance=1,
|
|
145
|
-
filter=filters.Equals(
|
|
159
|
+
filter=filters.Equals(
|
|
160
|
+
["edge", "type"],
|
|
161
|
+
property.type.dump(),
|
|
162
|
+
),
|
|
163
|
+
node_filter=filters.And(*edge_filter) if edge_filter else None,
|
|
146
164
|
direction=property.direction,
|
|
147
165
|
limit=MAX_LIMIT,
|
|
148
166
|
)
|
|
@@ -157,6 +175,7 @@ class QueryMapper:
|
|
|
157
175
|
property_key,
|
|
158
176
|
self._view_mapper.get_view(property.source.external_id),
|
|
159
177
|
relations_to_include,
|
|
178
|
+
edge_filters,
|
|
160
179
|
with_,
|
|
161
180
|
select_,
|
|
162
181
|
)
|
|
@@ -31,20 +31,20 @@ class SearchMapper:
|
|
|
31
31
|
|
|
32
32
|
def map(self, statement: SearchStatement[TViewInstance]) -> SearchQuery:
|
|
33
33
|
root_node = statement.entity.get_view_external_id()
|
|
34
|
-
|
|
34
|
+
statement_values = statement.get_values()
|
|
35
35
|
root_view = self._view_mapper.get_view(root_node)
|
|
36
36
|
|
|
37
|
-
filters_ = self._filter_mapper.map(
|
|
37
|
+
filters_ = self._filter_mapper.map(statement_values.where_clauses, root_view)
|
|
38
38
|
|
|
39
|
-
sort_clauses = self._sort_mapper.map(
|
|
39
|
+
sort_clauses = self._sort_mapper.map(statement_values.sort_clauses, root_view)
|
|
40
40
|
for item in sort_clauses:
|
|
41
41
|
item.nulls_first = None
|
|
42
42
|
|
|
43
43
|
return SearchQuery(
|
|
44
44
|
view=root_view,
|
|
45
45
|
filter=filters.And(*filters_) if filters_ else None,
|
|
46
|
-
query=
|
|
47
|
-
query_properties=
|
|
48
|
-
limit=
|
|
46
|
+
query=statement_values.query,
|
|
47
|
+
query_properties=statement_values.query_properties,
|
|
48
|
+
limit=statement_values.limit,
|
|
49
49
|
sort=sort_clauses,
|
|
50
50
|
)
|
|
@@ -59,7 +59,7 @@ class Engine:
|
|
|
59
59
|
statement: Statement[TViewInstance],
|
|
60
60
|
validation_mode: ValidationMode = "raiseOnError",
|
|
61
61
|
) -> list[TViewInstance]:
|
|
62
|
-
if statement.
|
|
62
|
+
if statement.get_values().cursor:
|
|
63
63
|
raise ValueError("Cursor should be none when querying all pages")
|
|
64
64
|
|
|
65
65
|
data, _ = self._cognite_adapter.query(statement, True)
|
|
@@ -16,7 +16,7 @@ from industrial_model.statements import Column
|
|
|
16
16
|
from .base import DBModelMetaclass, RootModel
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
class InstanceId(RootModel):
|
|
19
|
+
class InstanceId(RootModel, metaclass=DBModelMetaclass):
|
|
20
20
|
external_id: str
|
|
21
21
|
space: str
|
|
22
22
|
|
|
@@ -51,7 +51,7 @@ class ViewInstanceConfig(TypedDict, total=False):
|
|
|
51
51
|
view_code: str | None
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
class ViewInstance(InstanceId
|
|
54
|
+
class ViewInstance(InstanceId):
|
|
55
55
|
view_config: ClassVar[ViewInstanceConfig] = ViewInstanceConfig()
|
|
56
56
|
|
|
57
57
|
_edges: dict[str, list[EdgeContainer]] = PrivateAttr(default_factory=dict)
|
|
@@ -23,22 +23,36 @@ def _create_column(property: str | Column | Any) -> Column:
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
@dataclass
|
|
26
|
-
class
|
|
27
|
-
entity: type[T] = field(init=True)
|
|
26
|
+
class BaseStatementValues:
|
|
28
27
|
where_clauses: list[Expression] = field(init=False, default_factory=list)
|
|
28
|
+
where_edge_clauses: list[tuple[Column, list[Expression]]] = field(
|
|
29
|
+
init=False, default_factory=list
|
|
30
|
+
)
|
|
29
31
|
sort_clauses: list[tuple[Column, SORT_DIRECTION]] = field(
|
|
30
32
|
init=False, default_factory=list
|
|
31
33
|
)
|
|
32
|
-
|
|
34
|
+
limit: int = field(init=False, default=DEFAULT_LIMIT)
|
|
35
|
+
cursor: str | None = field(init=False, default=None)
|
|
36
|
+
|
|
37
|
+
query: str | None = field(init=False, default=None)
|
|
38
|
+
query_properties: list[str] | None = field(init=False, default=None)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass
|
|
42
|
+
class BaseStatement(Generic[T]):
|
|
43
|
+
entity: type[T] = field(init=True)
|
|
44
|
+
_values: BaseStatementValues = field(
|
|
45
|
+
init=False, default_factory=lambda: BaseStatementValues()
|
|
46
|
+
)
|
|
33
47
|
|
|
34
48
|
def where(self, *expressions: bool | Expression) -> Self:
|
|
35
49
|
for expression in expressions:
|
|
36
50
|
assert isinstance(expression, Expression)
|
|
37
|
-
self.where_clauses.append(expression)
|
|
51
|
+
self._values.where_clauses.append(expression)
|
|
38
52
|
return self
|
|
39
53
|
|
|
40
54
|
def limit(self, limit: int) -> Self:
|
|
41
|
-
self.
|
|
55
|
+
self._values.limit = limit
|
|
42
56
|
return self
|
|
43
57
|
|
|
44
58
|
def asc(self, property: str | Column | Any) -> Self:
|
|
@@ -48,7 +62,7 @@ class BaseStatement(Generic[T]):
|
|
|
48
62
|
return self.sort(property, "descending")
|
|
49
63
|
|
|
50
64
|
def sort(self, property: str | Column | Any, direction: SORT_DIRECTION) -> Self:
|
|
51
|
-
self.sort_clauses.append(
|
|
65
|
+
self._values.sort_clauses.append(
|
|
52
66
|
(
|
|
53
67
|
_create_column(property),
|
|
54
68
|
direction,
|
|
@@ -56,28 +70,45 @@ class BaseStatement(Generic[T]):
|
|
|
56
70
|
)
|
|
57
71
|
return self
|
|
58
72
|
|
|
73
|
+
def get_values(self) -> BaseStatementValues:
|
|
74
|
+
return self._values
|
|
75
|
+
|
|
59
76
|
|
|
60
77
|
@dataclass
|
|
61
78
|
class Statement(BaseStatement[T]):
|
|
62
|
-
cursor_: str | None = field(init=False, default=None)
|
|
63
|
-
|
|
64
79
|
def cursor(self, cursor: str | None) -> Self:
|
|
65
|
-
self.
|
|
80
|
+
self._values.cursor = cursor
|
|
81
|
+
return self
|
|
82
|
+
|
|
83
|
+
def where_edge(
|
|
84
|
+
self, property: str | Column | Any, *expressions: bool | Expression
|
|
85
|
+
) -> Self:
|
|
86
|
+
if not expressions:
|
|
87
|
+
return self
|
|
88
|
+
|
|
89
|
+
expressions_: list[Expression] = []
|
|
90
|
+
for expression in expressions:
|
|
91
|
+
assert isinstance(expression, Expression)
|
|
92
|
+
expressions_.append(expression)
|
|
93
|
+
|
|
94
|
+
self._values.where_edge_clauses.append(
|
|
95
|
+
(
|
|
96
|
+
_create_column(property),
|
|
97
|
+
expressions_,
|
|
98
|
+
)
|
|
99
|
+
)
|
|
66
100
|
return self
|
|
67
101
|
|
|
68
102
|
|
|
69
103
|
@dataclass
|
|
70
104
|
class SearchStatement(BaseStatement[T]):
|
|
71
|
-
query: str | None = field(init=False, default=None)
|
|
72
|
-
query_properties: list[str] | None = field(init=False, default=None)
|
|
73
|
-
|
|
74
105
|
def query_by(
|
|
75
106
|
self,
|
|
76
107
|
query: str,
|
|
77
108
|
query_properties: list[Column] | list[str] | list[Any] | None = None,
|
|
78
109
|
) -> Self:
|
|
79
|
-
self.query = query
|
|
80
|
-
self.query_properties = (
|
|
110
|
+
self._values.query = query
|
|
111
|
+
self._values.query_properties = (
|
|
81
112
|
[
|
|
82
113
|
prop
|
|
83
114
|
if isinstance(prop, str)
|
|
@@ -92,34 +123,44 @@ class SearchStatement(BaseStatement[T]):
|
|
|
92
123
|
return self
|
|
93
124
|
|
|
94
125
|
|
|
126
|
+
@dataclass
|
|
127
|
+
class AggregationStatementValues:
|
|
128
|
+
group_by_properties: list[Column] | None = field(init=False, default=None)
|
|
129
|
+
aggregation_property: Column = field(init=False, default=Column("externalId"))
|
|
130
|
+
where_clauses: list[Expression] = field(init=False, default_factory=list)
|
|
131
|
+
limit: int = field(init=False, default=-1)
|
|
132
|
+
|
|
133
|
+
|
|
95
134
|
@dataclass
|
|
96
135
|
class AggregationStatement(Generic[T]):
|
|
97
136
|
entity: type[T] = field(init=True)
|
|
98
137
|
aggregate: AggregateTypes = field(init=True)
|
|
99
138
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
limit_: int = field(init=False, default=-1)
|
|
139
|
+
_values: AggregationStatementValues = field(
|
|
140
|
+
init=False, default_factory=lambda: AggregationStatementValues()
|
|
141
|
+
)
|
|
104
142
|
|
|
105
143
|
def group_by(self, *property: str | Column | Any) -> Self:
|
|
106
|
-
self.group_by_properties = [_create_column(prop) for prop in property]
|
|
144
|
+
self._values.group_by_properties = [_create_column(prop) for prop in property]
|
|
107
145
|
return self
|
|
108
146
|
|
|
109
147
|
def aggregate_by(self, property: str | Column | Any) -> Self:
|
|
110
|
-
self.aggregation_property = _create_column(property)
|
|
148
|
+
self._values.aggregation_property = _create_column(property)
|
|
111
149
|
return self
|
|
112
150
|
|
|
113
151
|
def where(self, *expressions: bool | Expression) -> Self:
|
|
114
152
|
for expression in expressions:
|
|
115
153
|
assert isinstance(expression, Expression)
|
|
116
|
-
self.where_clauses.append(expression)
|
|
154
|
+
self._values.where_clauses.append(expression)
|
|
117
155
|
return self
|
|
118
156
|
|
|
119
157
|
def limit(self, limit: int) -> Self:
|
|
120
|
-
self.
|
|
158
|
+
self._values.limit = limit
|
|
121
159
|
return self
|
|
122
160
|
|
|
161
|
+
def get_values(self) -> AggregationStatementValues:
|
|
162
|
+
return self._values
|
|
163
|
+
|
|
123
164
|
|
|
124
165
|
def select(entity: type[T]) -> Statement[T]:
|
|
125
166
|
return Statement(entity)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/models.py
RENAMED
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/sort_mapper.py
RENAMED
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/utils.py
RENAMED
|
File without changes
|
{industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/cognite_adapters/view_mapper.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/engines/async_engine.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
|
{industrial_model-0.1.31 → industrial_model-0.1.33}/industrial_model/statements/expressions.py
RENAMED
|
File without changes
|
|
File without changes
|