use of datawave.query.attributes.AttributeFactory in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method buildExceededFromTermFrequency.
/**
* @param data
*/
private NestedIterator<Key> buildExceededFromTermFrequency(String identifier, JexlNode rootNode, JexlNode sourceNode, LiteralRange<?> range, Object data) {
if (limitLookup) {
ChainableEventDataQueryFilter wrapped = createWrappedTermFrequencyFilter(identifier, sourceNode, attrFilter);
NestedIterator<Key> eventFieldIterator = new EventFieldIterator(rangeLimiter, source.deepCopy(env), identifier, new AttributeFactory(this.typeMetadata), getEventFieldAggregator(identifier, wrapped));
TermFrequencyIndexBuilder builder = new TermFrequencyIndexBuilder();
builder.setSource(source.deepCopy(env));
builder.setTypeMetadata(typeMetadata);
builder.setFieldsToAggregate(fieldsToAggregate);
builder.setTimeFilter(timeFilter);
builder.setAttrFilter(attrFilter);
builder.setDatatypeFilter(datatypeFilter);
builder.setEnv(env);
builder.setTermFrequencyAggregator(getTermFrequencyAggregator(identifier, sourceNode, attrFilter, attrFilter != null ? attrFilter.getMaxNextCount() : -1));
builder.setNode(rootNode);
Range fiRange = getFiRangeForTF(range);
builder.setRange(fiRange);
builder.setField(identifier);
NestedIterator<Key> tfIterator = builder.build();
OrIterator tfMerge = new OrIterator(Arrays.asList(tfIterator, eventFieldIterator));
return tfMerge;
} else {
QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "buildExceededFromTermFrequency"));
throw new DatawaveFatalQueryException(qe);
}
}
use of datawave.query.attributes.AttributeFactory in project datawave by NationalSecurityAgency.
the class TLDEventDataFilterTest method setup.
@Before
public void setup() {
mockScript = createMock(ASTJexlScript.class);
mockAttributeFactory = createMock(TypeMetadata.class);
String lcNoDiacritics = LcNoDiacriticsType.class.getName();
String number = NumberType.class.getName();
TypeMetadata md = new TypeMetadata();
md.put("FOO", "dataType", lcNoDiacritics);
md.put("BAZ", "dataType", number);
md.put("BAR", "dataType", lcNoDiacritics);
md.put("BAR", "dataType", number);
attrFactory = new AttributeFactory(md);
}
use of datawave.query.attributes.AttributeFactory in project datawave by NationalSecurityAgency.
the class TermFrequencyAggregatorTest method apply_buildDocNotKeep.
@Test
public void apply_buildDocNotKeep() throws IOException {
Document doc = new Document();
AttributeFactory attributeFactory = new AttributeFactory(new TypeMetadata());
TreeMap<Key, Value> treeMap = Maps.newTreeMap();
treeMap.put(getTF("123", "FIELD1", "VALUE1", "dataType1", "123.345.456", 10), new Value());
treeMap.put(getTF("123", "NEXT_DOC_FIELD", "VALUE1", "dataType1", "124.345.456", 10), new Value());
SortedKeyValueIterator<Key, Value> itr = new SortedMapIterator(treeMap);
itr.seek(new Range(), null, true);
Set<String> keepFields = new HashSet<>();
keepFields.add("FIELD2");
EventDataQueryFilter filter = new EventDataQueryFieldFilter();
Set<String> blacklist = new HashSet<>();
blacklist.add("FIELD1");
((EventDataQueryFieldFilter) filter).initializeBlacklist(blacklist);
aggregator = new TermFrequencyAggregator(keepFields, filter, -1);
Key result = aggregator.apply(itr, doc, attributeFactory);
// test result key
assertTrue(result == null);
// test that the doc is empty
assertTrue(doc.size() == 0);
// test that the iterator is in the correct position
assertTrue(itr.hasTop());
assertTrue(itr.getTopKey().equals(getTF("123", "NEXT_DOC_FIELD", "VALUE1", "dataType1", "124.345.456", 10)));
}
use of datawave.query.attributes.AttributeFactory in project datawave by NationalSecurityAgency.
the class TermFrequencyAggregatorTest method apply_buildDocKeepFilteredOut.
@Test
public void apply_buildDocKeepFilteredOut() throws IOException, ParseException {
Document doc = new Document();
AttributeFactory attributeFactory = new AttributeFactory(new TypeMetadata());
TreeMap<Key, Value> treeMap = Maps.newTreeMap();
treeMap.put(getTF("123", "FIELD1", "VALUE1", "dataType1", "123.345.456", 10), new Value());
treeMap.put(getTF("123", "NEXT_DOC_FIELD", "VALUE1", "dataType1", "124.345.456", 10), new Value());
SortedKeyValueIterator<Key, Value> itr = new SortedMapIterator(treeMap);
itr.seek(new Range(), null, true);
Set<String> keepFields = new HashSet<>();
keepFields.add("FIELD2");
EventDataQueryFilter filter = new EventDataQueryFieldFilter(JexlASTHelper.parseJexlQuery("FIELD2 == 'VALUE1'"), Collections.EMPTY_SET);
aggregator = new TermFrequencyAggregator(keepFields, filter, -1);
Key result = aggregator.apply(itr, doc, attributeFactory);
// test result key
assertTrue(result == null);
// test that the doc is empty
assertTrue(doc.size() == 0);
// test that the iterator is in the correct position
assertTrue(itr.hasTop());
assertTrue(itr.getTopKey().equals(getTF("123", "NEXT_DOC_FIELD", "VALUE1", "dataType1", "124.345.456", 10)));
}
use of datawave.query.attributes.AttributeFactory in project datawave by NationalSecurityAgency.
the class EventDataQueryExpressionVisitorTest method setupTypeMetadata.
@Before
public void setupTypeMetadata() {
String lcNoDiacritics = LcNoDiacriticsType.class.getName();
String number = NumberType.class.getName();
TypeMetadata md = new TypeMetadata();
md.put("FOO", DATATYPE, lcNoDiacritics);
md.put("FOO2", DATATYPE, lcNoDiacritics);
md.put("BAZ", DATATYPE, number);
md.put("BAR", DATATYPE, lcNoDiacritics);
md.put("BAR", DATATYPE, number);
attrFactory = new AttributeFactory(md);
}
Aggregations