industrial-model 0.1.27__tar.gz → 0.1.28__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.27 → industrial_model-0.1.28}/PKG-INFO +1 -1
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/queries/__init__.py +2 -1
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/queries/models.py +24 -30
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/queries/params.py +12 -0
- industrial_model-0.1.28/industrial_model/queries/utils.py +42 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/pyproject.toml +1 -1
- {industrial_model-0.1.27 → industrial_model-0.1.28}/.gitignore +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/README.md +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/__init__.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/__init__.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/aggregation_mapper.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/filter_mapper.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/models.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/optimizer.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/query_mapper.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/query_result_mapper.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/search_mapper.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/sort_mapper.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/upsert_mapper.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/utils.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/view_mapper.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/config.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/constants.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/engines/__init__.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/engines/async_engine.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/engines/engine.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/models/__init__.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/models/base.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/models/entities.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/models/schemas.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/py.typed +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/statements/__init__.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/statements/expressions.py +0 -0
- {industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/utils.py +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from .models import BaseAggregationQuery, BasePaginatedQuery, BaseQuery, BaseSearchQuery
|
|
2
|
-
from .params import NestedQueryParam, QueryParam, SortParam
|
|
2
|
+
from .params import BoolQueryParam, NestedQueryParam, QueryParam, SortParam
|
|
3
3
|
|
|
4
4
|
__all__ = [
|
|
5
5
|
"BaseQuery",
|
|
@@ -9,4 +9,5 @@ __all__ = [
|
|
|
9
9
|
"SortParam",
|
|
10
10
|
"QueryParam",
|
|
11
11
|
"NestedQueryParam",
|
|
12
|
+
"BoolQueryParam",
|
|
12
13
|
]
|
|
@@ -7,24 +7,17 @@ from industrial_model.statements import (
|
|
|
7
7
|
SearchStatement,
|
|
8
8
|
Statement,
|
|
9
9
|
aggregate,
|
|
10
|
+
search,
|
|
11
|
+
select,
|
|
10
12
|
)
|
|
11
13
|
|
|
12
|
-
from .
|
|
14
|
+
from .utils import extract_base_statement_params
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
class BaseQuery(RootModel):
|
|
16
18
|
def to_statement(self, entity: type[TViewInstance]) -> Statement[TViewInstance]:
|
|
17
|
-
statement =
|
|
18
|
-
|
|
19
|
-
for key, item in self.__class__.model_fields.items():
|
|
20
|
-
values = getattr(self, key)
|
|
21
|
-
if values is None:
|
|
22
|
-
continue
|
|
23
|
-
for metadata_item in item.metadata:
|
|
24
|
-
if isinstance(metadata_item, SortParam):
|
|
25
|
-
statement.sort(values, metadata_item.direction)
|
|
26
|
-
elif isinstance(metadata_item, QueryParam | NestedQueryParam):
|
|
27
|
-
statement.where(metadata_item.to_expression(values))
|
|
19
|
+
statement = select(entity)
|
|
20
|
+
_set_base_statement_params(self, statement)
|
|
28
21
|
|
|
29
22
|
return statement
|
|
30
23
|
|
|
@@ -49,17 +42,8 @@ class BaseSearchQuery(RootModel):
|
|
|
49
42
|
def to_statement(
|
|
50
43
|
self, entity: type[TViewInstance]
|
|
51
44
|
) -> SearchStatement[TViewInstance]:
|
|
52
|
-
statement =
|
|
53
|
-
|
|
54
|
-
for key, item in self.__class__.model_fields.items():
|
|
55
|
-
values = getattr(self, key)
|
|
56
|
-
if values is None:
|
|
57
|
-
continue
|
|
58
|
-
for metadata_item in item.metadata:
|
|
59
|
-
if isinstance(metadata_item, SortParam):
|
|
60
|
-
statement.sort(values, metadata_item.direction)
|
|
61
|
-
elif isinstance(metadata_item, QueryParam | NestedQueryParam):
|
|
62
|
-
statement.where(metadata_item.to_expression(values))
|
|
45
|
+
statement = search(entity)
|
|
46
|
+
_set_base_statement_params(self, statement)
|
|
63
47
|
if self.query:
|
|
64
48
|
statement.query_by(self.query, self.query_properties)
|
|
65
49
|
statement.limit(self.limit)
|
|
@@ -78,13 +62,7 @@ class BaseAggregationQuery(RootModel):
|
|
|
78
62
|
) -> AggregationStatement[TAggregatedViewInstance]:
|
|
79
63
|
statement = aggregate(entity, self.aggregate)
|
|
80
64
|
|
|
81
|
-
|
|
82
|
-
values = getattr(self, key)
|
|
83
|
-
if values is None:
|
|
84
|
-
continue
|
|
85
|
-
for metadata_item in item.metadata:
|
|
86
|
-
if isinstance(metadata_item, QueryParam | NestedQueryParam):
|
|
87
|
-
statement.where(metadata_item.to_expression(values))
|
|
65
|
+
_set_base_statement_params(self, statement)
|
|
88
66
|
|
|
89
67
|
if self.group_by_properties:
|
|
90
68
|
statement.group_by(*self.group_by_properties)
|
|
@@ -96,3 +74,19 @@ class BaseAggregationQuery(RootModel):
|
|
|
96
74
|
statement.limit(self.limit)
|
|
97
75
|
|
|
98
76
|
return statement
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _set_base_statement_params(
|
|
80
|
+
entity: RootModel,
|
|
81
|
+
statement: Statement[TViewInstance]
|
|
82
|
+
| SearchStatement[TViewInstance]
|
|
83
|
+
| AggregationStatement[TAggregatedViewInstance],
|
|
84
|
+
) -> None:
|
|
85
|
+
filters_, sort_params = extract_base_statement_params(entity)
|
|
86
|
+
statement.where(*filters_)
|
|
87
|
+
|
|
88
|
+
if isinstance(statement, AggregationStatement):
|
|
89
|
+
return
|
|
90
|
+
|
|
91
|
+
for sort_value, direction in sort_params:
|
|
92
|
+
statement.sort(sort_value, direction)
|
|
@@ -2,6 +2,7 @@ from dataclasses import dataclass
|
|
|
2
2
|
from typing import Any
|
|
3
3
|
|
|
4
4
|
from industrial_model.constants import (
|
|
5
|
+
BOOL_EXPRESSION_OPERATORS,
|
|
5
6
|
LEAF_EXPRESSION_OPERATORS,
|
|
6
7
|
SORT_DIRECTION,
|
|
7
8
|
)
|
|
@@ -49,6 +50,17 @@ class NestedQueryParam:
|
|
|
49
50
|
)
|
|
50
51
|
|
|
51
52
|
|
|
53
|
+
@dataclass
|
|
54
|
+
class BoolQueryParam:
|
|
55
|
+
operator: BOOL_EXPRESSION_OPERATORS
|
|
56
|
+
|
|
57
|
+
def to_expression(self, filters: list[Expression]) -> Expression:
|
|
58
|
+
return BoolExpression(
|
|
59
|
+
operator=self.operator,
|
|
60
|
+
filters=filters,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
52
64
|
@dataclass
|
|
53
65
|
class SortParam:
|
|
54
66
|
direction: SORT_DIRECTION
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from industrial_model.constants import SORT_DIRECTION
|
|
4
|
+
from industrial_model.models import RootModel
|
|
5
|
+
from industrial_model.statements import Expression
|
|
6
|
+
|
|
7
|
+
from .params import BoolQueryParam, NestedQueryParam, QueryParam, SortParam
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def extract_base_statement_params(
|
|
11
|
+
entity: RootModel,
|
|
12
|
+
) -> tuple[list[Expression], list[tuple[Any, SORT_DIRECTION]]]:
|
|
13
|
+
filters_: list[Expression] = []
|
|
14
|
+
sort_params: list[tuple[Any, SORT_DIRECTION]] = []
|
|
15
|
+
|
|
16
|
+
for key, item in entity.__class__.model_fields.items():
|
|
17
|
+
values = getattr(entity, key)
|
|
18
|
+
if values is None:
|
|
19
|
+
continue
|
|
20
|
+
for metadata_item in item.metadata:
|
|
21
|
+
if isinstance(metadata_item, SortParam):
|
|
22
|
+
sort_params.append((values, metadata_item.direction))
|
|
23
|
+
elif isinstance(
|
|
24
|
+
metadata_item, QueryParam | NestedQueryParam | BoolQueryParam
|
|
25
|
+
):
|
|
26
|
+
filter_ = _extract_expression(metadata_item, values)
|
|
27
|
+
if filter_ is not None:
|
|
28
|
+
filters_.append(filter_)
|
|
29
|
+
return filters_, sort_params
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _extract_expression(
|
|
33
|
+
metadata_item: QueryParam | NestedQueryParam | BoolQueryParam, values: Any
|
|
34
|
+
) -> Expression | None:
|
|
35
|
+
if isinstance(metadata_item, QueryParam | NestedQueryParam):
|
|
36
|
+
return metadata_item.to_expression(values)
|
|
37
|
+
|
|
38
|
+
if not isinstance(values, RootModel):
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
filters_, _ = extract_base_statement_params(values)
|
|
42
|
+
return metadata_item.to_expression(filters_)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/models.py
RENAMED
|
File without changes
|
{industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/optimizer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/sort_mapper.py
RENAMED
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/utils.py
RENAMED
|
File without changes
|
{industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/cognite_adapters/view_mapper.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.27 → industrial_model-0.1.28}/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
|
{industrial_model-0.1.27 → industrial_model-0.1.28}/industrial_model/statements/expressions.py
RENAMED
|
File without changes
|
|
File without changes
|