Skip to content

Commit

Permalink
remove EXCLUDE_FILTER in Qualifier
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Nov 9, 2023
1 parent 8b3f47e commit 2127cb5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import static org.springframework.data.aerospike.core.TemplateUtils.getIdValue;
import static org.springframework.data.aerospike.query.QualifierUtils.getOneIdQualifier;
import static org.springframework.data.aerospike.query.QualifierUtils.queryCriteriaIsNotNull;
import static org.springframework.data.aerospike.query.QualifierUtils.validateQualifiers;

/**
* Primary implementation of {@link AerospikeOperations}.
Expand Down Expand Up @@ -1276,8 +1275,6 @@ private <T> Stream<T> applyPostProcessingOnResults(Stream<T> results, Sort sort,
private <T> Stream<KeyRecord> findRecordsUsingQuery(String setName, Class<T> targetClass, Query query) {
Qualifier qualifier = queryCriteriaIsNotNull(query) ? query.getCriteria().getCriteriaObject() : null;
if (qualifier != null) {
validateQualifiers(qualifier);

Qualifier idQualifier = getOneIdQualifier(qualifier);
if (idQualifier != null) {
// a special flow if there is id given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import static org.springframework.data.aerospike.core.TemplateUtils.getIdValue;
import static org.springframework.data.aerospike.query.QualifierUtils.getOneIdQualifier;
import static org.springframework.data.aerospike.query.QualifierUtils.queryCriteriaIsNotNull;
import static org.springframework.data.aerospike.query.QualifierUtils.validateQualifiers;

/**
* Primary implementation of {@link ReactiveAerospikeOperations}.
Expand Down Expand Up @@ -1232,8 +1231,6 @@ private <T> Flux<T> findUsingQueryWithDistinctPredicate(String setName, Class<T>
private <T> Flux<KeyRecord> findRecordsUsingQuery(String setName, Class<T> targetClass, Query query) {
Qualifier qualifier = queryCriteriaIsNotNull(query) ? query.getCriteria().getCriteriaObject() : null;
if (qualifier != null) {
validateQualifiers(qualifier);

Qualifier idQualifier = getOneIdQualifier(qualifier);
if (idQualifier != null) {
// a special flow if there is id given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class Qualifier implements CriteriaDefinition, Map<String, Object>, Seria
protected static final String QUALIFIERS = "qualifiers";
protected static final String OPERATION = "operation";
protected static final String AS_FILTER = "queryAsFilter";
protected static final String EXCLUDE_FILTER = "excludeFilter";
@Serial
private static final long serialVersionUID = -2689196529952712849L;
protected final Map<String, Object> internalMap = new HashMap<>();
Expand Down Expand Up @@ -114,14 +113,6 @@ public Boolean queryAsFilter() {
return internalMap.containsKey(AS_FILTER) && (Boolean) internalMap.get(AS_FILTER);
}

public boolean getExcludeFilter() {
return internalMap.containsKey(EXCLUDE_FILTER) && (Boolean) internalMap.get(EXCLUDE_FILTER);
}

public void setExcludeFilter(boolean excludeFilter) {
internalMap.put(EXCLUDE_FILTER, excludeFilter);
}

public boolean hasQualifiers() {
return internalMap.get(QUALIFIERS) != null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.springframework.data.aerospike.query;

import lombok.experimental.UtilityClass;
import org.springframework.data.aerospike.repository.query.AerospikeCriteria;
import org.springframework.data.aerospike.repository.query.Query;

import java.util.ArrayList;
Expand All @@ -10,58 +9,20 @@
@UtilityClass
public class QualifierUtils {

@Deprecated(since = "4.6.0", forRemoval = true)
public static Qualifier getIdQualifier(AerospikeCriteria criteria) {
Object qualifiers = getQualifiers(criteria);
return getOneIdQualifier((Qualifier[]) qualifiers);
}

public static Qualifier getIdQualifier(Qualifier criteria) {
Object qualifiers = getQualifiers(criteria);
return getOneIdQualifier((Qualifier[]) qualifiers);
}

@Deprecated(since = "4.6.0", forRemoval = true)
public static Qualifier[] getQualifiers(AerospikeCriteria criteria) {
if (criteria == null) {
return null;
} else if (criteria.getQualifiers() == null) {
return new Qualifier[]{(criteria)};
}
return criteria.getQualifiers();
}

public static Qualifier[] getQualifiers(Qualifier criteria) {
if (criteria == null) {
return null;
} else if (criteria.getQualifiers() == null) {
return new Qualifier[]{criteria};
}
return criteria.getQualifiers();
}

public static void validateQualifiers(Qualifier... qualifiers) {
boolean haveInternalQualifiers = qualifiers.length > 1;
for (Qualifier qualifier : qualifiers) {
haveInternalQualifiers = haveInternalQualifiers || qualifier.hasQualifiers();
// excludeFilter in the upmost parent qualifier is set to true
// if there are multiple qualifiers
// must not build secondary index filter based on any of them
// as it might conflict with the combination of qualifiers
qualifier.setExcludeFilter(haveInternalQualifiers);
}
public static Qualifier getIdQualifier(Qualifier qualifier) {
return getOneIdQualifier(qualifier);
}

/**
* Find id qualifier.
*
* @param qualifiers Qualifiers to search through
* @return The only id qualifier or null.
* @param qualifier {@link Qualifier} to search through
* @return The only id qualifier or null
* @throws IllegalArgumentException if more than one id qualifier given
*/
public static Qualifier getOneIdQualifier(Qualifier... qualifiers) {
if (qualifiers != null && qualifiers.length > 0) {
List<Qualifier> idQualifiers = getIdQualifiers(qualifiers);
public static Qualifier getOneIdQualifier(Qualifier qualifier) {
if (qualifier != null) {
List<Qualifier> idQualifiers = getIdQualifiers(new Qualifier[]{qualifier});
if (idQualifiers.size() > 1) {
throw new IllegalArgumentException("Expecting not more than one id qualifier in qualifiers array," +
" got " + idQualifiers.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void setStatementFilterFromQualifiers(Statement stmt, Qualifier qualifie
/*
* query with qualifier
*/
if (qualifier == null || qualifier.getExcludeFilter()) return;
if (qualifier == null) return;
if (qualifier.getOperation() == FilterOperation.AND) {
// no sense to use secondary index in case of OR
// as it requires to enlarge selection to more than 1 field
Expand Down

0 comments on commit 2127cb5

Please sign in to comment.