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

chore | add support for multi filter arguments #151

Merged
merged 1 commit into from
Nov 27, 2023
Merged
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 @@ -58,6 +58,11 @@
new TypeLiteral<
Converter<Collection<AttributeAssociation<FilterArgument>>, Filter>>() {}))
.to(FilterConverter.class);
bind(Key.get(

Check warning on line 61 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#L61

Added line #L61 was not covered by tests
new TypeLiteral<
Converter<
Collection<Collection<AttributeAssociation<FilterArgument>>>, Filter>>() {}))
.to(MultiFilterConverter.class);

Check warning on line 65 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#L64-L65

Added lines #L64 - L65 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
@@ -0,0 +1,70 @@
package org.hypertrace.core.graphql.utils.gateway;

import static io.reactivex.rxjava3.core.Single.zip;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
import java.util.Collection;
import java.util.stream.Collectors;
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.utils.Converter;
import org.hypertrace.gateway.service.v1.common.Filter;
import org.hypertrace.gateway.service.v1.common.Operator;

public class MultiFilterConverter
implements Converter<Collection<Collection<AttributeAssociation<FilterArgument>>>, Filter> {

private final AttributeExpressionConverter attributeExpressionConverter;
private final OperatorConverter operatorConverter;
private final LiteralConstantExpressionConverter literalConstantExpressionConverter;

@Inject
MultiFilterConverter(
AttributeExpressionConverter attributeExpressionConverter,
OperatorConverter operatorConverter,
LiteralConstantExpressionConverter literalConstantExpressionConverter) {
this.attributeExpressionConverter = attributeExpressionConverter;
this.operatorConverter = operatorConverter;
this.literalConstantExpressionConverter = literalConstantExpressionConverter;
}

Check warning on line 31 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.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/MultiFilterConverter.java#L27-L31

Added lines #L27 - L31 were not covered by tests

@Override
public Single<Filter> convert(
Collection<Collection<AttributeAssociation<FilterArgument>>> filters) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we assuming a collection of collection of filters should be an OR-AND relationship? That's extremely unintuitive. Can we revert this and instead build a real converter here that allows the caller to build relationships - (collection<filters>, logicalOperator) => filter

if (filters.isEmpty()) {
return Single.just(Filter.getDefaultInstance());

Check warning on line 37 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.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/MultiFilterConverter.java#L37

Added line #L37 was not covered by tests
}

return Observable.fromIterable(filters)
.flatMapSingle(this::buildAndFilterOperations)
.collect(Collectors.toUnmodifiableList())
.map(

Check warning on line 43 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.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/MultiFilterConverter.java#L40-L43

Added lines #L40 - L43 were not covered by tests
filterList ->
Filter.newBuilder().setOperator(Operator.OR).addAllChildFilter(filterList).build());

Check warning on line 45 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.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/MultiFilterConverter.java#L45

Added line #L45 was not covered by tests
}

private Single<Filter> buildAndFilterOperations(
Collection<AttributeAssociation<FilterArgument>> andFilters) {
return Observable.fromIterable(andFilters)
.flatMapSingle(this::buildFilter)
.collect(Collectors.toUnmodifiableList())
.map(

Check warning on line 53 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.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/MultiFilterConverter.java#L50-L53

Added lines #L50 - L53 were not covered by tests
filterList ->
Filter.newBuilder()
.setOperator(Operator.AND)
.addAllChildFilter(filterList)
.build());

Check warning on line 58 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.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/MultiFilterConverter.java#L55-L58

Added lines #L55 - L58 were not covered by tests
}

private Single<Filter> buildFilter(AttributeAssociation<FilterArgument> filter) {
return zip(
this.attributeExpressionConverter.convert(
AttributeAssociation.of(filter.attribute(), filter.value().keyExpression())),
this.operatorConverter.convert(filter.value().operator()),
this.literalConstantExpressionConverter.convert(filter.value().value()),

Check warning on line 66 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.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/MultiFilterConverter.java#L62-L66

Added lines #L62 - L66 were not covered by tests
(key, operator, value) ->
Filter.newBuilder().setLhs(key).setOperator(operator).setRhs(value).build());

Check warning on line 68 in hypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.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/MultiFilterConverter.java#L68

Added line #L68 was not covered by tests
}
}