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

Commit

Permalink
push limit and offset to EQS
Browse files Browse the repository at this point in the history
  • Loading branch information
skjindal93 committed Oct 30, 2023
1 parent 7c6a52b commit 4c5f357
Showing 1 changed file with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
import org.hypertrace.gateway.service.explore.ExploreRequestContext;
import org.hypertrace.gateway.service.v1.common.OrderByExpression;
import org.hypertrace.gateway.service.v1.explore.ExploreRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EntityServiceEntityFetcher {
private static final Logger LOG = LoggerFactory.getLogger(EntityServiceEntityFetcher.class);
private static final int DEFAULT_ENTITY_REQUEST_LIMIT = 10_000;

private final AttributeMetadataProvider attributeMetadataProvider;
Expand Down Expand Up @@ -60,16 +63,19 @@ private EntityQueryRequest buildRequest(

addGroupBys(exploreRequest, builder);
addSelections(requestContext, exploreRequest, builder);

// Ideally, needs the limit and offset for group by, since the fetcher is only triggered when
// there is a group by, or a single aggregation selection. A single aggregated selection would
// always return a single result (i.e. limit 1)
builder.setLimit(DEFAULT_ENTITY_REQUEST_LIMIT);

// TODO: Push group by down to EQS
// If there is a group by, specify a large limit and track actual limit, offset and order by
// expression list, so we can compute these once the we get the results.
if (requestContext.hasGroupBy()) {
addLimitAndOffset(requestContext, exploreRequest, builder);

Check warning on line 66 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L66

Added line #L66 was not covered by tests

// TODO: Push order by down to EQS
// EQS (and document-store) currently doesn't support order by on functional expressions
// If there are order by expressions, specify a large limit and track actual limit, offset and
// order by
// expression list, so we can compute these once we get the results.
if (!requestContext.getOrderByExpressions().isEmpty()) {
// Ideally, needs the limit and offset for group by, since the fetcher is only triggered when
// there is a group by, or a single aggregation selection. A single aggregated selection would
// always return a single result (i.e. limit 1)
builder.setOffset(0);
builder.setLimit(DEFAULT_ENTITY_REQUEST_LIMIT);

Check warning on line 78 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L77-L78

Added lines #L77 - L78 were not covered by tests
// Will need to do the ordering, limit and offset ourselves after we get the group by results
requestContext.setOrderByExpressions(getRequestOrderByExpressions(exploreRequest));

Check warning on line 80 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L80

Added line #L80 was not covered by tests
}
Expand Down Expand Up @@ -107,6 +113,33 @@ private void addSelections(
});
}

private void addLimitAndOffset(
ExploreRequestContext requestContext,
ExploreRequest exploreRequest,
EntityQueryRequest.Builder builder) {
// handle group by scenario with group limit set
if (requestContext.hasGroupBy()) {
int limit = exploreRequest.getLimit();

Check warning on line 122 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L122

Added line #L122 was not covered by tests
if (exploreRequest.getGroupLimit() > 0) {
// in group by scenario, set limit to minimum of limit or group-limit
limit = Math.min(exploreRequest.getLimit(), exploreRequest.getGroupLimit());

Check warning on line 125 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L125

Added line #L125 was not covered by tests
}
// don't exceed default group by limit
if (limit > DEFAULT_ENTITY_REQUEST_LIMIT) {
LOG.error(

Check warning on line 129 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L129

Added line #L129 was not covered by tests
"Trying to query for rows more than the default limit {} : {}",
DEFAULT_ENTITY_REQUEST_LIMIT,

Check warning on line 131 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L131

Added line #L131 was not covered by tests
exploreRequest);
throw new UnsupportedOperationException(

Check warning on line 133 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L133

Added line #L133 was not covered by tests
"Trying to query for rows more than the default limit " + exploreRequest);
}
builder.setLimit(limit);
} else {
builder.setLimit(exploreRequest.getLimit());
builder.setOffset(exploreRequest.getOffset());

Check warning on line 139 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L136-L139

Added lines #L136 - L139 were not covered by tests
}
}

Check warning on line 141 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L141

Added line #L141 was not covered by tests

private Filter.Builder buildFilter(
ExploreRequest exploreRequest, List<String> entityIdAttributeIds, Set<String> entityIds) {
Builder filterBuilder =
Expand Down

0 comments on commit 4c5f357

Please sign in to comment.