-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathlineage.py
More file actions
199 lines (178 loc) · 7.68 KB
/
Copy pathlineage.py
File metadata and controls
199 lines (178 loc) · 7.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
"""REST API endpoints for registry lineage and relationships."""
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, Query
from feast.api.registry.rest.rest_utils import (
create_grpc_pagination_params,
create_grpc_sorting_params,
get_pagination_params,
get_sorting_params,
grpc_call,
)
from feast.protos.feast.registry import RegistryServer_pb2
def get_lineage_router(grpc_handler) -> APIRouter:
router = APIRouter()
@router.get("/lineage/registry")
def get_registry_lineage(
project: str = Query(...),
allow_cache: bool = Query(True),
filter_object_type: Optional[str] = Query(None),
filter_object_name: Optional[str] = Query(None),
pagination_params: dict = Depends(get_pagination_params),
sorting_params: dict = Depends(get_sorting_params),
):
"""
Get complete registry lineage with relationships and indirect relationships.
Args:
project: Project name
allow_cache: Whether to allow cached data
filter_object_type: Optional filter by object type (dataSource, entity, featureView, featureService)
filter_object_name: Optional filter by object name
Returns:
Dictionary containing relationships and indirect_relationships arrays
"""
req = RegistryServer_pb2.GetRegistryLineageRequest(
project=project,
allow_cache=allow_cache,
filter_object_type=filter_object_type or "",
filter_object_name=filter_object_name or "",
pagination=create_grpc_pagination_params(pagination_params),
sorting=create_grpc_sorting_params(sorting_params),
)
response = grpc_call(grpc_handler.GetRegistryLineage, req)
return {
"relationships": response.get("relationships", []),
"indirect_relationships": response.get("indirectRelationships", []),
"relationships_pagination": response.get("relationshipsPagination", {}),
"indirect_relationships_pagination": response.get(
"indirectRelationshipsPagination", {}
),
}
@router.get("/lineage/objects/{object_type}/{object_name}")
def get_object_relationships_path(
object_type: str,
object_name: str,
project: str = Query(...),
include_indirect: bool = Query(False),
allow_cache: bool = Query(True),
pagination_params: dict = Depends(get_pagination_params),
sorting_params: dict = Depends(get_sorting_params),
):
"""
Get relationships for a specific object.
Args:
object_type: Type of object (dataSource, entity, featureView, featureService)
object_name: Name of the object
project: Project name
include_indirect: Whether to include indirect relationships
allow_cache: Whether to allow cached data
Returns:
Dictionary containing relationships array for the specific object
"""
valid_types = ["dataSource", "entity", "featureView", "featureService"]
if object_type not in valid_types:
raise HTTPException(
status_code=400,
detail=f"Invalid object_type. Must be one of: {', '.join(valid_types)}",
)
req = RegistryServer_pb2.GetObjectRelationshipsRequest(
project=project,
object_type=object_type,
object_name=object_name,
include_indirect=include_indirect,
allow_cache=allow_cache,
pagination=create_grpc_pagination_params(pagination_params),
sorting=create_grpc_sorting_params(sorting_params),
)
return grpc_call(grpc_handler.GetObjectRelationships, req)
@router.get("/lineage/complete")
def get_complete_registry_data(
project: str = Query(...),
allow_cache: bool = Query(True),
pagination_params: dict = Depends(get_pagination_params),
sorting_params: dict = Depends(get_sorting_params),
):
"""
Get complete registry data.
This endpoint provides all the data the UI currently loads:
- All registry objects
- Relationships
- Indirect relationships
- Merged feature view data
Args:
project: Project name
allow_cache: Whether to allow cached data
pagination_params: Pagination parameters (page, page_size)
sorting_params: Sorting parameters (sort_by, sort_order)
Returns:
Complete registry data structure with pagination metadata.
Note:
Pagination and sorting are applied to each object type separately.
"""
# Create pagination and sorting parameters for gRPC calls
grpc_pagination = create_grpc_pagination_params(pagination_params)
grpc_sorting = create_grpc_sorting_params(sorting_params)
# Get lineage data
lineage_req = RegistryServer_pb2.GetRegistryLineageRequest(
project=project,
allow_cache=allow_cache,
pagination=grpc_pagination,
sorting=grpc_sorting,
)
lineage_response = grpc_call(grpc_handler.GetRegistryLineage, lineage_req)
# Get all registry objects
entities_req = RegistryServer_pb2.ListEntitiesRequest(
project=project,
allow_cache=allow_cache,
pagination=grpc_pagination,
sorting=grpc_sorting,
)
entities_response = grpc_call(grpc_handler.ListEntities, entities_req)
data_sources_req = RegistryServer_pb2.ListDataSourcesRequest(
project=project,
allow_cache=allow_cache,
pagination=grpc_pagination,
sorting=grpc_sorting,
)
data_sources_response = grpc_call(
grpc_handler.ListDataSources, data_sources_req
)
feature_views_req = RegistryServer_pb2.ListAllFeatureViewsRequest(
project=project,
allow_cache=allow_cache,
pagination=grpc_pagination,
sorting=grpc_sorting,
)
feature_views_response = grpc_call(
grpc_handler.ListAllFeatureViews, feature_views_req
)
feature_services_req = RegistryServer_pb2.ListFeatureServicesRequest(
project=project,
allow_cache=allow_cache,
pagination=grpc_pagination,
sorting=grpc_sorting,
)
feature_services_response = grpc_call(
grpc_handler.ListFeatureServices, feature_services_req
)
return {
"project": project,
"objects": {
"entities": entities_response.get("entities", []),
"dataSources": data_sources_response.get("dataSources", []),
"featureViews": feature_views_response.get("featureViews", []),
"featureServices": feature_services_response.get("featureServices", []),
},
"relationships": lineage_response.get("relationships", []),
"indirectRelationships": lineage_response.get("indirectRelationships", []),
"pagination": {
"entities": entities_response.get("pagination", {}),
"dataSources": data_sources_response.get("pagination", {}),
"featureViews": feature_views_response.get("pagination", {}),
"featureServices": feature_services_response.get("pagination", {}),
"relationships": lineage_response.get("relationshipsPagination", {}),
"indirectRelationships": lineage_response.get(
"indirectRelationshipsPagination", {}
),
},
}
return router