-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added most recent equivalent unique functions (#2339)
* added MOST_RECENT_ in front of the function name
- Loading branch information
Showing
19 changed files
with
376 additions
and
23 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
72 changes: 72 additions & 0 deletions
72
...use/query-core/src/main/java/datawave/query/language/functions/jexl/MostRecentUnique.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,72 @@ | ||
package datawave.query.language.functions.jexl; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.ArrayList; | ||
import java.util.stream.Collectors; | ||
|
||
import datawave.query.attributes.UniqueFields; | ||
import datawave.query.jexl.functions.QueryFunctions; | ||
import datawave.query.language.functions.QueryFunction; | ||
import datawave.webservice.query.exception.BadRequestQueryException; | ||
import datawave.webservice.query.exception.DatawaveErrorCode; | ||
|
||
/** | ||
* Function to determine most recent uniqueness among documents given a set of fields and the levels of granularity that should be used for each fields. This | ||
* function accepts a list of fields with specified granularity levels in the format {@code field[ALL],dateField[DAY,HOUR,MINUTE]}. See {@link UniqueFields} for | ||
* additional documentation on supported formatting. | ||
*/ | ||
public class MostRecentUnique extends JexlQueryFunction { | ||
|
||
public MostRecentUnique() { | ||
super(QueryFunctions.MOST_RECENT_PREFIX + QueryFunctions.UNIQUE_FUNCTION, new ArrayList<>()); | ||
} | ||
|
||
/** | ||
* query options contain a list of fields. Cannot be the empty list. | ||
* | ||
* @throws IllegalArgumentException | ||
* for illegal arguments | ||
*/ | ||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
if (this.parameterList.isEmpty()) { | ||
BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.INVALID_FUNCTION_ARGUMENTS, | ||
MessageFormat.format("{0} requires at least one argument", this.name)); | ||
throw new IllegalArgumentException(qe); | ||
} else { | ||
String parameters = String.join(",", parameterList); | ||
try { | ||
UniqueFields.from(parameters); | ||
} catch (Exception e) { | ||
BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.INVALID_FUNCTION_ARGUMENTS, | ||
MessageFormat.format("Unable to parse unique fields from arguments for function {0}", this.name)); | ||
throw new IllegalArgumentException(qe); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
sb.append(QueryFunctions.QUERY_FUNCTION_NAMESPACE).append(':').append(QueryFunctions.MOST_RECENT_PREFIX).append(QueryFunctions.UNIQUE_FUNCTION); | ||
if (parameterList.isEmpty()) { | ||
sb.append("()"); | ||
} else { | ||
char separator = '('; | ||
for (String parm : parameterList) { | ||
sb.append(separator).append(escapeString(parm)); | ||
separator = ','; | ||
} | ||
sb.append(')'); | ||
} | ||
|
||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public QueryFunction duplicate() { | ||
return new Unique(); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...uery-core/src/main/java/datawave/query/language/functions/jexl/MostRecentUniqueByDay.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,22 @@ | ||
package datawave.query.language.functions.jexl; | ||
|
||
import java.util.ArrayList; | ||
|
||
import datawave.query.jexl.functions.QueryFunctions; | ||
import datawave.query.jexl.visitors.QueryOptionsFromQueryVisitor; | ||
import datawave.query.language.functions.QueryFunction; | ||
|
||
/** | ||
* Function to return a unique result for every day for a given list of fields. This function is equivalent to {@code #MOST_RECENT_UNIQUE(field[DAY])}. | ||
*/ | ||
public class MostRecentUniqueByDay extends UniqueByFunction { | ||
|
||
public MostRecentUniqueByDay() { | ||
super(QueryFunctions.MOST_RECENT_PREFIX + QueryOptionsFromQueryVisitor.UniqueFunction.UNIQUE_BY_DAY_FUNCTION, new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public QueryFunction duplicate() { | ||
return new UniqueByDay(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ery-core/src/main/java/datawave/query/language/functions/jexl/MostRecentUniqueByHour.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,23 @@ | ||
package datawave.query.language.functions.jexl; | ||
|
||
import java.util.ArrayList; | ||
|
||
import datawave.query.jexl.functions.QueryFunctions; | ||
import datawave.query.jexl.visitors.QueryOptionsFromQueryVisitor; | ||
import datawave.query.language.functions.QueryFunction; | ||
|
||
/** | ||
* Function to return a unique result for every hour of the day for a given list of fields. This function is equivalent to | ||
* {@code #MOST_RECENT_UNIQUE(field[HOUR])}. | ||
*/ | ||
public class MostRecentUniqueByHour extends UniqueByFunction { | ||
|
||
public MostRecentUniqueByHour() { | ||
super(QueryFunctions.MOST_RECENT_PREFIX + QueryOptionsFromQueryVisitor.UniqueFunction.UNIQUE_BY_HOUR_FUNCTION, new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public QueryFunction duplicate() { | ||
return new UniqueByHour(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...y-core/src/main/java/datawave/query/language/functions/jexl/MostRecentUniqueByMinute.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,23 @@ | ||
package datawave.query.language.functions.jexl; | ||
|
||
import java.util.ArrayList; | ||
|
||
import datawave.query.jexl.functions.QueryFunctions; | ||
import datawave.query.jexl.visitors.QueryOptionsFromQueryVisitor; | ||
import datawave.query.language.functions.QueryFunction; | ||
|
||
/** | ||
* Function to return a most recent unique result for every minute of the hour for a given list of fields. This function is equivalent to | ||
* {@code #MOST_RECENT_UNIQUE(field[MINUTE])}. | ||
*/ | ||
public class MostRecentUniqueByMinute extends UniqueByFunction { | ||
|
||
public MostRecentUniqueByMinute() { | ||
super(QueryFunctions.MOST_RECENT_PREFIX + QueryOptionsFromQueryVisitor.UniqueFunction.UNIQUE_BY_MINUTE_FUNCTION, new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public QueryFunction duplicate() { | ||
return new UniqueByMinute(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ry-core/src/main/java/datawave/query/language/functions/jexl/MostRecentUniqueByMonth.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,23 @@ | ||
package datawave.query.language.functions.jexl; | ||
|
||
import java.util.ArrayList; | ||
|
||
import datawave.query.jexl.functions.QueryFunctions; | ||
import datawave.query.jexl.visitors.QueryOptionsFromQueryVisitor; | ||
import datawave.query.language.functions.QueryFunction; | ||
|
||
/** | ||
* Function to return a most recent unique result for every month of the year for a given list of fields. This function is equivalent to | ||
* {@code #MOST_RECENT_UNIQUE(field[MONTH])}. | ||
*/ | ||
public class MostRecentUniqueByMonth extends UniqueByFunction { | ||
|
||
public MostRecentUniqueByMonth() { | ||
super(QueryFunctions.MOST_RECENT_PREFIX + QueryOptionsFromQueryVisitor.UniqueFunction.UNIQUE_BY_MONTH_FUNCTION, new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public QueryFunction duplicate() { | ||
return new UniqueByMonth(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...y-core/src/main/java/datawave/query/language/functions/jexl/MostRecentUniqueBySecond.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,23 @@ | ||
package datawave.query.language.functions.jexl; | ||
|
||
import java.util.ArrayList; | ||
|
||
import datawave.query.jexl.functions.QueryFunctions; | ||
import datawave.query.jexl.visitors.QueryOptionsFromQueryVisitor; | ||
import datawave.query.language.functions.QueryFunction; | ||
|
||
/** | ||
* Function to return a most recent unique result for every second for a given list of fields. This function is equivalent to | ||
* {@code #MOST_RECENT_UNIQUE(field[SECOND])}. | ||
*/ | ||
public class MostRecentUniqueBySecond extends UniqueByFunction { | ||
|
||
public MostRecentUniqueBySecond() { | ||
super(QueryFunctions.MOST_RECENT_PREFIX + QueryOptionsFromQueryVisitor.UniqueFunction.UNIQUE_BY_SECOND_FUNCTION, new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public QueryFunction duplicate() { | ||
return new UniqueBySecond(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...e/src/main/java/datawave/query/language/functions/jexl/MostRecentUniqueByTenthOfHour.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,23 @@ | ||
package datawave.query.language.functions.jexl; | ||
|
||
import java.util.ArrayList; | ||
|
||
import datawave.query.jexl.functions.QueryFunctions; | ||
import datawave.query.jexl.visitors.QueryOptionsFromQueryVisitor; | ||
import datawave.query.language.functions.QueryFunction; | ||
|
||
/** | ||
* Function to return a most recent_unique result for every tenth of an hour for a given list of fields. This function is equivalent to | ||
* {@code #MOST_RECENT_UNIQUE(field[TENTH_OF_HOUR])}. | ||
*/ | ||
public class MostRecentUniqueByTenthOfHour extends UniqueByFunction { | ||
|
||
public MostRecentUniqueByTenthOfHour() { | ||
super(QueryFunctions.MOST_RECENT_PREFIX + QueryOptionsFromQueryVisitor.UniqueFunction.UNIQUE_BY_TENTH_OF_HOUR_FUNCTION, new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public QueryFunction duplicate() { | ||
return new UniqueByTenthOfHour(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ery-core/src/main/java/datawave/query/language/functions/jexl/MostRecentUniqueByYear.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,23 @@ | ||
package datawave.query.language.functions.jexl; | ||
|
||
import java.util.ArrayList; | ||
|
||
import datawave.query.jexl.functions.QueryFunctions; | ||
import datawave.query.jexl.visitors.QueryOptionsFromQueryVisitor; | ||
import datawave.query.language.functions.QueryFunction; | ||
|
||
/** | ||
* Function to return a most recent unique result for the year for a given list of fields. This function is equivalent to | ||
* {@code #MOST_RECENT_UNIQUE(field[YEAR])}. | ||
*/ | ||
public class MostRecentUniqueByYear extends UniqueByFunction { | ||
|
||
public MostRecentUniqueByYear() { | ||
super(QueryFunctions.MOST_RECENT_PREFIX + QueryOptionsFromQueryVisitor.UniqueFunction.UNIQUE_BY_YEAR_FUNCTION, new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public QueryFunction duplicate() { | ||
return new UniqueByYear(); | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
warehouse/query-core/src/main/java/datawave/query/language/functions/jexl/UniqueByDay.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
Oops, something went wrong.