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

In support #535

Merged
merged 20 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.bpodgursky</groupId>
<artifactId>jbool_expressions</artifactId>
<version>1.24</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public FilterClause deserialize(
entry.getKey(), jsonNodeValue(entry.getKey(), entry.getValue())));
}
}

validate(expressionList);
return new FilterClause(expressionList);
}
Expand All @@ -90,11 +89,6 @@ private void validate(String path, FilterOperation<?> filterOperation) {
if (filterOperation.operator() instanceof ValueComparisonOperator valueComparisonOperator) {
switch (valueComparisonOperator) {
case IN -> {
if (!path.equals(DocumentConstants.Fields.DOC_ID)) {
throw new JsonApiException(
ErrorCode.INVALID_FILTER_EXPRESSION, "Can use $in operator only on _id field");
}

if (filterOperation.operand().value() instanceof List<?> list) {
if (list.size() > operationsConfig.defaultPageSize()) {
throw new JsonApiException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,81 @@ boolean canAddField() {
}
}
}

/**
* Filters db documents based on non document id field values if id use "$in" operator, use
Yuqi-Du marked this conversation as resolved.
Show resolved Hide resolved
* IDFilter, since partition key 'or' is not supported besides id, "$in" operator, use INFilter
*/
public static class InFilter extends DBFilterBase {
private final Object arrayValue;
Yuqi-Du marked this conversation as resolved.
Show resolved Hide resolved
protected final InFilter.Operator operator;

@Override
JsonNode asJson(JsonNodeFactory nodeFactory) {
return DBFilterBase.getJsonNode(nodeFactory, arrayValue);
}

@Override
boolean canAddField() {
return false;
}

public enum Operator {
Yuqi-Du marked this conversation as resolved.
Show resolved Hide resolved
IN;
}

public InFilter(InFilter.Operator operator, String path, Object arrayValue) {
super(path);
this.arrayValue = arrayValue;
this.operator = operator;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InFilter inFilter = (InFilter) o;
return operator == inFilter.operator && Objects.equals(arrayValue, inFilter.arrayValue);
}

@Override
public int hashCode() {
return Objects.hash(arrayValue, operator);
}

private static final String DATA_CONTAINS = "array_contains";
Yuqi-Du marked this conversation as resolved.
Show resolved Hide resolved

@Override
public BuiltCondition get() {
// For IN filter we always use getALL() method
Yuqi-Du marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

public List<BuiltCondition> getAll() {
List<String> values = (List<String>) arrayValue;
switch (operator) {
case IN:
if (values.isEmpty()) return List.of();
return values.stream()
.map(
v ->
BuiltCondition.of(
DATA_CONTAINS,
Predicate.CONTAINS,
getGrpcValue(getHashValue(new DocValueHasher(), getPath(), v))))
.collect(Collectors.toList());

default:
throw new JsonApiException(
ErrorCode.UNSUPPORTED_FILTER_OPERATION,
String.format("Unsupported %s column operation %s", getPath(), operator));
}
}
}

/**
* DB filter / condition for testing a set value Note: we can only do CONTAINS until SAI indexes
Yuqi-Du marked this conversation as resolved.
Show resolved Hide resolved
* are updated
* are updated Now, cassandra supports or operation, we can add $in
*/
public abstract static class SetFilterBase<T> extends DBFilterBase {
public enum Operator {
Expand Down
Loading