Skip to content

Commit 4bc32e9

Browse files
committed
Updated Visitor function to avoid modifying config as it needs to remain (#3086)
thread safe
1 parent c149b9a commit 4bc32e9

File tree

2 files changed

+48
-50
lines changed

2 files changed

+48
-50
lines changed

warehouse/query-core/src/main/java/datawave/query/jexl/visitors/PushdownLargeFieldedListsVisitor.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ public Object visit(ASTOrNode node, Object data) {
132132
SortedSet<String> fields = new TreeSet<>(eqNodesByField.keySet());
133133
fields.addAll(rangeNodesByField.keySet());
134134

135+
// capture the thresholds
136+
int maxOrExpansionFstThreshold = config.getMaxOrExpansionFstThreshold();
137+
int maxOrExpansionThreshold = config.getMaxOrExpansionThreshold();
138+
int maxOrRangeThreshold = config.getMaxOrRangeThreshold();
139+
140+
// if specific fields were requested, then reduce the thresholds
141+
if (this.fields != null) {
142+
maxOrExpansionThreshold = 2;
143+
maxOrRangeThreshold = 2;
144+
}
145+
135146
for (String field : fields) {
136147
// if fields is not specified or the current field is in fields it can be reduced
137148
boolean canReduce = (this.fields == null || this.fields.contains(field));
@@ -145,9 +156,9 @@ public Object visit(ASTOrNode node, Object data) {
145156
if (canReduce &&
146157
!Constants.ANY_FIELD.equals(field) &&
147158
!Constants.NO_FIELD.equals(field) &&
148-
(eqNodes.size() >= config.getMaxOrExpansionFstThreshold() ||
149-
eqNodes.size() >= config.getMaxOrExpansionThreshold() ||
150-
rangeNodes.size() >= config.getMaxOrRangeThreshold()
159+
(eqNodes.size() >= maxOrExpansionFstThreshold ||
160+
eqNodes.size() >= maxOrExpansionThreshold ||
161+
rangeNodes.size() >= maxOrRangeThreshold
151162
) &&
152163
isIndexed(field)) {
153164
// @formatter:on
@@ -164,17 +175,17 @@ public Object visit(ASTOrNode node, Object data) {
164175

165176
try {
166177
// if we have an hdfs cache directory and if past the fst/list threshold, then create the fst/list and replace the list with an assignment
167-
if (fstHdfsUri != null && (eqNodes.size() >= config.getMaxOrExpansionFstThreshold())) {
178+
if (fstHdfsUri != null && (eqNodes.size() >= maxOrExpansionFstThreshold)) {
168179
URI fstPath = createFst(values);
169180
markers.add(QueryPropertyMarker.create(new ExceededOr(field, fstPath).getJexlNode(), EXCEEDED_OR));
170181
eqNodes = null;
171-
} else if (eqNodes.size() >= config.getMaxOrExpansionThreshold()) {
182+
} else if (eqNodes.size() >= maxOrExpansionThreshold) {
172183
markers.add(QueryPropertyMarker.create(new ExceededOr(field, values).getJexlNode(), EXCEEDED_OR));
173184
eqNodes = null;
174185
}
175186

176187
// handle range nodes separately
177-
if (rangeNodes.size() >= config.getMaxOrRangeThreshold()) {
188+
if (rangeNodes.size() >= maxOrRangeThreshold) {
178189
TreeMap<Range,JexlNode> ranges = new TreeMap<>();
179190
rangeNodes.forEach(rangeNode -> ranges.put(rangeNodeToRange(rangeNode), rangeNode));
180191

warehouse/query-core/src/main/java/datawave/query/tables/async/event/VisitorFunction.java

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -650,53 +650,40 @@ protected ASTJexlScript pushdownLargeFieldedLists(ShardQueryConfiguration config
650650
}
651651

652652
if (termCount - capacitySum <= config.getFinalMaxTermThreshold()) {
653-
// preserve the original config and set minimum thresholds for creating Value and Range ivarators
654-
int originalMaxOrExpansionThreshold = config.getMaxOrExpansionThreshold();
655-
int originalMaxOrRangeThreshold = config.getMaxOrRangeThreshold();
656-
657-
config.setMaxOrExpansionThreshold(2);
658-
config.setMaxOrRangeThreshold(2);
653+
// invert pushdownCapacity to get the largest payoffs first
654+
SortedMap<Integer,List<String>> sortedMap = new TreeMap<>();
655+
for (String fieldName : pushdownCapacity.keySet()) {
656+
Integer reduction = pushdownCapacity.get(fieldName);
657+
List<String> fields = sortedMap.computeIfAbsent(reduction, k -> new ArrayList<>());
658+
fields.add(fieldName);
659+
}
659660

660-
try {
661-
// invert pushdownCapacity to get the largest payoffs first
662-
SortedMap<Integer,List<String>> sortedMap = new TreeMap<>();
663-
for (String fieldName : pushdownCapacity.keySet()) {
664-
Integer reduction = pushdownCapacity.get(fieldName);
665-
List<String> fields = sortedMap.computeIfAbsent(reduction, k -> new ArrayList<>());
666-
fields.add(fieldName);
667-
}
668-
669-
// sort from largest to smallest reductions and make reductions until under the threshold
670-
Set<String> fieldsToReduce = new HashSet<>();
671-
int toReduce = termCount - config.getFinalMaxTermThreshold();
672-
while (toReduce > 0) {
673-
// get the highest value field out of the map
674-
Integer reduction = sortedMap.lastKey();
675-
List<String> fields = sortedMap.get(reduction);
676-
677-
// take the first field
678-
String field = fields.remove(0);
679-
fieldsToReduce.add(field);
680-
toReduce -= reduction;
681-
682-
// if there are no more reductions of this size remove the reduction from pushdown capacity
683-
if (fields.size() == 0) {
684-
sortedMap.remove(reduction);
685-
}
661+
// sort from largest to smallest reductions and make reductions until under the threshold
662+
Set<String> fieldsToReduce = new HashSet<>();
663+
int toReduce = termCount - config.getFinalMaxTermThreshold();
664+
while (toReduce > 0) {
665+
// get the highest value field out of the map
666+
Integer reduction = sortedMap.lastKey();
667+
List<String> fields = sortedMap.get(reduction);
668+
669+
// take the first field
670+
String field = fields.remove(0);
671+
fieldsToReduce.add(field);
672+
toReduce -= reduction;
673+
674+
// if there are no more reductions of this size remove the reduction from pushdown capacity
675+
if (fields.size() == 0) {
676+
sortedMap.remove(reduction);
686677
}
678+
}
687679

688-
// execute the reduction
689-
if (hdfsQueryCacheUri != null) {
690-
FileSystem fs = VisitorFunction.fileSystemCache.getFileSystem(hdfsQueryCacheUri);
691-
// Find large lists of values against the same field and push down into an Ivarator
692-
script = PushdownLargeFieldedListsVisitor.pushdown(config, script, fs, hdfsQueryCacheUri.toString(), null, fieldsToReduce);
693-
} else {
694-
script = PushdownLargeFieldedListsVisitor.pushdown(config, script, null, null, null, fieldsToReduce);
695-
}
696-
} finally {
697-
// reset config thresholds
698-
config.setMaxOrExpansionThreshold(originalMaxOrExpansionThreshold);
699-
config.setMaxOrRangeThreshold(originalMaxOrRangeThreshold);
680+
// execute the reduction
681+
if (hdfsQueryCacheUri != null) {
682+
FileSystem fs = VisitorFunction.fileSystemCache.getFileSystem(hdfsQueryCacheUri);
683+
// Find large lists of values against the same field and push down into an Ivarator
684+
script = PushdownLargeFieldedListsVisitor.pushdown(config, script, fs, hdfsQueryCacheUri.toString(), null, fieldsToReduce);
685+
} else {
686+
script = PushdownLargeFieldedListsVisitor.pushdown(config, script, null, null, null, fieldsToReduce);
700687
}
701688
}
702689
}

0 commit comments

Comments
 (0)