2
2
3
3
import static com .linkedin .datahub .graphql .resolvers .ResolverUtils .*;
4
4
import static com .linkedin .datahub .graphql .resolvers .search .SearchUtils .*;
5
+ import static com .linkedin .metadata .Constants .QUERY_ENTITY_NAME ;
5
6
7
+ import com .google .common .collect .ImmutableSet ;
6
8
import com .linkedin .common .urn .Urn ;
7
9
import com .linkedin .datahub .graphql .generated .EntityType ;
8
10
import com .linkedin .datahub .graphql .generated .FacetFilterInput ;
14
16
import com .linkedin .datahub .graphql .types .entitytype .EntityTypeMapper ;
15
17
import com .linkedin .datahub .graphql .types .mappers .UrnSearchAcrossLineageResultsMapper ;
16
18
import com .linkedin .entity .client .EntityClient ;
19
+ import com .linkedin .metadata .models .EntitySpec ;
20
+ import com .linkedin .metadata .models .registry .EntityRegistry ;
17
21
import com .linkedin .metadata .query .SearchFlags ;
18
22
import com .linkedin .metadata .query .filter .Filter ;
23
+ import com .linkedin .metadata .search .LineageSearchResult ;
19
24
import com .linkedin .r2 .RemoteInvocationException ;
25
+ import graphql .VisibleForTesting ;
20
26
import graphql .schema .DataFetcher ;
21
27
import graphql .schema .DataFetchingEnvironment ;
22
28
import java .net .URISyntaxException ;
23
29
import java .util .ArrayList ;
24
30
import java .util .List ;
31
+ import java .util .Set ;
25
32
import java .util .concurrent .CompletableFuture ;
26
33
import java .util .stream .Collectors ;
27
34
import javax .annotation .Nullable ;
28
- import lombok .RequiredArgsConstructor ;
29
35
import lombok .extern .slf4j .Slf4j ;
30
36
31
37
/** Resolver responsible for resolving 'searchAcrossEntities' field of the Query type */
32
38
@ Slf4j
33
- @ RequiredArgsConstructor
34
39
public class SearchAcrossLineageResolver
35
40
implements DataFetcher <CompletableFuture <SearchAcrossLineageResults >> {
36
41
37
42
private static final int DEFAULT_START = 0 ;
38
43
private static final int DEFAULT_COUNT = 10 ;
39
44
45
+ private static final Set <String > TRANSIENT_ENTITIES = ImmutableSet .of (QUERY_ENTITY_NAME );
46
+
40
47
private final EntityClient _entityClient ;
41
48
49
+ private final EntityRegistry _entityRegistry ;
50
+
51
+ @ VisibleForTesting final Set <String > _allEntities ;
52
+ private final List <String > _allowedEntities ;
53
+
54
+ public SearchAcrossLineageResolver (EntityClient entityClient , EntityRegistry entityRegistry ) {
55
+ this ._entityClient = entityClient ;
56
+ this ._entityRegistry = entityRegistry ;
57
+ this ._allEntities =
58
+ entityRegistry .getEntitySpecs ().values ().stream ()
59
+ .map (EntitySpec ::getName )
60
+ .collect (Collectors .toSet ());
61
+
62
+ this ._allowedEntities =
63
+ this ._allEntities .stream ()
64
+ .filter (e -> !TRANSIENT_ENTITIES .contains (e ))
65
+ .collect (Collectors .toList ());
66
+ }
67
+
68
+ private List <String > getEntityNamesFromInput (List <EntityType > inputTypes ) {
69
+ if (inputTypes != null && !inputTypes .isEmpty ()) {
70
+ return inputTypes .stream ().map (EntityTypeMapper ::getName ).collect (Collectors .toList ());
71
+ } else {
72
+ return this ._allowedEntities ;
73
+ }
74
+ }
75
+
42
76
@ Override
43
77
public CompletableFuture <SearchAcrossLineageResults > get (DataFetchingEnvironment environment )
44
78
throws URISyntaxException {
@@ -50,12 +84,7 @@ public CompletableFuture<SearchAcrossLineageResults> get(DataFetchingEnvironment
50
84
51
85
final LineageDirection lineageDirection = input .getDirection ();
52
86
53
- List <EntityType > entityTypes =
54
- (input .getTypes () == null || input .getTypes ().isEmpty ())
55
- ? SEARCHABLE_ENTITY_TYPES
56
- : input .getTypes ();
57
- List <String > entityNames =
58
- entityTypes .stream ().map (EntityTypeMapper ::getName ).collect (Collectors .toList ());
87
+ List <String > entityNames = getEntityNamesFromInput (input .getTypes ());
59
88
60
89
// escape forward slash since it is a reserved character in Elasticsearch
61
90
final String sanitizedQuery =
@@ -99,8 +128,7 @@ public CompletableFuture<SearchAcrossLineageResults> get(DataFetchingEnvironment
99
128
} else {
100
129
searchFlags = new SearchFlags ().setFulltext (true ).setSkipHighlighting (true );
101
130
}
102
-
103
- return UrnSearchAcrossLineageResultsMapper .map (
131
+ LineageSearchResult salResults =
104
132
_entityClient .searchAcrossLineage (
105
133
urn ,
106
134
resolvedDirection ,
@@ -114,7 +142,9 @@ public CompletableFuture<SearchAcrossLineageResults> get(DataFetchingEnvironment
114
142
startTimeMillis ,
115
143
endTimeMillis ,
116
144
searchFlags ,
117
- ResolverUtils .getAuthentication (environment )));
145
+ getAuthentication (environment ));
146
+
147
+ return UrnSearchAcrossLineageResultsMapper .map (salResults );
118
148
} catch (RemoteInvocationException e ) {
119
149
log .error (
120
150
"Failed to execute search across relationships: source urn {}, direction {}, entity types {}, query {}, filters: {}, start: {}, count: {}" ,
0 commit comments