Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
fixing refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-bansal committed Aug 22, 2023
1 parent ef4a0fc commit 2d0b2d0
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.hypertrace.gateway.service.explore.entity;

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.hypertrace.gateway.service.common.AttributeMetadataProvider;
import org.hypertrace.gateway.service.common.datafetcher.QueryServiceEntityFetcher;
import org.hypertrace.gateway.service.common.util.DataCollectionUtil;
import org.hypertrace.gateway.service.common.util.QueryServiceClient;
import org.hypertrace.gateway.service.entity.config.EntityIdColumnsConfigs;
import org.hypertrace.gateway.service.explore.ExploreRequestContext;
import org.hypertrace.gateway.service.explore.RequestHandler;
import org.hypertrace.gateway.service.explore.RowComparator;
import org.hypertrace.gateway.service.v1.common.OrderByExpression;
import org.hypertrace.gateway.service.v1.explore.EntityOption;
import org.hypertrace.gateway.service.v1.explore.ExploreRequest;
import org.hypertrace.gateway.service.v1.explore.ExploreResponse;
Expand Down Expand Up @@ -90,6 +94,33 @@ public ExploreResponse.Builder handleRequest(
return builder;
}

@Override
public void sortAndPaginatePostProcess(
ExploreResponse.Builder builder,
List<OrderByExpression> orderByExpressions,
int limit,
int offset) {
List<org.hypertrace.gateway.service.v1.common.Row.Builder> rowBuilders =
builder.getRowBuilderList();

List<org.hypertrace.gateway.service.v1.common.Row.Builder> sortedRowBuilders =
sortAndPaginateRowBuilders(rowBuilders, orderByExpressions, limit, offset);

builder.clearRow();
sortedRowBuilders.forEach(builder::addRow);
}

protected List<org.hypertrace.gateway.service.v1.common.Row.Builder> sortAndPaginateRowBuilders(
List<org.hypertrace.gateway.service.v1.common.Row.Builder> rowBuilders,
List<OrderByExpression> orderByExpressions,
int limit,
int offset) {
RowComparator rowComparator = new RowComparator(orderByExpressions);

return DataCollectionUtil.limitAndSort(
rowBuilders.stream(), limit, offset, orderByExpressions.size(), rowComparator);
}

private boolean requestOnLiveEntities(Optional<EntityOption> entityOption) {
if (entityOption.isEmpty()) {
return true;
Expand Down

0 comments on commit 2d0b2d0

Please sign in to comment.