Search in sources :

Example 1 with OrderByExpression

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());
}
Also used : TotalEntitiesRequest(org.hypertrace.entity.query.service.v1.TotalEntitiesRequest) EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) AttributeScope(org.hypertrace.core.attribute.service.v1.AttributeScope) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) EntityQueryRequest(org.hypertrace.entity.query.service.v1.EntityQueryRequest) ResultSetChunk(org.hypertrace.entity.query.service.v1.ResultSetChunk) Test(org.junit.jupiter.api.Test)

Example 2 with OrderByExpression

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));
}
Also used : OrderByExpression(org.hypertrace.entity.query.service.v1.OrderByExpression) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with OrderByExpression

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();
}
Also used : ArrayList(java.util.ArrayList) SortingSpec(org.hypertrace.core.documentstore.query.SortingSpec) OrderByExpression(org.hypertrace.entity.query.service.v1.OrderByExpression)

Example 4 with OrderByExpression

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());
}
Also used : TotalEntitiesRequest(org.hypertrace.entity.query.service.v1.TotalEntitiesRequest) EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) AttributeScope(org.hypertrace.core.attribute.service.v1.AttributeScope) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) EntityQueryRequest(org.hypertrace.entity.query.service.v1.EntityQueryRequest) ResultSetChunk(org.hypertrace.entity.query.service.v1.ResultSetChunk) Test(org.junit.jupiter.api.Test)

Example 5 with OrderByExpression

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);
}
Also used : Query(org.hypertrace.core.documentstore.query.Query) AggregationModule(org.hypertrace.entity.query.service.converter.aggregation.AggregationModule) ConstantExpression(org.hypertrace.core.documentstore.expression.impl.ConstantExpression) FilterModule(org.hypertrace.entity.query.service.converter.filter.FilterModule) ResponseModule(org.hypertrace.entity.query.service.converter.response.ResponseModule) AccessorModule(org.hypertrace.entity.query.service.converter.accessor.AccessorModule) LiteralConstant(org.hypertrace.entity.query.service.v1.LiteralConstant) SelectionConverterModule(org.hypertrace.entity.query.service.converter.selection.SelectionConverterModule) TypeLiteral(com.google.inject.TypeLiteral) Sort(org.hypertrace.core.documentstore.query.Sort) List(java.util.List) IdentifierModule(org.hypertrace.entity.query.service.converter.identifier.IdentifierModule) EntityQueryRequest(org.hypertrace.entity.query.service.v1.EntityQueryRequest)

Aggregations

EntityQueryRequest (org.hypertrace.entity.query.service.v1.EntityQueryRequest)5 Test (org.junit.jupiter.api.Test)4 OrderByExpression (org.hypertrace.entity.query.service.v1.OrderByExpression)3 AttributeScope (org.hypertrace.core.attribute.service.v1.AttributeScope)2 Query (org.hypertrace.entity.data.service.v1.Query)2 ResultSetChunk (org.hypertrace.entity.query.service.v1.ResultSetChunk)2 TotalEntitiesRequest (org.hypertrace.entity.query.service.v1.TotalEntitiesRequest)2 EntitiesRequestAndResponseUtils.buildOrderByExpression (org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression)2 EntitiesRequestContext (org.hypertrace.gateway.service.entity.EntitiesRequestContext)2 OrderByExpression (org.hypertrace.gateway.service.v1.common.OrderByExpression)2 EntitiesRequest (org.hypertrace.gateway.service.v1.entity.EntitiesRequest)2 TypeLiteral (com.google.inject.TypeLiteral)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConstantExpression (org.hypertrace.core.documentstore.expression.impl.ConstantExpression)1 IdentifierExpression (org.hypertrace.core.documentstore.expression.impl.IdentifierExpression)1 SortOrder (org.hypertrace.core.documentstore.expression.operators.SortOrder)1 Query (org.hypertrace.core.documentstore.query.Query)1 Sort (org.hypertrace.core.documentstore.query.Sort)1 SortingSpec (org.hypertrace.core.documentstore.query.SortingSpec)1