Repository navigation
Expand file tree
/
Copy pathlineage.py
More file actions
142 lines (125 loc) · 5.22 KB
/
Copy pathlineage.py
File metadata and controls
142 lines (125 loc) · 5.22 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
"""REST API endpoints for registry lineage and relationships."""
from typing import Optional
from fastapi import APIRouter, HTTPException, Query
from feast.api.registry.rest.rest_utils import 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),
):
"""
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 "",
)
response = grpc_call(grpc_handler.GetRegistryLineage, req)
return {
"relationships": response.get("relationships", []),
"indirect_relationships": response.get("indirectRelationships", []),
}
@router.get("/lineage/objects/{object_type}/{object_name}")
def get_object_relationships(
object_type: str,
object_name: str,
project: str = Query(...),
include_indirect: bool = Query(False),
allow_cache: bool = Query(True),
):
"""
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: {valid_types}",
)
req = RegistryServer_pb2.GetObjectRelationshipsRequest(
project=project,
object_type=object_type,
object_name=object_name,
include_indirect=include_indirect,
allow_cache=allow_cache,
)
response = grpc_call(grpc_handler.GetObjectRelationships, req)
return {"relationships": response.get("relationships", [])}
@router.get("/lineage/complete")
def get_complete_registry_data(
project: str = Query(...),
allow_cache: bool = Query(True),
):
"""
Get complete registry data.
This endpoint provides all the data the UI currently loads:
- All registry objects
- Relationships
- Indirect relationships
- Merged feature view data
Returns:
Complete registry data structure.
"""
# Get lineage data
lineage_req = RegistryServer_pb2.GetRegistryLineageRequest(
project=project,
allow_cache=allow_cache,
)
lineage_response = grpc_call(grpc_handler.GetRegistryLineage, lineage_req)
# Get all registry objects
entities_req = RegistryServer_pb2.ListEntitiesRequest(
project=project, allow_cache=allow_cache
)
entities_response = grpc_call(grpc_handler.ListEntities, entities_req)
data_sources_req = RegistryServer_pb2.ListDataSourcesRequest(
project=project, allow_cache=allow_cache
)
data_sources_response = grpc_call(
grpc_handler.ListDataSources, data_sources_req
)
feature_views_req = RegistryServer_pb2.ListAllFeatureViewsRequest(
project=project, allow_cache=allow_cache
)
feature_views_response = grpc_call(
grpc_handler.ListAllFeatureViews, feature_views_req
)
feature_services_req = RegistryServer_pb2.ListFeatureServicesRequest(
project=project, allow_cache=allow_cache
)
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", []),
}
return router