Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport #2051 to 5.8 #2069

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Tuple3<Key,Document,Map<String,Object>> apply(Tuple2<Key,Document> from)

logStart();
Map<String,Object> map = new HashMap<>(tfPopulator.getContextMap(from.first(), docKeys, fields));
logStop(docKeys.iterator().next());
logStop(docKeys);

Document merged = from.second();
merged.putAll(tfPopulator.document(), false);
Expand Down Expand Up @@ -96,14 +96,19 @@ private void logStart() {
aggregationStart = System.currentTimeMillis();
}

private void logStop(Key k) {
private void logStop(Set<Key> keys) {
if (aggregationThreshold == -1) {
return;
}

long elapsed = System.currentTimeMillis() - aggregationStart;
if (elapsed > aggregationThreshold) {
log.warn("time to aggregate offsets " + k.getRow() + " " + k.getColumnFamily().toString().replace("\0", "0x00") + " was " + elapsed);
if (keys == null || keys.isEmpty()) {
log.warn("time to aggregate offsets was " + elapsed);
} else {
Key k = keys.iterator().next();
log.warn("time to aggregate offsets " + k.getRow() + " " + k.getColumnFamily().toString().replace("\0", "0x00") + " was " + elapsed);
}
}
}

Expand Down
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();
}
}

}