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());
}
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);
}
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());
}
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());
}
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));
}
}
Aggregations