-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 Codecov / codecov/patchhypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.java#L27-L31
|
||
|
||
@Override | ||
public Single<Filter> convert( | ||
Collection<Collection<AttributeAssociation<FilterArgument>>> filters) { | ||
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 Codecov / codecov/patchhypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.java#L37
|
||
} | ||
|
||
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 Codecov / codecov/patchhypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.java#L40-L43
|
||
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 Codecov / codecov/patchhypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.java#L45
|
||
} | ||
|
||
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 Codecov / codecov/patchhypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.java#L50-L53
|
||
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 Codecov / codecov/patchhypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.java#L55-L58
|
||
} | ||
|
||
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 Codecov / codecov/patchhypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.java#L62-L66
|
||
(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 Codecov / codecov/patchhypertrace-core-graphql-gateway-service-utils/src/main/java/org/hypertrace/core/graphql/utils/gateway/MultiFilterConverter.java#L68
|
||
} | ||
} |
There was a problem hiding this comment.
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