-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a lucene and jexl implementations of a stochastic query builder f…
…or use in randomized input testing (#2381)
- Loading branch information
1 parent
d70fcd1
commit b7d257f
Showing
9 changed files
with
1,323 additions
and
30 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
123 changes: 123 additions & 0 deletions
123
warehouse/query-core/src/test/java/datawave/query/jexl/util/AbstractQueryGenerator.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,123 @@ | ||
package datawave.query.jexl.util; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.Set; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
public abstract class AbstractQueryGenerator implements QueryGenerator { | ||
|
||
protected boolean intersectionsEnabled = true; | ||
protected boolean unionsEnabled = true; | ||
protected boolean negationsEnabled = false; | ||
protected boolean regexEnabled = false; | ||
protected boolean filterFunctionsEnabled = false; | ||
protected boolean contentFunctionsEnabled = false; | ||
protected boolean groupingFunctionsEnabled = false; | ||
|
||
protected final Random random = new Random(); | ||
protected final StringBuilder sb = new StringBuilder(); | ||
|
||
protected final List<String> fields; | ||
protected final List<String> values; | ||
|
||
enum NodeType { | ||
EQ, NE, ER, FILTER_FUNCTION, CONTENT_FUNCTION, GROUPING_FUNCTION | ||
} | ||
|
||
public AbstractQueryGenerator(Set<String> fields, Set<String> values) { | ||
this.fields = Lists.newArrayList(fields); | ||
this.values = Lists.newArrayList(values); | ||
} | ||
|
||
public void validateOptions() { | ||
if (!intersectionsEnabled && !unionsEnabled) { | ||
throw new IllegalStateException("cannot disable both unions and intersections"); | ||
} | ||
} | ||
|
||
public QueryGenerator enableIntersections() { | ||
intersectionsEnabled = true; | ||
return this; | ||
} | ||
|
||
public QueryGenerator disableIntersections() { | ||
intersectionsEnabled = false; | ||
return this; | ||
} | ||
|
||
public QueryGenerator enableUnions() { | ||
unionsEnabled = true; | ||
return this; | ||
} | ||
|
||
public QueryGenerator disableUnions() { | ||
unionsEnabled = false; | ||
return this; | ||
} | ||
|
||
public QueryGenerator enableNegations() { | ||
negationsEnabled = true; | ||
return this; | ||
} | ||
|
||
public QueryGenerator disableNegations() { | ||
negationsEnabled = false; | ||
return this; | ||
} | ||
|
||
public QueryGenerator enableRegexes() { | ||
regexEnabled = true; | ||
return this; | ||
} | ||
|
||
public QueryGenerator disableRegexes() { | ||
regexEnabled = false; | ||
return this; | ||
} | ||
|
||
public QueryGenerator enableFilterFunctions() { | ||
filterFunctionsEnabled = true; | ||
return this; | ||
} | ||
|
||
public QueryGenerator disableFilterFunctions() { | ||
filterFunctionsEnabled = false; | ||
return this; | ||
} | ||
|
||
public QueryGenerator enableContentFunctions() { | ||
contentFunctionsEnabled = true; | ||
return this; | ||
} | ||
|
||
public QueryGenerator disableContentFunctions() { | ||
contentFunctionsEnabled = false; | ||
return this; | ||
} | ||
|
||
public QueryGenerator enableGroupingFunctions() { | ||
groupingFunctionsEnabled = true; | ||
return this; | ||
} | ||
|
||
public QueryGenerator disableGroupingFunctions() { | ||
groupingFunctionsEnabled = false; | ||
return this; | ||
} | ||
|
||
public QueryGenerator enableAllOptions() { | ||
return enableNegations().enableRegexes().enableFilterFunctions().enableContentFunctions().enableGroupingFunctions(); | ||
} | ||
|
||
public QueryGenerator disableAllOptions() { | ||
return disableNegations().disableRegexes().disableFilterFunctions().disableContentFunctions().disableGroupingFunctions(); | ||
} | ||
|
||
protected abstract void buildNode(); | ||
|
||
protected abstract void buildJunction(); | ||
|
||
protected abstract void buildLeaf(); | ||
} |
Oops, something went wrong.