-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to specify a max count on results from the unique operation such that only the unique results that occurred up to the specified max count are returned. This max count can be specified either via the function MAX_UNIQUE_COUNT or via the query parameter max.unique.count. Fixes #2635
- Loading branch information
Showing
17 changed files
with
438 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...house/query-core/src/main/java/datawave/query/language/functions/jexl/MaxUniqueCount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package datawave.query.language.functions.jexl; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.ArrayList; | ||
|
||
import datawave.query.Constants; | ||
import datawave.query.jexl.functions.QueryFunctions; | ||
import datawave.query.language.functions.QueryFunction; | ||
import datawave.webservice.query.exception.BadRequestQueryException; | ||
import datawave.webservice.query.exception.DatawaveErrorCode; | ||
|
||
public class MaxUniqueCount extends JexlQueryFunction { | ||
|
||
public MaxUniqueCount() { | ||
super(QueryFunctions.MAX_UNIQUE_COUNT, new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
if (parameterList.size() == 1) { | ||
try { | ||
int value = Integer.parseInt(parameterList.get(0)); | ||
if (value < 1) { | ||
throw new IllegalArgumentException(new BadRequestQueryException(DatawaveErrorCode.INVALID_FUNCTION_ARGUMENTS, | ||
MessageFormat.format("{0} requires an integer argument greater than 0.", this.name))); | ||
} | ||
} catch (NumberFormatException e) { | ||
throw new IllegalArgumentException(new BadRequestQueryException(DatawaveErrorCode.INVALID_FUNCTION_ARGUMENTS, e, | ||
MessageFormat.format("Failed to parse argument in {0} to an integer.", this))); | ||
} | ||
} else { | ||
throw new IllegalArgumentException(new BadRequestQueryException(DatawaveErrorCode.INVALID_FUNCTION_ARGUMENTS, | ||
MessageFormat.format("{0} requires a single integer argument greater than 0.", this.name))); | ||
} | ||
} | ||
|
||
@Override | ||
public QueryFunction duplicate() { | ||
return new MaxUniqueCount(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(QueryFunctions.QUERY_FUNCTION_NAMESPACE).append(Constants.COLON).append(QueryFunctions.MAX_UNIQUE_COUNT); | ||
String separator = Constants.LEFT_PAREN; | ||
for (String param : parameterList) { | ||
sb.append(separator).append(param); | ||
separator = Constants.COMMA; | ||
} | ||
sb.append(Constants.RIGHT_PAREN); | ||
return sb.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.