Search in sources :

Example 1 with AttributeFactory

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);
    }
}
Also used : ChainableEventDataQueryFilter(datawave.query.predicate.ChainableEventDataQueryFilter) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) EventFieldIterator(datawave.query.iterator.EventFieldIterator) TermFrequencyIndexBuilder(datawave.query.iterator.builder.TermFrequencyIndexBuilder) OrIterator(datawave.query.iterator.logic.OrIterator) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) AttributeFactory(datawave.query.attributes.AttributeFactory) LiteralRange(datawave.query.jexl.LiteralRange) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 2 with AttributeFactory

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);
}
Also used : TypeMetadata(datawave.query.util.TypeMetadata) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) AttributeFactory(datawave.query.attributes.AttributeFactory) Before(org.junit.Before)

Example 3 with AttributeFactory

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)));
}
Also used : TypeMetadata(datawave.query.util.TypeMetadata) EventDataQueryFilter(datawave.query.predicate.EventDataQueryFilter) AttributeFactory(datawave.query.attributes.AttributeFactory) Document(datawave.query.attributes.Document) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) EventDataQueryFieldFilter(datawave.query.predicate.EventDataQueryFieldFilter) Value(org.apache.accumulo.core.data.Value) DatawaveKey(datawave.query.data.parsers.DatawaveKey) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with AttributeFactory

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)));
}
Also used : TypeMetadata(datawave.query.util.TypeMetadata) EventDataQueryFilter(datawave.query.predicate.EventDataQueryFilter) AttributeFactory(datawave.query.attributes.AttributeFactory) Document(datawave.query.attributes.Document) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) EventDataQueryFieldFilter(datawave.query.predicate.EventDataQueryFieldFilter) Value(org.apache.accumulo.core.data.Value) DatawaveKey(datawave.query.data.parsers.DatawaveKey) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with AttributeFactory

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);
}
Also used : TypeMetadata(datawave.query.util.TypeMetadata) AttributeFactory(datawave.query.attributes.AttributeFactory) Before(org.junit.Before)

Aggregations

AttributeFactory (datawave.query.attributes.AttributeFactory)10 TypeMetadata (datawave.query.util.TypeMetadata)9 Key (org.apache.accumulo.core.data.Key)8 Range (org.apache.accumulo.core.data.Range)8 Document (datawave.query.attributes.Document)7 EventDataQueryFilter (datawave.query.predicate.EventDataQueryFilter)7 HashSet (java.util.HashSet)7 Value (org.apache.accumulo.core.data.Value)7 SortedMapIterator (org.apache.accumulo.core.iterators.SortedMapIterator)7 Test (org.junit.Test)7 DatawaveKey (datawave.query.data.parsers.DatawaveKey)6 EventDataQueryFieldFilter (datawave.query.predicate.EventDataQueryFieldFilter)6 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 Attribute (datawave.query.attributes.Attribute)1 TypeAttribute (datawave.query.attributes.TypeAttribute)1 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)1 EventFieldIterator (datawave.query.iterator.EventFieldIterator)1 TermFrequencyIndexBuilder (datawave.query.iterator.builder.TermFrequencyIndexBuilder)1 OrIterator (datawave.query.iterator.logic.OrIterator)1