Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.hypertrace.gateway.service.common;

public enum ExpressionLocation {
COLUMN_SELECTION,
METRIC_AGGREGATION,
TIME_AGGREGATION,
COLUMN_ORDER_BY,
METRIC_ORDER_BY,
COLUMN_FILTER,
COLUMN_GROUP_BY,
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public List<Entity.Builder> transform(
.flatMap(Optional::stream)
.collect(Collectors.toSet());
Set<String> aggregations =
executionContext.getExpressionContext().getSourceToMetricExpressionMap().values().stream()
executionContext.getExpressionContext().getSourceToMetricAggregationExpressionMap().values().stream()
.flatMap(Collection::stream)
.map(expression -> expression.getFunction().getAlias())
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void removeSelectionAttributes(String source, Set<String> attributes) {
private void buildSelectionPendingSources() {
pendingSelectionSources.addAll(expressionContext.getSourceToSelectionExpressionMap().keySet());
pendingMetricAggregationSources.addAll(
expressionContext.getSourceToMetricExpressionMap().keySet());
expressionContext.getSourceToMetricAggregationExpressionMap().keySet());
pendingTimeAggregationSources.addAll(
expressionContext.getSourceToTimeAggregationMap().keySet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public EntityResponse visit(SelectionNode selectionNode) {
.addAllSelection(
executionContext
.getExpressionContext()
.getSourceToMetricExpressionMap()
.getSourceToMetricAggregationExpressionMap()
.get(source))
.setFilter(filter)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ void testGetSingleSourceForAllAttributes_allSourceExpressionMapKeySetsHaveOneSou
createSourceToExpressionsMap(List.of("QS")),
createSourceToExpressionsMap(List.of("QS")),
createSourceToExpressionsMap(List.of("QS")),
createSourceToExpressionsMap(List.of("QS")),
Map.of(
"API.id", Set.of(QS.name()),
"API.name", Set.of(QS.name()),
"API.duration", Set.of(QS.name()),
"API.startTime", Set.of(QS.name())));
createSourceToExpressionsMap(List.of("QS")));

assertEquals(
Optional.of("QS"), ExpressionContext.getSingleSourceForAllAttributes(expressionContext));
Expand All @@ -51,12 +46,7 @@ void testGetSingleSourceForAllAttributes_someSourceExpressionMapKeySetsHaveMulti
createSourceToExpressionsMap(List.of("QS", "EDS")),
createSourceToExpressionsMap(List.of("QS")),
createSourceToExpressionsMap(List.of("QS")),
createSourceToExpressionsMap(List.of("QS")),
Map.of(
"API.id", Set.of(QS.name()),
"API.name", Set.of(QS.name()),
"API.duration", Set.of(QS.name(), EDS.name()),
"API.startTime", Set.of(QS.name())));
createSourceToExpressionsMap(List.of("QS")));

assertEquals(
Optional.of("QS"), ExpressionContext.getSingleSourceForAllAttributes(expressionContext));
Expand All @@ -71,12 +61,7 @@ void testGetSingleSourceForAllAttributes_someSourceExpressionMapKeySetsHaveDiffe
createSourceToExpressionsMap(List.of("EDS")),
createSourceToExpressionsMap(List.of("QS")),
createSourceToExpressionsMap(List.of("QS")),
createSourceToExpressionsMap(List.of("QS")),
Map.of(
"API.id", Set.of(QS.name()),
"API.name", Set.of(QS.name()),
"API.duration", Set.of(EDS.name()),
"API.startTime", Set.of(QS.name())));
createSourceToExpressionsMap(List.of("QS")));

assertEquals(
Optional.empty(), ExpressionContext.getSingleSourceForAllAttributes(expressionContext));
Expand All @@ -92,12 +77,7 @@ void testGetSingleSourceForAllAttributes_someSourceExpressionMapKeySetsAreEmpty(
createSourceToExpressionsMap(List.of()),
createSourceToExpressionsMap(List.of("QS")),
createSourceToExpressionsMap(List.of("QS")),
createSourceToExpressionsMap(List.of()),
Map.of(
"API.id", Set.of(QS.name()),
"API.name", Set.of(QS.name()),
"API.duration", Set.of(),
"API.startTime", Set.of(QS.name())));
createSourceToExpressionsMap(List.of()));

assertEquals(
Optional.of("QS"), ExpressionContext.getSingleSourceForAllAttributes(expressionContext));
Expand All @@ -113,12 +93,7 @@ void testGetSingleSourceForAllAttributes_allEmptySourceExpressionMapKeySetsAndAt
createSourceToExpressionsMap(List.of()),
createSourceToExpressionsMap(List.of()),
createSourceToExpressionsMap(List.of()),
createSourceToExpressionsMap(List.of()),
Map.of(
"API.id", Set.of(),
"API.name", Set.of(),
"API.duration", Set.of(),
"API.startTime", Set.of()));
createSourceToExpressionsMap(List.of()));

assertEquals(
Optional.empty(), ExpressionContext.getSingleSourceForAllAttributes(expressionContext));
Expand Down Expand Up @@ -309,12 +284,11 @@ private ExpressionContext getMockExpressionContext(
Map<String, List<TimeAggregation>> sourceToTimeAggregationMap,
Map<String, List<OrderByExpression>> sourceToSelectionOrderByExpressionMap,
Map<String, List<OrderByExpression>> sourceToMetricOrderByExpressionMap,
Map<String, List<Expression>> sourceToFilterExpressionMap,
Map<String, Set<String>> attributeToSourcesMap) {
Map<String, List<Expression>> sourceToFilterExpressionMap) {
ExpressionContext expressionContext = mock(ExpressionContext.class);
when(expressionContext.getSourceToSelectionExpressionMap())
.thenReturn(sourceToSelectionExpressionMap);
when(expressionContext.getSourceToMetricExpressionMap())
when(expressionContext.getSourceToMetricAggregationExpressionMap())
.thenReturn(sourceToMetricExpressionMap);
when(expressionContext.getSourceToTimeAggregationMap()).thenReturn(sourceToTimeAggregationMap);
when(expressionContext.getSourceToSelectionOrderByExpressionMap())
Expand All @@ -323,7 +297,6 @@ private ExpressionContext getMockExpressionContext(
.thenReturn(sourceToMetricOrderByExpressionMap);
when(expressionContext.getSourceToFilterExpressionMap())
.thenReturn(sourceToFilterExpressionMap);
when(expressionContext.getAllAttributesToSourcesMap()).thenReturn(attributeToSourcesMap);

return expressionContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void shouldAddMissingSelections() {
List.of(createAttributeExpression("API.id"), createAttributeExpression("API.name")),
"QS",
List.of(createAttributeExpression("API.serviceId"))));
when(expressionContext.getSourceToMetricExpressionMap()).thenReturn(Collections.emptyMap());
when(expressionContext.getSourceToMetricAggregationExpressionMap()).thenReturn(Collections.emptyMap());
when(expressionContext.getSourceToTimeAggregationMap()).thenReturn(Collections.emptyMap());

EntityExecutionContext executionContext = mock(EntityExecutionContext.class);
Expand Down Expand Up @@ -81,7 +81,7 @@ public void shouldAddMissingSelections() {
public void shouldAddMissingAggregations() {
ExpressionContext expressionContext = mock(ExpressionContext.class);
when(expressionContext.getSourceToSelectionExpressionMap()).thenReturn(Collections.emptyMap());
when(expressionContext.getSourceToMetricExpressionMap())
when(expressionContext.getSourceToMetricAggregationExpressionMap())
.thenReturn(Map.of("QS", List.of(createAggregateExpression("API.duration"))));
when(expressionContext.getSourceToTimeAggregationMap()).thenReturn(Collections.emptyMap());

Expand Down Expand Up @@ -119,7 +119,7 @@ public void shouldAddMissingAggregations() {
public void shouldAddMissingTimeAggregations() {
ExpressionContext expressionContext = mock(ExpressionContext.class);
when(expressionContext.getSourceToSelectionExpressionMap()).thenReturn(Collections.emptyMap());
when(expressionContext.getSourceToMetricExpressionMap()).thenReturn(Collections.emptyMap());
when(expressionContext.getSourceToMetricAggregationExpressionMap()).thenReturn(Collections.emptyMap());
when(expressionContext.getSourceToTimeAggregationMap())
.thenReturn(Map.of("QS", List.of(createTimeAggregation("API.duration"))));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@
import static org.mockito.Mockito.when;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.hypertrace.gateway.service.common.ExpressionContext;
import org.hypertrace.gateway.service.v1.common.Expression;
import org.hypertrace.gateway.service.v1.common.OrderByExpression;
import org.hypertrace.gateway.service.v1.common.TimeAggregation;
import org.junit.jupiter.api.Test;

class ExecutionTreeUtilsTest {
Expand Down Expand Up @@ -54,34 +49,4 @@ void removeDuplicateSelectionAttributes() {
verify(executionContext).removeSelectionAttributes("EDS", Set.of("API.name"));
verify(executionContext).removeSelectionAttributes("AS", Set.of("API.latency"));
}

private ExpressionContext getMockExpressionContext(
Map<String, List<Expression>> sourceToSelectionExpressionMap,
Map<String, List<Expression>> sourceToMetricExpressionMap,
Map<String, List<TimeAggregation>> sourceToTimeAggregationMap,
Map<String, List<OrderByExpression>> sourceToSelectionOrderByExpressionMap,
Map<String, List<OrderByExpression>> sourceToMetricOrderByExpressionMap,
Map<String, List<Expression>> sourceToFilterExpressionMap,
Map<String, Set<String>> attributeToSourcesMap) {
ExpressionContext expressionContext = mock(ExpressionContext.class);
when(expressionContext.getSourceToSelectionExpressionMap())
.thenReturn(sourceToSelectionExpressionMap);
when(expressionContext.getSourceToMetricExpressionMap())
.thenReturn(sourceToMetricExpressionMap);
when(expressionContext.getSourceToTimeAggregationMap()).thenReturn(sourceToTimeAggregationMap);
when(expressionContext.getSourceToSelectionOrderByExpressionMap())
.thenReturn(sourceToSelectionOrderByExpressionMap);
when(expressionContext.getSourceToMetricOrderByExpressionMap())
.thenReturn(sourceToMetricOrderByExpressionMap);
when(expressionContext.getSourceToFilterExpressionMap())
.thenReturn(sourceToFilterExpressionMap);
when(expressionContext.getAllAttributesToSourcesMap()).thenReturn(attributeToSourcesMap);

return expressionContext;
}

// We don't care about the values. Just they keySets.
private <T> Map<String, List<T>> createSourceToExpressionsMap(List<String> sourceKeys) {
return sourceKeys.stream().collect(Collectors.toUnmodifiableMap(s -> s, s -> List.of()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public void test_visitPaginateOnlyNode() {
.thenReturn(List.of(buildExpression(API_ID_ATTR)));
when(expressionContext.getSourceToSelectionExpressionMap())
.thenReturn(Map.of("QS", List.of(selectionExpression)));
when(expressionContext.getSourceToMetricExpressionMap())
when(expressionContext.getSourceToMetricAggregationExpressionMap())
.thenReturn(Map.of("QS", List.of(metricExpression)));
when(expressionContext.getSourceToTimeAggregationMap())
.thenReturn(Map.of("QS", List.of(timeAggregation)));
Expand Down Expand Up @@ -854,7 +854,7 @@ public void test_visitOnlySelectionsNode_shouldSetTotalEntityKeys() {
.thenReturn(List.of(buildExpression(API_ID_ATTR)));
when(expressionContext.getSourceToSelectionExpressionMap())
.thenReturn(Map.of("QS", List.of(selectionExpression)));
when(expressionContext.getSourceToMetricExpressionMap())
when(expressionContext.getSourceToMetricAggregationExpressionMap())
.thenReturn(Map.of("QS", List.of(metricExpression)));
when(expressionContext.getSourceToTimeAggregationMap())
.thenReturn(Map.of("QS", List.of(timeAggregation)));
Expand Down Expand Up @@ -986,7 +986,7 @@ private EntityExecutionContext mockExecutionContext(
when(executionContext.getPendingSelectionSources()).thenReturn(selectionSource);
when(executionContext.getPendingMetricAggregationSources()).thenReturn(aggregateSource);
when(expressionContext.getSourceToSelectionExpressionMap()).thenReturn(sourceToSelectionMap);
when(expressionContext.getSourceToMetricExpressionMap()).thenReturn(sourceToAggregateMap);
when(expressionContext.getSourceToMetricAggregationExpressionMap()).thenReturn(sourceToAggregateMap);
return executionContext;
}

Expand Down