industrial-model 0.1.3__py3-none-any.whl → 0.1.5__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.
- industrial_model/cognite_adapters/optimizer.py +5 -2
- industrial_model/cognite_adapters/query_mapper.py +16 -14
- industrial_model/models/__init__.py +2 -0
- industrial_model/{cognite_adapters → models}/schemas.py +1 -3
- {industrial_model-0.1.3.dist-info → industrial_model-0.1.5.dist-info}/METADATA +24 -4
- {industrial_model-0.1.3.dist-info → industrial_model-0.1.5.dist-info}/RECORD +7 -7
- {industrial_model-0.1.3.dist-info → industrial_model-0.1.5.dist-info}/WHEEL +0 -0
|
@@ -49,8 +49,11 @@ class QueryOptimizer:
|
|
|
49
49
|
where_clause, BoolExpression
|
|
50
50
|
) and self._has_space_filter(where_clause.filters):
|
|
51
51
|
return True
|
|
52
|
-
elif
|
|
53
|
-
|
|
52
|
+
elif (
|
|
53
|
+
isinstance(where_clause, LeafExpression)
|
|
54
|
+
and where_clause.property == SPACE_PROPERTY
|
|
55
|
+
):
|
|
56
|
+
return True
|
|
54
57
|
|
|
55
58
|
return False
|
|
56
59
|
|
|
@@ -21,13 +21,12 @@ from cognite.client.data_classes.data_modeling.views import (
|
|
|
21
21
|
)
|
|
22
22
|
|
|
23
23
|
from industrial_model.constants import EDGE_MARKER, MAX_LIMIT, NESTED_SEP
|
|
24
|
-
from industrial_model.models import TViewInstance
|
|
24
|
+
from industrial_model.models import TViewInstance, get_schema_properties
|
|
25
25
|
from industrial_model.statements import Statement
|
|
26
26
|
|
|
27
27
|
from .filter_mapper import (
|
|
28
28
|
FilterMapper,
|
|
29
29
|
)
|
|
30
|
-
from .schemas import get_schema_properties
|
|
31
30
|
from .sort_mapper import SortMapper
|
|
32
31
|
from .view_mapper import ViewMapper
|
|
33
32
|
|
|
@@ -135,19 +134,22 @@ class QueryMapper:
|
|
|
135
134
|
with_,
|
|
136
135
|
select_,
|
|
137
136
|
)
|
|
138
|
-
if not props:
|
|
139
|
-
with_[property_key] = NodeResultSetExpression(
|
|
140
|
-
from_=key,
|
|
141
|
-
direction="inwards",
|
|
142
|
-
through=property.source.as_property_ref(
|
|
143
|
-
property.through.property
|
|
144
|
-
),
|
|
145
|
-
limit=MAX_LIMIT,
|
|
146
|
-
)
|
|
147
137
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
138
|
+
with_[property_key] = NodeResultSetExpression(
|
|
139
|
+
from_=key,
|
|
140
|
+
direction="inwards",
|
|
141
|
+
through=property.source.as_property_ref(
|
|
142
|
+
property.through.property
|
|
143
|
+
),
|
|
144
|
+
limit=MAX_LIMIT,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
if property.through.property not in props:
|
|
148
|
+
props.append(property.through.property)
|
|
149
|
+
|
|
150
|
+
select_[property_key] = self._get_select(
|
|
151
|
+
property.source, props
|
|
152
|
+
)
|
|
151
153
|
elif isinstance(property, EdgeConnection) and property.source:
|
|
152
154
|
edge_property_key = f"{property_key}{NESTED_SEP}{EDGE_MARKER}"
|
|
153
155
|
|
|
@@ -7,6 +7,7 @@ from .entities import (
|
|
|
7
7
|
ViewInstance,
|
|
8
8
|
ViewInstanceConfig,
|
|
9
9
|
)
|
|
10
|
+
from .schemas import get_schema_properties
|
|
10
11
|
|
|
11
12
|
__all__ = [
|
|
12
13
|
"RootModel",
|
|
@@ -16,4 +17,5 @@ __all__ = [
|
|
|
16
17
|
"ValidationMode",
|
|
17
18
|
"PaginatedResult",
|
|
18
19
|
"ViewInstanceConfig",
|
|
20
|
+
"get_schema_properties",
|
|
19
21
|
]
|
|
@@ -12,14 +12,12 @@ from typing import (
|
|
|
12
12
|
|
|
13
13
|
from pydantic import BaseModel
|
|
14
14
|
|
|
15
|
-
from industrial_model.constants import NESTED_SEP
|
|
16
|
-
|
|
17
15
|
TBaseModel = TypeVar("TBaseModel", bound=BaseModel)
|
|
18
16
|
|
|
19
17
|
|
|
20
18
|
def get_schema_properties(
|
|
21
19
|
cls: type[TBaseModel],
|
|
22
|
-
nested_separator: str
|
|
20
|
+
nested_separator: str,
|
|
23
21
|
prefix: str | None = None,
|
|
24
22
|
) -> list[str]:
|
|
25
23
|
data = _get_type_properties(cls) or {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: industrial-model
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Industrial Model ORM
|
|
5
5
|
Author-email: Lucas Alves <lucasrosaalves@gmail.com>
|
|
6
6
|
Classifier: Programming Language :: Python
|
|
@@ -81,7 +81,27 @@ class Country(ViewInstance):
|
|
|
81
81
|
class Person(ViewInstance):
|
|
82
82
|
name: str
|
|
83
83
|
birthday: datetime.date
|
|
84
|
-
|
|
84
|
+
lives_in: Country
|
|
85
|
+
cars: list[Car]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# By default, the ORM maps the class name to the view in the data model.
|
|
89
|
+
# You can override this behavior using the `view_config` field.
|
|
90
|
+
|
|
91
|
+
# For improved query performance, you can configure `instance_spaces` or `instance_spaces_prefix`
|
|
92
|
+
# in the `view_config`. These options include space filters in the generated queries,
|
|
93
|
+
# which can significantly reduce response times when working with large datasets.
|
|
94
|
+
|
|
95
|
+
class AnotherPerson(ViewInstance):
|
|
96
|
+
view_config = ViewInstanceConfig(
|
|
97
|
+
view_external_id="Person", # Maps this class to the 'Person' view
|
|
98
|
+
instance_spaces_prefix="Industr-", # Filters queries to spaces with this prefix
|
|
99
|
+
instance_spaces=["Industrial-Data"] # Alternatively, explicitly filter by these spaces
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
name: str
|
|
103
|
+
birthday: datetime.date
|
|
104
|
+
lives_in: Country
|
|
85
105
|
cars: list[Car]
|
|
86
106
|
|
|
87
107
|
|
|
@@ -128,9 +148,9 @@ result = engine.query(statement)
|
|
|
128
148
|
# 4. Nested filtering using relationships
|
|
129
149
|
statement = select(Person).where(
|
|
130
150
|
or_(
|
|
131
|
-
col(Person.
|
|
151
|
+
col(Person.lives_in).nested_(Country.name == "usa"),
|
|
132
152
|
and_(
|
|
133
|
-
col(Person.
|
|
153
|
+
col(Person.lives_in).nested_(col(Country.name).equals_("bra")),
|
|
134
154
|
col(Person.birthday).equals_("2023-01-01")
|
|
135
155
|
)
|
|
136
156
|
)
|
|
@@ -5,24 +5,24 @@ industrial_model/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
5
5
|
industrial_model/utils.py,sha256=OuuAkIqu-551axsZJPuqHu5d9iReGcfY9ROBFtHIwkY,933
|
|
6
6
|
industrial_model/cognite_adapters/__init__.py,sha256=9N4oT7tWZx5wjVr7q64Ef5FLT75Omep48xGYv1PhxV8,1917
|
|
7
7
|
industrial_model/cognite_adapters/filter_mapper.py,sha256=NqH-OW7_iKFY9POCG8W3KjkwXUgrZP1d_yxDx1J0fXM,3859
|
|
8
|
-
industrial_model/cognite_adapters/optimizer.py,sha256=
|
|
9
|
-
industrial_model/cognite_adapters/query_mapper.py,sha256=
|
|
8
|
+
industrial_model/cognite_adapters/optimizer.py,sha256=G8I07jJ9tarE5GZXXUSpTMKUei6ptV-cudJSLsoykX4,2223
|
|
9
|
+
industrial_model/cognite_adapters/query_mapper.py,sha256=3fEcaLsGjLKIh-g1BbMcffQ6rp99JeCW555iJo8JW44,6260
|
|
10
10
|
industrial_model/cognite_adapters/query_result_mapper.py,sha256=jUreXqsaLnq7hp6T_JZQNRtL8TL8hoLSFvD4SkJ4TEE,7002
|
|
11
|
-
industrial_model/cognite_adapters/schemas.py,sha256=EiRe0HK6thCzk0WYOPrAIRe8GkkG7_ykQsy7WVfT_Og,3430
|
|
12
11
|
industrial_model/cognite_adapters/sort_mapper.py,sha256=RJUAYlZGXoYzK0PwX63cibRF_L-MUq9g2ZsC2EeNIF4,696
|
|
13
12
|
industrial_model/cognite_adapters/utils.py,sha256=nBYHK8697L2yGEAcyKjQV9NEZQmWy_aSGq_iMl7gofM,907
|
|
14
13
|
industrial_model/cognite_adapters/view_mapper.py,sha256=lnv64KezSQTAr6XdcExa8d92GU5Ll9K9HfMcQGzhX6k,488
|
|
15
14
|
industrial_model/engines/__init__.py,sha256=7aGHrUm2MxIq39vR8h0xu3i1zNOuT9H9U-q4lV3nErQ,102
|
|
16
15
|
industrial_model/engines/async_engine.py,sha256=3Y4Ao14CDJJAZFbgTX9I6LOJUxfe8nwOOukGVeiw914,1070
|
|
17
16
|
industrial_model/engines/engine.py,sha256=8-wfktRLZpad_V7_F1Vz7vtjE_bQhga_jXXjuwSgfrE,1897
|
|
18
|
-
industrial_model/models/__init__.py,sha256=
|
|
17
|
+
industrial_model/models/__init__.py,sha256=YcNLjpYnxdU_wTpn1n0AhwlZ-XHWYqX6FzfbuevG3jo,406
|
|
19
18
|
industrial_model/models/base.py,sha256=jbiaICJ0R1mmxXtDqxxlVdq-tTX4RLdqnLTgs9HLm_4,1279
|
|
20
19
|
industrial_model/models/entities.py,sha256=NrFV_a3ZP6Y4b1M2PFl_746qcCsexsyO2cuB0snZhkw,1319
|
|
20
|
+
industrial_model/models/schemas.py,sha256=FzreMCR2TGX89-tMRpCNdcYqHj1u9QlocRLNwE_J2rA,3366
|
|
21
21
|
industrial_model/queries/__init__.py,sha256=7aheTE5qs03rxWm9fmGWptbz_p9OIXXYD8if56cqs18,227
|
|
22
22
|
industrial_model/queries/models.py,sha256=iiHQ7-cfg0nukEv5PoCx9QPF-w1gVSnoNbXBOK9Mzeo,1185
|
|
23
23
|
industrial_model/queries/params.py,sha256=ehgCoR5n6E-tkEuoymZ2lkLcSzMaBAx_HnyJ7sWpqz0,964
|
|
24
24
|
industrial_model/statements/__init__.py,sha256=mqPIvfQ-XZ_IILwha7RbkdIKH_MRAdAvfrw80pCKU1c,1753
|
|
25
25
|
industrial_model/statements/expressions.py,sha256=bsUnkFDGVHpOQ1RUtEbSPE1nfVkF0zC3m5-9JFkSqu8,4751
|
|
26
|
-
industrial_model-0.1.
|
|
27
|
-
industrial_model-0.1.
|
|
28
|
-
industrial_model-0.1.
|
|
26
|
+
industrial_model-0.1.5.dist-info/METADATA,sha256=QqFzf6bL7tomB8Ym8LLtMTQBWe7yIuaPtni1NzCoWSM,4806
|
|
27
|
+
industrial_model-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
28
|
+
industrial_model-0.1.5.dist-info/RECORD,,
|
|
File without changes
|