-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct logic to protect against NoSuchElementException (#2069)
- Loading branch information
1 parent
9ee7757
commit ceec11c
Showing
2 changed files
with
66 additions
and
3 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
58 changes: 58 additions & 0 deletions
58
...use/query-core/src/test/java/datawave/query/postprocessing/tf/TermOffsetFunctionTest.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,58 @@ | ||
package datawave.query.postprocessing.tf; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.apache.accumulo.core.data.Key; | ||
|
||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.Multimap; | ||
|
||
import datawave.query.attributes.Document; | ||
import datawave.query.jexl.JexlASTHelper; | ||
import datawave.query.util.Tuple2; | ||
import datawave.query.util.Tuple3; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class TermOffsetFunctionTest { | ||
|
||
@Test | ||
public void testApplyWithLogLogAggregationPruneToZero() throws Exception { | ||
TermFrequencyConfig config = new TermFrequencyConfig(); | ||
config.setScript(JexlASTHelper.parseAndFlattenJexlQuery("content:phrase(FOO, termOffsetMap, 'bar', 'baz')")); | ||
DocumentKeysFunction docKeyFunction = new DocumentKeysFunction(config); | ||
|
||
MyTermOffsetPopulator termOffsetPopulator = new MyTermOffsetPopulator(null, config); | ||
|
||
TermOffsetFunction termOffsetFunction = new TermOffsetFunction(termOffsetPopulator, Collections.emptySet(), docKeyFunction); | ||
Tuple3<Key,Document,Map<String,Object>> tuple = termOffsetFunction.apply(new Tuple2<>(new Key(), new Document())); | ||
assertEquals(new Key(), tuple.first()); | ||
assertEquals(new Document(), tuple.second()); | ||
assertEquals(new HashMap<String,Object>(), tuple.third()); | ||
} | ||
|
||
// no-op | ||
private static class MyTermOffsetPopulator extends TermOffsetPopulator { | ||
|
||
public MyTermOffsetPopulator(Multimap<String,String> termFrequencyFieldValues, TermFrequencyConfig config) { | ||
super(termFrequencyFieldValues, config); | ||
} | ||
|
||
public Multimap<String,String> getTermFrequencyFieldValues() { | ||
return HashMultimap.create(); | ||
} | ||
|
||
public Map<String,Object> getContextMap(Key docKey, Set<Key> keys, Set<String> fields) { | ||
return new HashMap<>(); | ||
} | ||
|
||
public Document document() { | ||
return new Document(); | ||
} | ||
} | ||
|
||
} |