-
Notifications
You must be signed in to change notification settings - Fork 8
fix(explore): return early, if no entities #196
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,16 +88,21 @@ | |
@Override | ||
public ExploreResponse.Builder handleRequest( | ||
ExploreRequestContext requestContext, ExploreRequest request) { | ||
QueryRequest queryRequest = | ||
Optional<QueryRequest> maybeQueryRequest = | ||
buildQueryRequest(requestContext, request, attributeMetadataProvider); | ||
|
||
if (maybeQueryRequest.isEmpty()) { | ||
return ExploreResponse.newBuilder(); | ||
Check warning on line 95 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/RequestHandler.java Codecov / codecov/patchgateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/RequestHandler.java#L95
|
||
} | ||
|
||
QueryRequest queryRequest = maybeQueryRequest.get(); | ||
Iterator<ResultSetChunk> resultSetChunkIterator = executeQuery(requestContext, queryRequest); | ||
|
||
return handleQueryServiceResponse( | ||
request, requestContext, resultSetChunkIterator, requestContext, attributeMetadataProvider); | ||
} | ||
|
||
QueryRequest buildQueryRequest( | ||
Optional<QueryRequest> buildQueryRequest( | ||
ExploreRequestContext requestContext, | ||
ExploreRequest request, | ||
AttributeMetadataProvider attributeMetadataProvider) { | ||
|
@@ -113,12 +118,18 @@ | |
attributeMetadataProvider.getAttributesMetadata(requestContext, request.getContext()); | ||
if (hasOnlyAttributeSource(request.getFilter(), AttributeSource.EDS, attributeMetadataMap)) { | ||
entityIds = getEntityIdsToFilterFromSourceEDS(requestContext, request, attributeMetadataMap); | ||
|
||
if (entityIds.isEmpty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - worth a comment explaining why we shouldn't build a query request in this case |
||
return Optional.empty(); | ||
Check warning on line 123 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/RequestHandler.java Codecov / codecov/patchgateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/RequestHandler.java#L123
|
||
} | ||
|
||
qsSourceFilter = | ||
buildFilter(request.getFilter(), AttributeSource.QS, attributeMetadataMap) | ||
.orElse(request.getFilter()); | ||
} | ||
|
||
QueryRequest.Builder builder = QueryRequest.newBuilder(); | ||
|
||
// 1. Add selections. All selections should either be only column or only function, never both. | ||
// The validator should catch this. | ||
List<Expression> aggregatedSelections = | ||
|
@@ -160,7 +171,7 @@ | |
// 4. Add order by along with setting limit, offset | ||
addSortLimitAndOffset(request, requestContext, builder); | ||
|
||
return builder.build(); | ||
return Optional.of(builder.build()); | ||
} | ||
|
||
// This is to get all the entity Ids for the EDS source filter. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - prefer
.orElseThrow
over.get
(or move code around to avoid the direct access)