use of org.hypertrace.entity.query.service.v1.OrderByExpression in project gateway-service by hypertrace.
the class EntityDataServiceEntityFetcherTests method test_getEntities_WithoutPagination.
@Test
public void test_getEntities_WithoutPagination() {
List<OrderByExpression> orderByExpressions = List.of(buildOrderByExpression(API_ID_ATTR));
long startTime = 1L;
long endTime = 10L;
int limit = 0;
int offset = 0;
String tenantId = "TENANT_ID";
Map<String, String> requestHeaders = Map.of("x-tenant-id", tenantId);
AttributeScope entityType = AttributeScope.API;
EntitiesRequest entitiesRequest = EntitiesRequest.newBuilder().setEntityType(entityType.name()).setStartTimeMillis(startTime).setEndTimeMillis(endTime).setFilter(Filter.newBuilder().setOperator(AND).addChildFilter(generateEQFilter(API_TYPE_ATTR, "HTTP")).addChildFilter(generateEQFilter(API_NAME_ATTR, "DISCOVERED"))).addAllOrderBy(orderByExpressions).setLimit(limit).setOffset(offset).build();
EntitiesRequestContext entitiesRequestContext = new EntitiesRequestContext(tenantId, startTime, endTime, entityType.name(), "API.startTime", requestHeaders);
EntityQueryRequest expectedQueryRequest = EntityQueryRequest.newBuilder().setEntityType("API").addSelection(convertToEntityServiceExpression(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName(API_ID_ATTR)).build())).setFilter(convertToEntityServiceFilter(entitiesRequest.getFilter())).addAllOrderBy(EntityServiceAndGatewayServiceConverter.convertToOrderByExpressions(orderByExpressions)).build();
List<ResultSetChunk> resultSetChunks = List.of(getResultSetChunk(List.of("API.apiId"), new String[][] { { "apiId1" }, { "apiId2" } }));
when(entityQueryServiceClient.execute(eq(expectedQueryRequest), eq(requestHeaders))).thenReturn(resultSetChunks.iterator());
assertEquals(2, entityDataServiceEntityFetcher.getEntities(entitiesRequestContext, entitiesRequest).size());
}
use of org.hypertrace.entity.query.service.v1.OrderByExpression in project entity-service by hypertrace.
the class OrderByConverterTest method testConvertCoverage.
@ParameterizedTest
@EnumSource(value = org.hypertrace.entity.query.service.v1.SortOrder.class, mode = Mode.EXCLUDE, names = "UNRECOGNIZED")
void testConvertCoverage(final org.hypertrace.entity.query.service.v1.SortOrder sortOrder) throws ConversionException {
OrderByExpression orderByExpression = OrderByExpression.newBuilder().setExpression(Expression.newBuilder().setColumnIdentifier(columnIdentifier)).setOrder(sortOrder).build();
assertNotNull(orderByConverter.convert(List.of(orderByExpression), requestContext));
}
use of org.hypertrace.entity.query.service.v1.OrderByExpression in project entity-service by hypertrace.
the class OrderByConverter method convert.
@Override
public Sort convert(final List<OrderByExpression> orders, final RequestContext requestContext) throws ConversionException {
final List<SortingSpec> specs = new ArrayList<>();
for (final OrderByExpression orderBy : orders) {
final SortingSpec spec = convert(orderBy);
specs.add(spec);
}
return Sort.builder().sortingSpecs(specs).build();
}
use of org.hypertrace.entity.query.service.v1.OrderByExpression in project gateway-service by hypertrace.
the class EntityDataServiceEntityFetcherTests method test_getEntities_WithPagination.
@Test
public void test_getEntities_WithPagination() {
List<OrderByExpression> orderByExpressions = List.of(buildOrderByExpression(API_ID_ATTR));
long startTime = 1L;
long endTime = 10L;
int limit = 10;
int offset = 5;
String tenantId = "TENANT_ID";
Map<String, String> requestHeaders = Map.of("x-tenant-id", tenantId);
AttributeScope entityType = AttributeScope.API;
EntitiesRequest entitiesRequest = EntitiesRequest.newBuilder().setEntityType(entityType.name()).setStartTimeMillis(startTime).setEndTimeMillis(endTime).setFilter(Filter.newBuilder().setOperator(AND).addChildFilter(generateEQFilter(API_TYPE_ATTR, "HTTP")).addChildFilter(generateEQFilter(API_NAME_ATTR, "DISCOVERED"))).addAllOrderBy(orderByExpressions).setLimit(limit).setOffset(offset).build();
EntitiesRequestContext entitiesRequestContext = new EntitiesRequestContext(tenantId, startTime, endTime, entityType.name(), "API.startTime", requestHeaders);
EntityQueryRequest expectedQueryRequest = EntityQueryRequest.newBuilder().setEntityType("API").addSelection(convertToEntityServiceExpression(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName(API_ID_ATTR)).build())).setFilter(convertToEntityServiceFilter(entitiesRequest.getFilter())).setOffset(offset).setLimit(limit).addAllOrderBy(EntityServiceAndGatewayServiceConverter.convertToOrderByExpressions(orderByExpressions)).build();
List<ResultSetChunk> resultSetChunks = List.of(getResultSetChunk(List.of("API.apiId"), new String[][] { { "apiId1" }, { "apiId2" } }));
when(entityQueryServiceClient.execute(eq(expectedQueryRequest), eq(requestHeaders))).thenReturn(resultSetChunks.iterator());
assertEquals(2, entityDataServiceEntityFetcher.getEntities(entitiesRequestContext, entitiesRequest).size());
}
use of org.hypertrace.entity.query.service.v1.OrderByExpression in project entity-service by hypertrace.
the class ConverterModule method configure.
@Override
protected void configure() {
install(new AccessorModule());
install(new AggregationModule());
install(new FilterModule());
install(new IdentifierModule());
install(new SelectionConverterModule());
install(new ResponseModule());
bind(new TypeLiteral<Converter<LiteralConstant, ConstantExpression>>() {
}).to(ConstantExpressionConverter.class);
bind(new TypeLiteral<Converter<List<OrderByExpression>, Sort>>() {
}).to(OrderByConverter.class);
bind(new TypeLiteral<Converter<EntityQueryRequest, Query>>() {
}).to(QueryConverter.class);
bind(new TypeLiteral<Converter<List<Expression>, List<FromTypeExpression>>>() {
}).to(FromClauseConverter.class);
}
Aggregations