Search in sources :

Example 16 with EntitiesRequest

use of org.hypertrace.gateway.service.v1.entity.EntitiesRequest in project gateway-service by hypertrace.

the class ExecutionTreeBuilderTest method test_build_filterAndOrderBySameSourceSets_paginationToDataSourceToQs.

@Test
public void test_build_filterAndOrderBySameSourceSets_paginationToDataSourceToQs() {
    // filter and order by on QS
    // selections on both EDS and QS
    EntitiesRequest entitiesRequest = EntitiesRequest.newBuilder().setEntityType(AttributeScope.API.name()).addSelection(buildExpression(API_NAME_ATTR)).addSelection(buildAggregateExpression(API_NUM_CALLS_ATTR, FunctionType.SUM, "SUM_numCalls", List.of())).setFilter(getTimeRangeFilter(API_START_TIME_ATTR, System.currentTimeMillis() - 1000, System.currentTimeMillis())).addOrderBy(buildOrderByExpression(API_NUM_CALLS_ATTR)).setLimit(10).setOffset(0).build();
    EntitiesRequestContext entitiesRequestContext = new EntitiesRequestContext(TENANT_ID, entitiesRequest.getStartTimeMillis(), entitiesRequest.getEndTimeMillis(), "API", "API.startTime", new HashMap<>());
    EntityExecutionContext executionContext = new EntityExecutionContext(attributeMetadataProvider, entityIdColumnsConfigs, entitiesRequestContext, entitiesRequest);
    ExecutionTreeBuilder executionTreeBuilder = new ExecutionTreeBuilder(executionContext);
    QueryNode executionTree = executionTreeBuilder.build();
    assertNotNull(executionTree);
    assertTrue(executionTree instanceof SelectionNode);
    assertTrue(((SelectionNode) executionTree).getAggMetricSelectionSources().contains(AttributeSource.QS.name()));
    QueryNode firstChild = ((SelectionNode) executionTree).getChildNode();
    assertTrue(firstChild instanceof SelectionNode);
    assertTrue(((SelectionNode) firstChild).getAttrSelectionSources().contains(AttributeSource.EDS.name()));
    QueryNode secondChild = ((SelectionNode) firstChild).getChildNode();
    assertTrue(secondChild instanceof PaginateOnlyNode);
    assertEquals(0, ((PaginateOnlyNode) secondChild).getOffset());
    assertEquals(10, ((PaginateOnlyNode) secondChild).getLimit());
    QueryNode thirdChild = ((PaginateOnlyNode) secondChild).getChildNode();
    assertTrue(thirdChild instanceof DataFetcherNode);
    assertEquals(AttributeSource.QS.name(), ((DataFetcherNode) thirdChild).getSource());
    assertEquals(10, ((DataFetcherNode) thirdChild).getLimit());
    assertEquals(0, ((DataFetcherNode) thirdChild).getOffset());
    assertEquals(1, ((DataFetcherNode) thirdChild).getOrderByExpressionList().size());
}
Also used : EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) Test(org.junit.jupiter.api.Test)

Example 17 with EntitiesRequest

use of org.hypertrace.gateway.service.v1.entity.EntitiesRequest in project gateway-service by hypertrace.

the class ExecutionTreeBuilderTest method testOptimizedFilterTreeBuilderSimpleFilter.

@Test
public void testOptimizedFilterTreeBuilderSimpleFilter() {
    Filter filter = generateEQFilter(API_API_ID_ATTR, UUID.randomUUID().toString());
    EntitiesRequest entitiesRequest = buildEntitiesRequest(filter);
    EntityExecutionContext executionContext = getExecutionContext(entitiesRequest);
    ExecutionTreeBuilder executionTreeBuilder = new ExecutionTreeBuilder(executionContext);
    QueryNode queryNode = executionTreeBuilder.buildFilterTree(entitiesRequest, filter);
    QueryNode optimizedQueryNode = queryNode.acceptVisitor(new FilterOptimizingVisitor());
    assertNotNull(optimizedQueryNode);
    assertTrue(optimizedQueryNode instanceof DataFetcherNode);
    assertEquals(((DataFetcherNode) optimizedQueryNode).getFilter(), filter);
}
Also used : EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) EntitiesRequestAndResponseUtils.getTimeRangeFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.getTimeRangeFilter) EntitiesRequestAndResponseUtils.generateEQFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.generateEQFilter) Filter(org.hypertrace.gateway.service.v1.common.Filter) EntitiesRequestAndResponseUtils.generateFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.generateFilter) EntitiesRequestAndResponseUtils.generateAndOrNotFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.generateAndOrNotFilter) FilterOptimizingVisitor(org.hypertrace.gateway.service.entity.query.visitor.FilterOptimizingVisitor) Test(org.junit.jupiter.api.Test)

Example 18 with EntitiesRequest

use of org.hypertrace.gateway.service.v1.entity.EntitiesRequest in project gateway-service by hypertrace.

the class ExecutionTreeBuilderTest method test_build_selectAttributesAndFilterWithDifferentSourceNonZeroOffset_shouldCreateDataFetcherNodeAndPaginateOnlyNode.

@Test
public void test_build_selectAttributesAndFilterWithDifferentSourceNonZeroOffset_shouldCreateDataFetcherNodeAndPaginateOnlyNode() {
    // selections on EDS and QS
    // filters and order by on QS
    OrderByExpression orderByExpression = buildOrderByExpression(API_STATE_ATTR);
    EntitiesRequest entitiesRequest = EntitiesRequest.newBuilder().setEntityType(AttributeScope.API.name()).addSelection(buildExpression(API_TYPE_ATTR)).addSelection(buildExpression(API_STATE_ATTR)).addSelection(buildAggregateExpression(API_NUM_CALLS_ATTR, FunctionType.SUM, "SUM_numCalls", List.of())).setFilter(generateAndOrNotFilter(Operator.AND, generateEQFilter(API_DISCOVERY_STATE, "DISCOVERED"), generateFilter(Operator.GE, API_NUM_CALLS_ATTR, Value.newBuilder().setDouble(60).setValueType(ValueType.DOUBLE).build()))).addOrderBy(orderByExpression).setLimit(10).setOffset(10).build();
    EntitiesRequestContext entitiesRequestContext = new EntitiesRequestContext(TENANT_ID, 0L, 10L, "API", "API.startTime", new HashMap<>());
    EntityExecutionContext executionContext = new EntityExecutionContext(attributeMetadataProvider, entityIdColumnsConfigs, entitiesRequestContext, entitiesRequest);
    ExecutionTreeBuilder executionTreeBuilder = new ExecutionTreeBuilder(executionContext);
    QueryNode executionTree = executionTreeBuilder.build();
    assertNotNull(executionTree);
    assertTrue(executionTree instanceof SelectionNode);
    assertTrue(((SelectionNode) executionTree).getAggMetricSelectionSources().contains("QS"));
    QueryNode selectionNode = ((SelectionNode) executionTree).getChildNode();
    assertTrue(selectionNode instanceof SelectionNode);
    assertTrue(((SelectionNode) selectionNode).getAttrSelectionSources().contains("EDS"));
    QueryNode paginateOnlyNode = ((SelectionNode) selectionNode).getChildNode();
    assertTrue(paginateOnlyNode instanceof PaginateOnlyNode);
    assertEquals(10, ((PaginateOnlyNode) paginateOnlyNode).getOffset());
    assertEquals(10, ((PaginateOnlyNode) paginateOnlyNode).getLimit());
    QueryNode dataFetcherNode = ((PaginateOnlyNode) paginateOnlyNode).getChildNode();
    assertTrue(dataFetcherNode instanceof DataFetcherNode);
    assertEquals("QS", ((DataFetcherNode) dataFetcherNode).getSource());
    assertEquals(0, ((DataFetcherNode) dataFetcherNode).getOffset());
    assertEquals(20, ((DataFetcherNode) dataFetcherNode).getLimit());
}
Also used : EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) Test(org.junit.jupiter.api.Test)

Example 19 with EntitiesRequest

use of org.hypertrace.gateway.service.v1.entity.EntitiesRequest in project gateway-service by hypertrace.

the class ExecutionTreeBuilderTest method test_build_selectAttributeAndAggregateMetricWithDifferentSource_shouldCreateDifferentNode.

@Test
public void test_build_selectAttributeAndAggregateMetricWithDifferentSource_shouldCreateDifferentNode() {
    EntitiesRequest entitiesRequest = EntitiesRequest.newBuilder().setEntityType(AttributeScope.API.name()).addSelection(buildExpression(API_NAME_ATTR)).addSelection(buildAggregateExpression(API_NUM_CALLS_ATTR, FunctionType.SUM, "SUM_numCalls", List.of())).setFilter(getTimeRangeFilter("API.startTime", System.currentTimeMillis() - 1000, System.currentTimeMillis())).addOrderBy(buildOrderByExpression(API_NAME_ATTR)).setLimit(10).setOffset(0).build();
    EntitiesRequestContext entitiesRequestContext = new EntitiesRequestContext(TENANT_ID, entitiesRequest.getStartTimeMillis(), entitiesRequest.getEndTimeMillis(), "API", "API.startTime", new HashMap<>());
    EntityExecutionContext executionContext = new EntityExecutionContext(attributeMetadataProvider, entityIdColumnsConfigs, entitiesRequestContext, entitiesRequest);
    ExecutionTreeBuilder executionTreeBuilder = new ExecutionTreeBuilder(executionContext);
    QueryNode executionTree = executionTreeBuilder.build();
    assertNotNull(executionTree);
    assertTrue(executionTree instanceof SelectionNode);
    assertTrue(((SelectionNode) executionTree).getAggMetricSelectionSources().contains(AttributeSource.QS.name()));
    QueryNode firstChild = ((SelectionNode) executionTree).getChildNode();
    assertTrue(firstChild instanceof SortAndPaginateNode);
    assertEquals(entitiesRequest.getLimit(), ((SortAndPaginateNode) firstChild).getLimit());
    QueryNode secondChild = ((SortAndPaginateNode) firstChild).getChildNode();
    assertTrue(secondChild instanceof SelectionNode);
    assertTrue(((SelectionNode) secondChild).getAttrSelectionSources().contains(AttributeSource.EDS.name()));
    QueryNode thirdChild = ((SelectionNode) secondChild).getChildNode();
    assertTrue(thirdChild instanceof DataFetcherNode);
    assertEquals(AttributeSource.QS.name(), ((DataFetcherNode) thirdChild).getSource());
}
Also used : EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) Test(org.junit.jupiter.api.Test)

Example 20 with EntitiesRequest

use of org.hypertrace.gateway.service.v1.entity.EntitiesRequest in project gateway-service by hypertrace.

the class ExecutionTreeBuilderTest method testOptimizedFilterTreeBuilderNestedAndFilter.

@Test
public void testOptimizedFilterTreeBuilderNestedAndFilter() {
    Filter apiIdFilter = generateEQFilter(API_API_ID_ATTR, UUID.randomUUID().toString());
    Filter apiNameFilter = generateEQFilter(API_NAME_ATTR, "/login");
    Filter apiPatternFilter = generateEQFilter(API_PATTERN_ATTR, "/login");
    Filter startTimeFilter = generateFilter(Operator.GE, API_START_TIME_ATTR, Value.newBuilder().setTimestamp(System.currentTimeMillis() - 5 * 60 * 1000).setValueType(ValueType.TIMESTAMP).build());
    Filter endTimeFilter = generateFilter(Operator.LE, API_END_TIME_ATTR, Value.newBuilder().setTimestamp(System.currentTimeMillis()).setValueType(ValueType.TIMESTAMP).build());
    {
        Filter level2Filter = generateAndOrNotFilter(Operator.AND, apiIdFilter, startTimeFilter);
        Filter filter = generateAndOrNotFilter(Operator.AND, level2Filter, apiNameFilter);
        EntitiesRequest entitiesRequest = buildEntitiesRequest(filter);
        EntityExecutionContext executionContext = getExecutionContext(entitiesRequest);
        ExecutionTreeBuilder executionTreeBuilder = new ExecutionTreeBuilder(executionContext);
        QueryNode queryNode = executionTreeBuilder.buildFilterTree(entitiesRequest, filter);
        assertNotNull(queryNode);
        QueryNode optimizedNode = queryNode.acceptVisitor(new FilterOptimizingVisitor());
        assertNotNull(optimizedNode);
        assertTrue(optimizedNode instanceof AndNode);
        List<QueryNode> queryNodeList = ((AndNode) optimizedNode).getChildNodes();
        assertEquals(2, queryNodeList.size());
        queryNodeList.forEach(tn -> assertTrue(tn instanceof DataFetcherNode));
        List<Filter> filterList = queryNodeList.stream().map(tn -> ((DataFetcherNode) tn).getFilter()).collect(Collectors.toList());
        assertTrue(filterList.containsAll(Arrays.asList(generateAndOrNotFilter(Operator.AND, apiNameFilter, apiIdFilter), startTimeFilter)));
    }
    {
        Filter level2Filter = generateAndOrNotFilter(Operator.AND, apiIdFilter, apiNameFilter);
        Filter filter = generateAndOrNotFilter(Operator.AND, level2Filter, startTimeFilter);
        EntitiesRequest entitiesRequest = buildEntitiesRequest(filter);
        EntityExecutionContext executionContext = getExecutionContext(entitiesRequest);
        ExecutionTreeBuilder executionTreeBuilder = new ExecutionTreeBuilder(executionContext);
        QueryNode queryNode = executionTreeBuilder.buildFilterTree(entitiesRequest, filter);
        assertNotNull(queryNode);
        QueryNode optimizedNode = queryNode.acceptVisitor(new FilterOptimizingVisitor());
        assertNotNull(optimizedNode);
        assertTrue(optimizedNode instanceof AndNode);
        List<QueryNode> queryNodeList = ((AndNode) optimizedNode).getChildNodes();
        assertEquals(2, queryNodeList.size());
        queryNodeList.forEach(tn -> assertTrue(tn instanceof DataFetcherNode));
        List<Filter> filterList = queryNodeList.stream().map(tn -> ((DataFetcherNode) tn).getFilter()).collect(Collectors.toList());
        assertTrue(filterList.containsAll(Arrays.asList(generateAndOrNotFilter(Operator.AND, apiIdFilter, apiNameFilter), startTimeFilter)));
    }
    {
        Filter level3Filter = generateAndOrNotFilter(Operator.AND, endTimeFilter, apiPatternFilter);
        Filter level2Filter = generateAndOrNotFilter(Operator.AND, apiIdFilter, startTimeFilter, level3Filter);
        Filter filter = generateAndOrNotFilter(Operator.AND, level2Filter, apiNameFilter);
        EntitiesRequest entitiesRequest = buildEntitiesRequest(filter);
        EntityExecutionContext executionContext = getExecutionContext(entitiesRequest);
        ExecutionTreeBuilder executionTreeBuilder = new ExecutionTreeBuilder(executionContext);
        QueryNode queryNode = executionTreeBuilder.buildFilterTree(entitiesRequest, filter);
        assertNotNull(queryNode);
        QueryNode optimizedNode = queryNode.acceptVisitor(new FilterOptimizingVisitor());
        assertNotNull(optimizedNode);
        assertTrue(optimizedNode instanceof AndNode);
        List<QueryNode> queryNodeList = ((AndNode) optimizedNode).getChildNodes();
        assertEquals(2, queryNodeList.size());
        queryNodeList.forEach(tn -> assertTrue(tn instanceof DataFetcherNode));
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) RequestContext(org.hypertrace.gateway.service.common.RequestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) AttributeMetadata(org.hypertrace.core.attribute.service.v1.AttributeMetadata) EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) FilterOptimizingVisitor(org.hypertrace.gateway.service.entity.query.visitor.FilterOptimizingVisitor) HashMap(java.util.HashMap) EntitiesRequestAndResponseUtils.getTimeRangeFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.getTimeRangeFilter) HashSet(java.util.HashSet) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) EntityIdColumnsConfigs(org.hypertrace.gateway.service.entity.config.EntityIdColumnsConfigs) EntitiesRequestAndResponseUtils.generateEQFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.generateEQFilter) Map(java.util.Map) AttributeScope(org.hypertrace.core.attribute.service.v1.AttributeScope) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EntitiesRequestAndResponseUtils.buildAggregateExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildAggregateExpression) AttributeSource(org.hypertrace.core.attribute.service.v1.AttributeSource) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) Filter(org.hypertrace.gateway.service.v1.common.Filter) Value(org.hypertrace.gateway.service.v1.common.Value) Set(java.util.Set) EntitiesRequestAndResponseUtils.generateFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.generateFilter) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) ValueType(org.hypertrace.gateway.service.v1.common.ValueType) Collectors(java.util.stream.Collectors) EntitiesRequestAndResponseUtils.buildExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildExpression) EntitiesRequestAndResponseUtils.buildTimeAggregation(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildTimeAggregation) Test(org.junit.jupiter.api.Test) Operator(org.hypertrace.gateway.service.v1.common.Operator) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) EntitiesRequestAndResponseUtils.generateAndOrNotFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.generateAndOrNotFilter) Optional(java.util.Optional) FunctionType(org.hypertrace.gateway.service.v1.common.FunctionType) Collections(java.util.Collections) AttributeMetadataProvider(org.hypertrace.gateway.service.common.AttributeMetadataProvider) Mockito.mock(org.mockito.Mockito.mock) EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) EntitiesRequestAndResponseUtils.getTimeRangeFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.getTimeRangeFilter) EntitiesRequestAndResponseUtils.generateEQFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.generateEQFilter) Filter(org.hypertrace.gateway.service.v1.common.Filter) EntitiesRequestAndResponseUtils.generateFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.generateFilter) EntitiesRequestAndResponseUtils.generateAndOrNotFilter(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.generateAndOrNotFilter) FilterOptimizingVisitor(org.hypertrace.gateway.service.entity.query.visitor.FilterOptimizingVisitor) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

EntitiesRequest (org.hypertrace.gateway.service.v1.entity.EntitiesRequest)77 Test (org.junit.jupiter.api.Test)63 EntitiesRequestContext (org.hypertrace.gateway.service.entity.EntitiesRequestContext)39 OrderByExpression (org.hypertrace.gateway.service.v1.common.OrderByExpression)21 EntitiesRequestAndResponseUtils.buildOrderByExpression (org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression)18 AttributeScope (org.hypertrace.core.attribute.service.v1.AttributeScope)17 QueryRequest (org.hypertrace.core.query.service.api.QueryRequest)16 AttributeMetadata (org.hypertrace.core.attribute.service.v1.AttributeMetadata)15 EntityKey (org.hypertrace.gateway.service.entity.EntityKey)14 Filter (org.hypertrace.gateway.service.v1.common.Filter)14 Builder (org.hypertrace.gateway.service.v1.entity.Entity.Builder)14 HashMap (java.util.HashMap)13 Expression (org.hypertrace.gateway.service.v1.common.Expression)13 AttributeMetadataProvider (org.hypertrace.gateway.service.common.AttributeMetadataProvider)12 EntitiesRequestAndResponseUtils.buildExpression (org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildExpression)12 TimeAggregation (org.hypertrace.gateway.service.v1.common.TimeAggregation)11 EntitiesRequestAndResponseUtils.buildAggregateExpression (org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildAggregateExpression)9 LinkedHashMap (java.util.LinkedHashMap)8 ResultSetChunk (org.hypertrace.core.query.service.api.ResultSetChunk)8 AbstractGatewayServiceTest (org.hypertrace.gateway.service.AbstractGatewayServiceTest)8