fix NPE for missing names in direct queries and block requests based on direct query count before deduping
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/98a2f5d2 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/98a2f5d2 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/98a2f5d2 Branch: refs/heads/master Commit: 98a2f5d23d4736219d23c637223a891c47216eed Parents: 59e7a24 Author: Mike Dunker <mdun...@google.com> Authored: Thu Apr 12 18:03:47 2018 -0700 Committer: Keyur Karnik <keyur.karnik+git...@gmail.com> Committed: Tue Aug 28 16:41:44 2018 -0700 ---------------------------------------------------------------------- .../pipeline/read/search/CandidateEntityFilter.java | 13 ++++++++----- .../persistence/index/impl/EsEntityIndexImpl.java | 7 ++++--- .../usergrid/persistence/index/query/ParsedQuery.java | 9 +++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/98a2f5d2/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/CandidateEntityFilter.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/CandidateEntityFilter.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/CandidateEntityFilter.java index 955b419..cf1984d 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/CandidateEntityFilter.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/CandidateEntityFilter.java @@ -289,13 +289,16 @@ public class CandidateEntityFilter extends AbstractFilter<FilterResult<Candidate if (!isDirectQuery) { filterDuplicateCandidates(query); } else { - // remove direct query duplicates + // remove direct query duplicates or missing entities (names that don't exist will have null ids) Set<UUID> foundUUIDs = new HashSet<>(); for (FilterResult<Candidate> candidateFilterResult : candidateResults) { - UUID uuid = candidateFilterResult.getValue().getCandidateResult().getId().getUuid(); - if (!foundUUIDs.contains(uuid)) { - dedupedCandidateResults.add(candidateFilterResult); - foundUUIDs.add(uuid); + Id id = candidateFilterResult.getValue().getCandidateResult().getId(); + if (id != null) { + UUID uuid = id.getUuid(); + if (!foundUUIDs.contains(uuid)) { + dedupedCandidateResults.add(candidateFilterResult); + foundUUIDs.add(uuid); + } } } } http://git-wip-us.apache.org/repos/asf/usergrid/blob/98a2f5d2/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java index 6dfb2ae..82be6ec 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java @@ -456,14 +456,15 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData { throw new IllegalArgumentException("a null query string cannot be parsed"); } + if (parsedQuery.isDirectQuery() && parsedQuery.getDirectQueryItemCount() > indexFig.directQueryMaxItems()) { + throw new TooManyDirectEntitiesException(parsedQuery.getDirectQueryItemCount(), indexFig.directQueryMaxItems()); + } + final QueryVisitor visitor = visitParsedQuery(parsedQuery); List<Identifier> directIdentifiers = visitor.getDirectIdentifiers(); if (directIdentifiers != null && directIdentifiers.size() > 0) { // this is a direct query - if (directIdentifiers.size() > indexFig.directQueryMaxItems()) { - throw new TooManyDirectEntitiesException(directIdentifiers.size(), indexFig.directQueryMaxItems()); - } return buildCandidateResultsForDirectQuery(directIdentifiers, parsedQuery, searchTypes); } http://git-wip-us.apache.org/repos/asf/usergrid/blob/98a2f5d2/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java index 80ba6b1..4c0da5d 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java @@ -211,4 +211,13 @@ public class ParsedQuery { public boolean isDirectQuery() { return rootOperand instanceof DirectOperand; } + + public int getDirectQueryItemCount() { + int count = 0; + if (rootOperand instanceof DirectOperand) { + DirectOperand root = (DirectOperand)rootOperand; + count = root.getChildCount(); + } + return count; + } }