Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for logical operators #148

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.hypertrace.core.graphql.common.schema.attributes.arguments.AttributeExpression;
import org.hypertrace.core.graphql.common.schema.results.ResultSet;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperatorArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.page.LimitArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.page.OffsetArgument;
Expand Down Expand Up @@ -89,6 +91,11 @@
.deserializeObjectList(arguments, orderArgumentClass)
.orElse(Collections.emptyList());

LogicalFilterOperator logicalFilterOperator =
this.argumentDeserializer
.deserializePrimitive(arguments, LogicalFilterOperatorArgument.class)
.orElse(LogicalFilterOperator.AND);

List<FilterArgument> requestedFilters =
this.argumentDeserializer
.deserializeObjectList(arguments, FilterArgument.class)
Expand All @@ -114,6 +121,7 @@
offset,
timeRange,
orders,
logicalFilterOperator,
filters,
this.getAttributeQueryableFields(selectionSet),
spaceId))
Expand All @@ -128,6 +136,7 @@
int offset,
TimeRangeArgument timeRange,
List<AttributeAssociation<O>> orderArguments,
LogicalFilterOperator logicalFilterOperator,
Collection<AttributeAssociation<FilterArgument>> filterArguments,
Stream<SelectedField> attributeQueryableFields,
Optional<String> spaceId) {
Expand All @@ -145,6 +154,7 @@
limit,
offset,
orderArguments,
logicalFilterOperator,
filterArguments,
spaceId));
}
Expand Down Expand Up @@ -184,6 +194,7 @@
limit,
0,
List.of(),
LogicalFilterOperator.AND,
filters,
Optional.empty()));
}
Expand All @@ -206,6 +217,7 @@
originalRequest.limit(),
originalRequest.offset(),
originalRequest.orderArguments(),
originalRequest.logicalFilterOperator(),

Check warning on line 220 in hypertrace-core-graphql-common-schema/src/main/java/org/hypertrace/core/graphql/common/request/DefaultResultSetRequestBuilder.java

View check run for this annotation

Codecov / codecov/patch

hypertrace-core-graphql-common-schema/src/main/java/org/hypertrace/core/graphql/common/request/DefaultResultSetRequestBuilder.java#L220

Added line #L220 was not covered by tests
mergedFilters,
originalRequest.spaceId()));
}
Expand Down Expand Up @@ -251,6 +263,7 @@
int limit;
int offset;
List<AttributeAssociation<O>> orderArguments;
LogicalFilterOperator logicalFilterOperator;

Check warning on line 266 in hypertrace-core-graphql-common-schema/src/main/java/org/hypertrace/core/graphql/common/request/DefaultResultSetRequestBuilder.java

View check run for this annotation

Codecov / codecov/patch

hypertrace-core-graphql-common-schema/src/main/java/org/hypertrace/core/graphql/common/request/DefaultResultSetRequestBuilder.java#L266

Added line #L266 was not covered by tests
Collection<AttributeAssociation<FilterArgument>> filterArguments;
Optional<String> spaceId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Optional;
import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;

public interface ResultSetRequest<O extends OrderArgument> extends ContextualRequest {
Expand All @@ -24,5 +25,7 @@ public interface ResultSetRequest<O extends OrderArgument> extends ContextualReq

Collection<AttributeAssociation<FilterArgument>> filterArguments();

LogicalFilterOperator logicalFilterOperator();

Optional<String> spaceId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument;
import org.hypertrace.core.graphql.common.schema.attributes.arguments.AttributeExpression;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.context.GraphQlRequestContext;

Expand All @@ -35,6 +36,7 @@ <O extends OrderArgument> Single<ResultSetRequest<O>> build(
int offset,
TimeRangeArgument timeRange,
List<AttributeAssociation<O>> orderArguments,
LogicalFilterOperator logicalFilterOperator,
Collection<AttributeAssociation<FilterArgument>> filterArguments,
Stream<SelectedField> attributeQueryableFields,
Optional<String> spaceId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.hypertrace.core.graphql.common.schema.results.arguments.filter;

import graphql.annotations.annotationTypes.GraphQLName;

@GraphQLName(LogicalFilterOperator.TYPE_NAME)
public enum LogicalFilterOperator {
AND,
OR;

static final String TYPE_NAME = "LogicalFilterOperator";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.hypertrace.core.graphql.common.schema.results.arguments.filter;

import org.hypertrace.core.graphql.deserialization.PrimitiveArgument;

public interface LogicalFilterOperatorArgument extends PrimitiveArgument<LogicalFilterOperator> {

String ARGUMENT_NAME = "logicalOperator";
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hypertrace.core.graphql.attributes.AttributeModel;
import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperatorArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.page.LimitArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.page.OffsetArgument;
Expand Down Expand Up @@ -94,6 +95,9 @@ void canBuildRequest() {
.thenReturn(Optional.of(List.of(this.mockFilterArgument)));
when(this.mockArgumentDeserializer.deserializePrimitive(any(), eq(SpaceArgument.class)))
.thenReturn(Optional.of(this.mockSpace));
when(this.mockArgumentDeserializer.deserializePrimitive(
any(), eq(LogicalFilterOperatorArgument.class)))
.thenReturn(Optional.empty());

ResultSetRequest<OrderArgument> request =
this.requestBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import javax.inject.Inject;
import org.hypertrace.core.graphql.common.request.AttributeAssociation;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.utils.BiConverter;
import org.hypertrace.core.graphql.common.utils.Converter;
import org.hypertrace.gateway.service.v1.common.Filter;
import org.hypertrace.gateway.service.v1.common.Operator;

class FilterConverter
implements Converter<Collection<AttributeAssociation<FilterArgument>>, Filter> {
implements Converter<Collection<AttributeAssociation<FilterArgument>>, Filter>,
BiConverter<
Collection<AttributeAssociation<FilterArgument>>, LogicalFilterOperator, Filter> {

private final AttributeExpressionConverter attributeExpressionConverter;
private final OperatorConverter operatorConverter;
Expand All @@ -32,6 +36,12 @@

@Override
public Single<Filter> convert(Collection<AttributeAssociation<FilterArgument>> filters) {
return this.convert(filters, LogicalFilterOperator.AND);

Check warning on line 39 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/FilterConverter.java

View check run for this annotation

Codecov / codecov/patch

hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/FilterConverter.java#L39

Added line #L39 was not covered by tests
}

@Override
public Single<Filter> convert(
Collection<AttributeAssociation<FilterArgument>> filters, LogicalFilterOperator operator) {
if (filters.isEmpty()) {
return Single.just(Filter.getDefaultInstance());
}
Expand All @@ -42,11 +52,21 @@
.map(
filterList ->
Filter.newBuilder()
.setOperator(Operator.AND)
.setOperator(this.convertLogicalOperator(operator))

Check warning on line 55 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/FilterConverter.java

View check run for this annotation

Codecov / codecov/patch

hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/FilterConverter.java#L55

Added line #L55 was not covered by tests
.addAllChildFilter(filterList)
.build());
}

private Operator convertLogicalOperator(LogicalFilterOperator logicalFilterOperator) {
switch (logicalFilterOperator) {
case OR:
return Operator.OR;

Check warning on line 63 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/FilterConverter.java

View check run for this annotation

Codecov / codecov/patch

hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/FilterConverter.java#L63

Added line #L63 was not covered by tests
case AND:
default:
return Operator.AND;

Check warning on line 66 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/FilterConverter.java

View check run for this annotation

Codecov / codecov/patch

hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/FilterConverter.java#L66

Added line #L66 was not covered by tests
}
}

private Single<Filter> buildFilter(AttributeAssociation<FilterArgument> filter) {
return zip(
this.attributeExpressionConverter.convert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.hypertrace.core.graphql.common.schema.attributes.arguments.AttributeExpression;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterOperatorType;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderDirection;
import org.hypertrace.core.graphql.common.utils.BiConverter;
Expand Down Expand Up @@ -58,6 +59,13 @@
new TypeLiteral<
Converter<Collection<AttributeAssociation<FilterArgument>>, Filter>>() {}))
.to(FilterConverter.class);
bind(Key.get(

Check warning on line 62 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/GatewayUtilsModule.java

View check run for this annotation

Codecov / codecov/patch

hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/GatewayUtilsModule.java#L62

Added line #L62 was not covered by tests
new TypeLiteral<
BiConverter<
Collection<AttributeAssociation<FilterArgument>>,
LogicalFilterOperator,
Filter>>() {}))
.to(FilterConverter.class);

Check warning on line 68 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/GatewayUtilsModule.java

View check run for this annotation

Codecov / codecov/patch

hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/GatewayUtilsModule.java#L67-L68

Added lines #L67 - L68 were not covered by tests

bind(Key.get(new TypeLiteral<Converter<AttributeModel, ColumnIdentifier>>() {}))
.to(ColumnIdentifierConverter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,35 @@
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import lombok.RequiredArgsConstructor;
import org.hypertrace.core.graphql.common.request.AttributeAssociation;
import org.hypertrace.core.graphql.common.request.AttributeRequest;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.common.utils.BiConverter;
import org.hypertrace.core.graphql.common.utils.Converter;
import org.hypertrace.core.graphql.log.event.request.LogEventRequest;
import org.hypertrace.gateway.service.v1.common.Expression;
import org.hypertrace.gateway.service.v1.common.Filter;
import org.hypertrace.gateway.service.v1.common.OrderByExpression;
import org.hypertrace.gateway.service.v1.log.events.LogEventsRequest;

@RequiredArgsConstructor(onConstructor_ = @Inject)
class GatewayServiceLogEventsRequestBuilder {

private final Converter<Collection<AttributeAssociation<FilterArgument>>, Filter> filterConverter;
private final BiConverter<
Collection<AttributeAssociation<FilterArgument>>, LogicalFilterOperator, Filter>
filterConverter;
private final Converter<List<AttributeAssociation<OrderArgument>>, List<OrderByExpression>>
orderConverter;
private final Converter<Collection<AttributeRequest>, Set<Expression>> attributeConverter;

@Inject
GatewayServiceLogEventsRequestBuilder(
Converter<Collection<AttributeAssociation<FilterArgument>>, Filter> filterConverter,
Converter<List<AttributeAssociation<OrderArgument>>, List<OrderByExpression>> orderConverter,
Converter<Collection<AttributeRequest>, Set<Expression>> attributeConverter) {
this.filterConverter = filterConverter;
this.orderConverter = orderConverter;
this.attributeConverter = attributeConverter;
}

Single<LogEventsRequest> buildRequest(LogEventRequest gqlRequest) {
return zip(
this.attributeConverter.convert(gqlRequest.attributes()),
this.orderConverter.convert(gqlRequest.orderArguments()),
this.filterConverter.convert(gqlRequest.filterArguments()),
this.filterConverter.convert(
gqlRequest.filterArguments(), gqlRequest.logicalFilterOperator()),
(selections, orderBys, filters) ->
LogEventsRequest.newBuilder()
.setStartTimeMillis(gqlRequest.timeRange().startTime().toEpochMilli())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.hypertrace.core.graphql.common.request.AttributeRequest;
import org.hypertrace.core.graphql.common.schema.attributes.arguments.AttributeExpression;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.common.utils.BiConverter;
import org.hypertrace.core.graphql.common.utils.Converter;
Expand Down Expand Up @@ -46,7 +47,10 @@ protected void configure() {
requireBinding(
Key.get(
new TypeLiteral<
Converter<Collection<AttributeAssociation<FilterArgument>>, Filter>>() {}));
BiConverter<
Collection<AttributeAssociation<FilterArgument>>,
LogicalFilterOperator,
Filter>>() {}));

requireBinding(
Key.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument;
import org.hypertrace.core.graphql.common.schema.results.ResultSet;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperatorArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.page.LimitArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.page.OffsetArgument;
Expand Down Expand Up @@ -94,6 +96,11 @@ Single<LogEventRequest> build(
.deserializeObjectList(arguments, orderArgumentClass)
.orElse(Collections.emptyList());

LogicalFilterOperator filterOperator =
this.argumentDeserializer
.deserializePrimitive(arguments, LogicalFilterOperatorArgument.class)
.orElse(LogicalFilterOperator.AND);

List<FilterArgument> requestedFilters =
this.argumentDeserializer
.deserializeObjectList(arguments, FilterArgument.class)
Expand All @@ -115,7 +122,14 @@ context, requestScope, getAttributeQueryableFields(selectionSet))
(attributeRequests, orders, filters) ->
Single.just(
new DefaultLogEventRequest(
context, attributeRequests, timeRange, limit, offset, orders, filters)))
context,
attributeRequests,
timeRange,
limit,
offset,
orders,
filterOperator,
filters)))
.flatMap(single -> single);
}

Expand All @@ -135,6 +149,7 @@ private static class DefaultLogEventRequest implements LogEventRequest {
int limit;
int offset;
List<AttributeAssociation<OrderArgument>> orderArguments;
LogicalFilterOperator logicalFilterOperator;
Collection<AttributeAssociation<FilterArgument>> filterArguments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.hypertrace.core.graphql.common.request.ContextualRequest;
import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;

public interface LogEventRequest extends ContextualRequest {
Expand All @@ -21,5 +22,7 @@ public interface LogEventRequest extends ContextualRequest {

List<AttributeAssociation<OrderArgument>> orderArguments();

LogicalFilterOperator logicalFilterOperator();

Collection<AttributeAssociation<FilterArgument>> filterArguments();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.List;
import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperatorArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.page.LimitArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.page.OffsetArgument;
Expand All @@ -21,6 +23,8 @@ public interface LogEventSchema {
@GraphQLDataFetcher(LogEventFetcher.class)
LogEventResultSet logEvents(
@GraphQLName(TimeRangeArgument.ARGUMENT_NAME) @GraphQLNonNull TimeRangeArgument between,
@GraphQLName(LogicalFilterOperatorArgument.ARGUMENT_NAME)
LogicalFilterOperator logicalFilterOperator,
@GraphQLName(FilterArgument.ARGUMENT_NAME) List<FilterArgument> filterBy,
@GraphQLName(OrderArgument.ARGUMENT_NAME) List<OrderArgument> orderBy,
@GraphQLName(LimitArgument.ARGUMENT_NAME) int limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument;
import org.hypertrace.core.graphql.common.schema.attributes.arguments.AttributeExpression;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.LogicalFilterOperator;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.context.GraphQlRequestContext;
import org.hypertrace.core.graphql.log.event.request.LogEventRequest;
Expand All @@ -30,6 +31,7 @@ static class DefaultLogEventRequest implements LogEventRequest {
int limit;
int offset;
List<AttributeAssociation<OrderArgument>> orderArguments;
LogicalFilterOperator logicalFilterOperator;
Collection<AttributeAssociation<FilterArgument>> filterArguments;
}

Expand Down
Loading