corvic-engine 0.3.0rc44__cp38-abi3-win_amd64.whl → 0.3.0rc45__cp38-abi3-win_amd64.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.
- corvic/engine/_native.pyd +0 -0
- corvic/model/__init__.py +7 -1
- corvic/model/_base_model.py +35 -42
- corvic/model/_feature_view.py +43 -43
- corvic/model/_pipeline.py +2 -14
- corvic/model/_proto_orm_convert.py +242 -239
- corvic/model/_resource.py +2 -7
- corvic/model/_source.py +14 -16
- corvic/model/_space.py +330 -362
- corvic/orm/__init__.py +38 -138
- {corvic_engine-0.3.0rc44.dist-info → corvic_engine-0.3.0rc45.dist-info}/METADATA +1 -1
- {corvic_engine-0.3.0rc44.dist-info → corvic_engine-0.3.0rc45.dist-info}/RECORD +16 -16
- corvic_generated/model/v1alpha/models_pb2.py +28 -28
- corvic_generated/model/v1alpha/models_pb2.pyi +8 -12
- {corvic_engine-0.3.0rc44.dist-info → corvic_engine-0.3.0rc45.dist-info}/WHEEL +0 -0
- {corvic_engine-0.3.0rc44.dist-info → corvic_engine-0.3.0rc45.dist-info}/licenses/LICENSE +0 -0
corvic/engine/_native.pyd
CHANGED
Binary file
|
corvic/model/__init__.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import corvic.model._feature_type as feature_type
|
4
4
|
from corvic.model._agent import Agent, AgentID
|
5
|
-
from corvic.model._base_model import BaseModel
|
5
|
+
from corvic.model._base_model import BaseModel, HasProtoSelf, UsesOrmID
|
6
6
|
from corvic.model._completion_model import (
|
7
7
|
CompletionModel,
|
8
8
|
CompletionModelID,
|
@@ -47,7 +47,9 @@ from corvic.model._space import (
|
|
47
47
|
SemanticSpace,
|
48
48
|
Space,
|
49
49
|
SpecificSpace,
|
50
|
+
SpecificSpaceParameters,
|
50
51
|
TabularSpace,
|
52
|
+
UnknownSpace,
|
51
53
|
embedding_model_proto_to_name,
|
52
54
|
image_model_proto_to_name,
|
53
55
|
)
|
@@ -70,6 +72,7 @@ __all__ = [
|
|
70
72
|
"FeatureView",
|
71
73
|
"FeatureViewEdgeTableMetadata",
|
72
74
|
"FeatureViewRelationshipsMetadata",
|
75
|
+
"HasProtoSelf",
|
73
76
|
"ImageSpace",
|
74
77
|
"Node2VecParameters",
|
75
78
|
"OcrPdfsPipeline",
|
@@ -87,9 +90,12 @@ __all__ = [
|
|
87
90
|
"Space",
|
88
91
|
"SpecificPipeline",
|
89
92
|
"SpecificSpace",
|
93
|
+
"SpecificSpaceParameters",
|
90
94
|
"TabularSpace",
|
91
95
|
"UNCOMMITTED_ID_PREFIX",
|
92
96
|
"UnknownTransformationPipeline",
|
97
|
+
"UnknownSpace",
|
98
|
+
"UsesOrmID",
|
93
99
|
"embedding_model_proto_to_name",
|
94
100
|
"feature_type",
|
95
101
|
"image_model_proto_to_name",
|
corvic/model/_base_model.py
CHANGED
@@ -5,7 +5,7 @@ import datetime
|
|
5
5
|
import functools
|
6
6
|
import uuid
|
7
7
|
from collections.abc import Callable, Iterable, Iterator, Sequence
|
8
|
-
from typing import
|
8
|
+
from typing import Final, Generic, Protocol, TypeVar
|
9
9
|
|
10
10
|
import sqlalchemy as sa
|
11
11
|
import sqlalchemy.orm as sa_orm
|
@@ -14,7 +14,7 @@ from google.protobuf import timestamp_pb2
|
|
14
14
|
from typing_extensions import Self
|
15
15
|
|
16
16
|
from corvic import orm, system
|
17
|
-
from corvic.model._proto_orm_convert import UNCOMMITTED_ID_PREFIX
|
17
|
+
from corvic.model._proto_orm_convert import ID, UNCOMMITTED_ID_PREFIX, OrmObj
|
18
18
|
from corvic.result import InvalidArgumentError, NotFoundError, Ok
|
19
19
|
|
20
20
|
_logger = structlog.get_logger()
|
@@ -26,21 +26,6 @@ class _ModelProto(Protocol):
|
|
26
26
|
|
27
27
|
|
28
28
|
_ProtoObj = TypeVar("_ProtoObj", bound=_ModelProto)
|
29
|
-
_ID = TypeVar("_ID", bound=orm.BaseID[Any])
|
30
|
-
|
31
|
-
|
32
|
-
class _OrmModel(Protocol[_ID]):
|
33
|
-
id: sa_orm.Mapped[_ID | None]
|
34
|
-
|
35
|
-
@sa.ext.hybrid.hybrid_property
|
36
|
-
def created_at(self) -> datetime.datetime | None: ...
|
37
|
-
|
38
|
-
@created_at.inplace.expression
|
39
|
-
@classmethod
|
40
|
-
def _created_at_expression(cls): ...
|
41
|
-
|
42
|
-
|
43
|
-
_OrmObj = TypeVar("_OrmObj", bound=_OrmModel[Any])
|
44
29
|
|
45
30
|
|
46
31
|
def _generate_uncommitted_id_str():
|
@@ -58,55 +43,63 @@ def _create_or_join_session(
|
|
58
43
|
yield session
|
59
44
|
|
60
45
|
|
61
|
-
class
|
62
|
-
"""Base for orm wrappers providing a unified update mechanism."""
|
63
|
-
|
46
|
+
class HasProtoSelf(Generic[_ProtoObj], abc.ABC):
|
64
47
|
client: Final[system.Client]
|
65
48
|
proto_self: Final[_ProtoObj]
|
66
49
|
|
67
50
|
def __init__(self, client: system.Client, proto_self: _ProtoObj):
|
68
|
-
if not proto_self.id:
|
69
|
-
proto_self.id = _generate_uncommitted_id_str()
|
70
51
|
self.proto_self = proto_self
|
71
52
|
self.client = client
|
72
53
|
|
54
|
+
@property
|
55
|
+
def created_at(self) -> datetime.datetime | None:
|
56
|
+
if self.proto_self.created_at:
|
57
|
+
return self.proto_self.created_at.ToDatetime(tzinfo=datetime.timezone.utc)
|
58
|
+
return None
|
59
|
+
|
60
|
+
|
61
|
+
class UsesOrmID(Generic[ID, _ProtoObj], HasProtoSelf[_ProtoObj]):
|
62
|
+
def __init__(self, client: system.Client, proto_self: _ProtoObj):
|
63
|
+
if not proto_self.id:
|
64
|
+
proto_self.id = _generate_uncommitted_id_str()
|
65
|
+
super().__init__(client, proto_self)
|
66
|
+
|
73
67
|
@classmethod
|
74
68
|
@abc.abstractmethod
|
75
|
-
def
|
69
|
+
def id_class(cls) -> type[ID]: ...
|
70
|
+
|
71
|
+
@functools.cached_property
|
72
|
+
def id(self) -> ID:
|
73
|
+
return self.id_class().from_str(self.proto_self.id)
|
74
|
+
|
75
|
+
|
76
|
+
class BaseModel(Generic[ID, _ProtoObj, OrmObj], UsesOrmID[ID, _ProtoObj]):
|
77
|
+
"""Base for orm wrappers providing a unified update mechanism."""
|
76
78
|
|
77
79
|
@classmethod
|
78
80
|
@abc.abstractmethod
|
79
|
-
def
|
81
|
+
def orm_class(cls) -> type[OrmObj]: ...
|
80
82
|
|
81
83
|
@classmethod
|
82
84
|
@abc.abstractmethod
|
83
|
-
def orm_to_proto(cls, orm_obj:
|
85
|
+
def orm_to_proto(cls, orm_obj: OrmObj) -> _ProtoObj: ...
|
84
86
|
|
85
87
|
@classmethod
|
86
88
|
@abc.abstractmethod
|
87
89
|
def proto_to_orm(
|
88
90
|
cls, proto_obj: _ProtoObj, session: orm.Session
|
89
|
-
) -> Ok[
|
91
|
+
) -> Ok[OrmObj] | InvalidArgumentError: ...
|
92
|
+
|
90
93
|
@classmethod
|
91
94
|
@abc.abstractmethod
|
92
95
|
def delete_by_ids(
|
93
|
-
cls, ids: Sequence[
|
96
|
+
cls, ids: Sequence[ID], session: orm.Session
|
94
97
|
) -> Ok[None] | InvalidArgumentError: ...
|
95
98
|
|
96
|
-
@functools.cached_property
|
97
|
-
def id(self) -> _ID:
|
98
|
-
return self.id_class().from_str(self.proto_self.id)
|
99
|
-
|
100
|
-
@property
|
101
|
-
def created_at(self) -> datetime.datetime | None:
|
102
|
-
if self.proto_self.created_at:
|
103
|
-
return self.proto_self.created_at.ToDatetime(tzinfo=datetime.timezone.utc)
|
104
|
-
return None
|
105
|
-
|
106
99
|
@classmethod
|
107
100
|
def load_proto_for(
|
108
101
|
cls,
|
109
|
-
obj_id:
|
102
|
+
obj_id: ID,
|
110
103
|
client: system.Client,
|
111
104
|
existing_session: sa_orm.Session | None = None,
|
112
105
|
) -> Ok[_ProtoObj] | NotFoundError:
|
@@ -120,8 +113,8 @@ class BaseModel(Generic[_ID, _ProtoObj, _OrmObj], abc.ABC):
|
|
120
113
|
|
121
114
|
@classmethod
|
122
115
|
def _generate_query_results(
|
123
|
-
cls, query: sa.Select[tuple[
|
124
|
-
) -> Iterator[
|
116
|
+
cls, query: sa.Select[tuple[OrmObj]], session: sa_orm.Session
|
117
|
+
) -> Iterator[OrmObj]:
|
125
118
|
it = iter(session.scalars(query))
|
126
119
|
while True:
|
127
120
|
try:
|
@@ -147,9 +140,9 @@ class BaseModel(Generic[_ID, _ProtoObj, _OrmObj], abc.ABC):
|
|
147
140
|
limit: int | None = None,
|
148
141
|
room_id: orm.RoomID | None = None,
|
149
142
|
created_before: datetime.datetime | None = None,
|
150
|
-
ids: Iterable[
|
143
|
+
ids: Iterable[ID] | None = None,
|
151
144
|
additional_query_transform: Callable[
|
152
|
-
[sa.Select[tuple[
|
145
|
+
[sa.Select[tuple[OrmObj]]], sa.Select[tuple[OrmObj]]
|
153
146
|
]
|
154
147
|
| None = None,
|
155
148
|
existing_session: sa_orm.Session | None = None,
|
corvic/model/_feature_view.py
CHANGED
@@ -18,15 +18,12 @@ from sqlalchemy.orm.interfaces import LoaderOption
|
|
18
18
|
from typing_extensions import Self
|
19
19
|
|
20
20
|
from corvic import op_graph, orm, system
|
21
|
-
from corvic.model._base_model import BaseModel
|
21
|
+
from corvic.model._base_model import BaseModel, UsesOrmID
|
22
22
|
from corvic.model._defaults import Defaults
|
23
23
|
from corvic.model._proto_orm_convert import (
|
24
24
|
feature_view_delete_orms,
|
25
25
|
feature_view_orm_to_proto,
|
26
26
|
feature_view_proto_to_orm,
|
27
|
-
feature_view_source_delete_orms,
|
28
|
-
feature_view_source_orm_to_proto,
|
29
|
-
feature_view_source_proto_to_orm,
|
30
27
|
)
|
31
28
|
from corvic.model._source import Source, SourceID
|
32
29
|
from corvic.result import InvalidArgumentError, NotFoundError, Ok
|
@@ -541,36 +538,31 @@ class RelationshipPath:
|
|
541
538
|
return f"end-{uuid.uuid4()}"
|
542
539
|
|
543
540
|
|
544
|
-
class FeatureViewSource(
|
545
|
-
BaseModel[FeatureViewSourceID, models_pb2.FeatureViewSource, orm.FeatureViewSource]
|
546
|
-
):
|
541
|
+
class FeatureViewSource(UsesOrmID[FeatureViewSourceID, models_pb2.FeatureViewSource]):
|
547
542
|
"""A table from a source with some extra operations defined by a feature view."""
|
548
543
|
|
549
|
-
@classmethod
|
550
|
-
def orm_class(cls):
|
551
|
-
return orm.FeatureViewSource
|
552
|
-
|
553
544
|
@classmethod
|
554
545
|
def id_class(cls):
|
555
546
|
return FeatureViewSourceID
|
556
547
|
|
557
548
|
@classmethod
|
558
|
-
def
|
559
|
-
cls,
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
549
|
+
def create(
|
550
|
+
cls,
|
551
|
+
table: Table,
|
552
|
+
source: Source,
|
553
|
+
*,
|
554
|
+
drop_disconnected: bool,
|
555
|
+
room_id: orm.RoomID,
|
556
|
+
):
|
557
|
+
return cls(
|
558
|
+
source.client,
|
559
|
+
models_pb2.FeatureViewSource(
|
560
|
+
source=source.proto_self,
|
561
|
+
table_op_graph=table.op_graph.to_proto(),
|
562
|
+
drop_disconnected=drop_disconnected,
|
563
|
+
room_id=str(room_id),
|
564
|
+
),
|
565
|
+
)
|
574
566
|
|
575
567
|
def with_table(self, table: Table | op_graph.Op) -> FeatureViewSource:
|
576
568
|
if isinstance(table, Table):
|
@@ -713,12 +705,8 @@ class FeatureView(BaseModel[FeatureViewID, models_pb2.FeatureView, orm.FeatureVi
|
|
713
705
|
return [
|
714
706
|
sa_orm.selectinload(orm.FeatureView.feature_view_sources)
|
715
707
|
.selectinload(orm.FeatureViewSource.source)
|
716
|
-
.selectinload(orm.Source.
|
717
|
-
.selectinload(orm.
|
718
|
-
sa_orm.selectinload(orm.FeatureView.feature_view_sources)
|
719
|
-
.selectinload(orm.FeatureViewSource.source)
|
720
|
-
.selectinload(orm.Source.pipeline_output_refs)
|
721
|
-
.selectinload(orm.PipelineOutput.pipeline),
|
708
|
+
.selectinload(orm.Source.pipeline_ref)
|
709
|
+
.selectinload(orm.PipelineOutput.source)
|
722
710
|
]
|
723
711
|
|
724
712
|
@classmethod
|
@@ -775,12 +763,19 @@ class FeatureView(BaseModel[FeatureViewID, models_pb2.FeatureView, orm.FeatureVi
|
|
775
763
|
]
|
776
764
|
|
777
765
|
@functools.cached_property
|
778
|
-
def
|
766
|
+
def output_source_ids(self) -> set[SourceID]:
|
779
767
|
return {
|
780
768
|
SourceID(output_source.source_id)
|
781
769
|
for output_source in self.proto_self.feature_view_output.output_sources
|
782
770
|
}
|
783
771
|
|
772
|
+
@functools.cached_property
|
773
|
+
def output_sources(self) -> Sequence[Source]:
|
774
|
+
return [
|
775
|
+
self.source_id_to_feature_view_source[source_id].source
|
776
|
+
for source_id in self.output_source_ids
|
777
|
+
]
|
778
|
+
|
784
779
|
@functools.cached_property
|
785
780
|
def source_id_to_feature_view_source(self) -> Mapping[SourceID, FeatureViewSource]:
|
786
781
|
return {fvs.source.id: fvs for fvs in self.feature_view_sources}
|
@@ -846,7 +841,7 @@ class FeatureView(BaseModel[FeatureViewID, models_pb2.FeatureView, orm.FeatureVi
|
|
846
841
|
paths_between_outputs = list(
|
847
842
|
flatten(
|
848
843
|
self._calculate_paths_to_outputs(output, self.relationships)
|
849
|
-
for output in self.
|
844
|
+
for output in self.output_source_ids
|
850
845
|
)
|
851
846
|
)
|
852
847
|
return [RelationshipPath(path) for path in paths_between_outputs]
|
@@ -857,7 +852,7 @@ class FeatureView(BaseModel[FeatureViewID, models_pb2.FeatureView, orm.FeatureVi
|
|
857
852
|
paths: list[list[Relationship]] = []
|
858
853
|
for rel in rels:
|
859
854
|
if rel.start_source.id == output:
|
860
|
-
if rel.end_source.id in self.
|
855
|
+
if rel.end_source.id in self.output_source_ids:
|
861
856
|
paths.append([rel])
|
862
857
|
else:
|
863
858
|
child_paths = self._calculate_paths_to_outputs(
|
@@ -944,7 +939,7 @@ class FeatureView(BaseModel[FeatureViewID, models_pb2.FeatureView, orm.FeatureVi
|
|
944
939
|
)
|
945
940
|
node_tables = {
|
946
941
|
source_id: self.source_id_to_feature_view_source[source_id].table
|
947
|
-
for source_id in self.
|
942
|
+
for source_id in self.output_source_ids
|
948
943
|
}
|
949
944
|
node_id_columns = _validate_deepgnn_nodes(node_tables).unwrap_or_raise()
|
950
945
|
|
@@ -1034,6 +1029,11 @@ class FeatureView(BaseModel[FeatureViewID, models_pb2.FeatureView, orm.FeatureVi
|
|
1034
1029
|
new_proto_self.name = name
|
1035
1030
|
return self.__class__(self.client, proto_self=new_proto_self)
|
1036
1031
|
|
1032
|
+
def with_description(self, description: str) -> Self:
|
1033
|
+
new_proto_self = copy.deepcopy(self.proto_self)
|
1034
|
+
new_proto_self.description = description
|
1035
|
+
return self.__class__(self.client, proto_self=new_proto_self)
|
1036
|
+
|
1037
1037
|
def with_source(
|
1038
1038
|
self,
|
1039
1039
|
source: SourceID | Source,
|
@@ -1074,15 +1074,15 @@ class FeatureView(BaseModel[FeatureViewID, models_pb2.FeatureView, orm.FeatureVi
|
|
1074
1074
|
FeatureViewSourceColumnRenames(column_renames=renames)
|
1075
1075
|
)
|
1076
1076
|
|
1077
|
-
|
1078
|
-
room_id=
|
1079
|
-
|
1077
|
+
fvs = FeatureViewSource.create(
|
1078
|
+
room_id=source.room_id,
|
1079
|
+
table=new_table,
|
1080
1080
|
drop_disconnected=drop_disconnected,
|
1081
|
-
source=source
|
1081
|
+
source=source,
|
1082
1082
|
)
|
1083
1083
|
|
1084
1084
|
new_proto_self = copy.deepcopy(self.proto_self)
|
1085
|
-
new_proto_self.feature_view_sources.append(
|
1085
|
+
new_proto_self.feature_view_sources.append(fvs.proto_self)
|
1086
1086
|
|
1087
1087
|
if output:
|
1088
1088
|
primary_key = source.table.schema.get_primary_key()
|
@@ -1336,7 +1336,7 @@ class FeatureView(BaseModel[FeatureViewID, models_pb2.FeatureView, orm.FeatureVi
|
|
1336
1336
|
del new_proto_self.feature_view_sources[:]
|
1337
1337
|
|
1338
1338
|
for fvs in self.feature_view_sources:
|
1339
|
-
if fvs.source.id in self.
|
1339
|
+
if fvs.source.id in self.output_source_ids:
|
1340
1340
|
row_id_column = f"row-id-{uuid.uuid4()}"
|
1341
1341
|
# TODO(Patrick): make row ids stable
|
1342
1342
|
new_fvs = fvs.with_table(
|
corvic/model/_pipeline.py
CHANGED
@@ -124,22 +124,10 @@ class Pipeline(BaseModel[PipelineID, models_pb2.Pipeline, orm.Pipeline]):
|
|
124
124
|
return [
|
125
125
|
sa_orm.selectinload(orm.Pipeline.inputs)
|
126
126
|
.selectinload(orm.PipelineInput.resource)
|
127
|
-
.selectinload(orm.Resource.
|
128
|
-
sa_orm.selectinload(orm.Pipeline.inputs)
|
129
|
-
.selectinload(orm.PipelineInput.resource)
|
130
|
-
.selectinload(orm.Resource.pipeline_input_refs),
|
131
|
-
sa_orm.selectinload(orm.Pipeline.inputs).selectinload(
|
132
|
-
orm.PipelineInput.pipeline
|
133
|
-
),
|
134
|
-
sa_orm.selectinload(orm.Pipeline.outputs).selectinload(
|
135
|
-
orm.PipelineOutput.pipeline
|
136
|
-
),
|
137
|
-
sa_orm.selectinload(orm.Pipeline.outputs)
|
138
|
-
.selectinload(orm.PipelineOutput.source)
|
139
|
-
.selectinload(orm.Source.resource_associations),
|
127
|
+
.selectinload(orm.Resource.pipeline_ref),
|
140
128
|
sa_orm.selectinload(orm.Pipeline.outputs)
|
141
129
|
.selectinload(orm.PipelineOutput.source)
|
142
|
-
.selectinload(orm.Source.
|
130
|
+
.selectinload(orm.Source.pipeline_ref),
|
143
131
|
]
|
144
132
|
|
145
133
|
@classmethod
|