Skip to content

Commit

Permalink
Added support for transformation of explore request (#224)
Browse files Browse the repository at this point in the history
* Added support for transformation of explore request

* Update hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/DefaultExploreRequestBuilder.java

Co-authored-by: Aaron Steinfeld <[email protected]>

---------

Co-authored-by: Aaron Steinfeld <[email protected]>
  • Loading branch information
avinashkolluru and aaron-steinfeld authored May 2, 2024
1 parent 857b861 commit cd911fb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import graphql.schema.DataFetchingFieldSelectionSet;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -190,6 +191,46 @@ public Single<ExploreRequest> build(
groupBy.map(GroupByArgument::groupLimit)));
}

@Override
public Single<ExploreRequest> rebuildWithAdditionalFilters(
ExploreRequest originalRequest, List<FilterArgument> additionalFilterArguments) {
return this.mergeFilterLists(
originalRequest.context(),
originalRequest.scope(),
originalRequest.filterArguments(),
additionalFilterArguments)
.map(
newFilterArguments ->
new DefaultExploreRequest(
originalRequest.context(),
originalRequest.scope(),
originalRequest.timeRange(),
originalRequest.limit(),
originalRequest.offset(),
originalRequest.attributeRequests(),
originalRequest.aggregationRequests(),
originalRequest.orderArguments(),
newFilterArguments,
originalRequest.groupByAttributeRequests(),
originalRequest.timeInterval(),
originalRequest.entityContextOptions(),
originalRequest.includeRest(),
originalRequest.spaceId(),
originalRequest.groupLimit()));
}

private Single<List<AttributeAssociation<FilterArgument>>> mergeFilterLists(
GraphQlRequestContext requestContext,
String scope,
Collection<AttributeAssociation<FilterArgument>> original,
Collection<FilterArgument> additional) {
return this.filterRequestBuilder
.build(requestContext, scope, additional)
.flattenAsObservable(list -> list)
.concatWith(Observable.fromIterable(original))
.toList();
}

private Single<Set<AttributeRequest>> buildGroupByAttributes(
GraphQlRequestContext context,
String explorerScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ Single<ExploreRequest> build(
Optional<EntityContextOptions> entityContextOptions,
Single<Set<AttributeRequest>> attributeSelections,
Single<Set<MetricAggregationRequest>> aggregationSelections);

Single<ExploreRequest> rebuildWithAdditionalFilters(
ExploreRequest originalRequest, List<FilterArgument> filterArguments);
}

0 comments on commit cd911fb

Please sign in to comment.