Search in sources :

Example 11 with PreNormalizedAttribute

use of datawave.query.attributes.PreNormalizedAttribute in project datawave by NationalSecurityAgency.

the class FunctionalSetTest method runTestQuery.

protected void runTestQuery(List<String> expected, String querystr, Date startDate, Date endDate, Map<String, String> extraParms, Connector connector) throws Exception {
    log.debug("runTestQuery");
    log.trace("Creating QueryImpl");
    QueryImpl settings = new QueryImpl();
    settings.setBeginDate(startDate);
    settings.setEndDate(endDate);
    settings.setPagesize(Integer.MAX_VALUE);
    settings.setQueryAuthorizations(auths.serialize());
    settings.setQuery(querystr);
    settings.setParameters(extraParms);
    settings.setId(UUID.randomUUID());
    log.debug("query: " + settings.getQuery());
    log.debug("logic: " + settings.getQueryLogicName());
    logic.setMaxEvaluationPipelines(1);
    logic.setMaxDepthThreshold(6);
    GenericQueryConfiguration config = logic.initialize(connector, settings, authSet);
    logic.setupQuery(config);
    HashSet<String> expectedSet = new HashSet<>(expected);
    HashSet<String> resultSet;
    resultSet = new HashSet<>();
    Set<Document> docs = new HashSet<>();
    for (Entry<Key, Value> entry : logic) {
        Document d = deserializer.apply(entry).getValue();
        log.debug(entry.getKey() + " => " + d);
        Attribute<?> attr = d.get("UUID.0");
        Assert.assertNotNull("Result Document did not contain a 'UUID'", attr);
        Assert.assertTrue("Expected result to be an instance of DatwawaveTypeAttribute, was: " + attr.getClass().getName(), attr instanceof TypeAttribute || attr instanceof PreNormalizedAttribute);
        TypeAttribute<?> UUIDAttr = (TypeAttribute<?>) attr;
        String UUID = UUIDAttr.getType().getDelegate().toString();
        Assert.assertTrue("Received unexpected UUID for query:" + querystr + "  " + UUID, expected.contains(UUID));
        resultSet.add(UUID);
        docs.add(d);
    }
    if (expected.size() > resultSet.size()) {
        expectedSet.addAll(expected);
        expectedSet.removeAll(resultSet);
        for (String s : expectedSet) {
            log.warn("Missing: " + s);
        }
    }
    if (!expected.containsAll(resultSet)) {
        log.error("Expected results " + expected + " differ form actual results " + resultSet);
    }
    Assert.assertTrue("Expected results " + expected + " differ form actual results " + resultSet, expected.containsAll(resultSet));
    Assert.assertEquals("Unexpected number of records for query:" + querystr, expected.size(), resultSet.size());
}
Also used : PreNormalizedAttribute(datawave.query.attributes.PreNormalizedAttribute) Document(datawave.query.attributes.Document) GenericQueryConfiguration(datawave.webservice.query.configuration.GenericQueryConfiguration) QueryImpl(datawave.webservice.query.QueryImpl) TypeAttribute(datawave.query.attributes.TypeAttribute) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet)

Example 12 with PreNormalizedAttribute

use of datawave.query.attributes.PreNormalizedAttribute in project datawave by NationalSecurityAgency.

the class IfThisTestFailsThenHitTermsAreBroken method runTestQuery.

protected void runTestQuery(List<String> expected, String querystr, Date startDate, Date endDate, Map<String, String> extraParms, Multimap<String, String> expectedHitTerms) throws Exception {
    log.debug("runTestQuery");
    log.trace("Creating QueryImpl");
    QueryImpl settings = new QueryImpl();
    settings.setBeginDate(startDate);
    settings.setEndDate(endDate);
    settings.setPagesize(Integer.MAX_VALUE);
    settings.setQueryAuthorizations(auths.serialize());
    settings.setQuery(querystr);
    settings.setParameters(extraParms);
    settings.setId(UUID.randomUUID());
    settings.setParameters(extraParms);
    log.debug("query: " + settings.getQuery());
    log.debug("logic: " + settings.getQueryLogicName());
    GenericQueryConfiguration config = logic.initialize(connector, settings, authSet);
    logic.setupQuery(config);
    HashSet<String> expectedSet = new HashSet<>(expected);
    HashSet<String> resultSet;
    resultSet = new HashSet<>();
    Set<Document> docs = new HashSet<>();
    for (Entry<Key, Value> entry : logic) {
        Document d = deserializer.apply(entry).getValue();
        log.debug(entry.getKey() + " => " + d);
        Attribute<?> attr = d.get("UUID.0");
        Assert.assertNotNull("Result Document did not contain a 'UUID'", attr);
        Assert.assertTrue("Expected result to be an instance of DatwawaveTypeAttribute, was: " + attr.getClass().getName(), attr instanceof TypeAttribute || attr instanceof PreNormalizedAttribute);
        TypeAttribute<?> uuidAttr = (TypeAttribute<?>) attr;
        String uuid = uuidAttr.getType().getDelegate().toString();
        Assert.assertTrue("Received unexpected UUID: " + uuid, expected.contains(uuid));
        Attribute<?> hitTermAttribute = d.get(JexlEvaluation.HIT_TERM_FIELD);
        if (hitTermAttribute instanceof Attributes) {
            Attributes hitTerms = (Attributes) hitTermAttribute;
            for (Attribute<?> hitTerm : hitTerms.getAttributes()) {
                log.debug("hitTerm:" + hitTerm);
                String hitString = hitTerm.getData().toString();
                log.debug("as string:" + hitString);
                log.debug("expectedHitTerms:" + expectedHitTerms);
                Assert.assertNotEquals(hitTerm.getTimestamp(), Long.MAX_VALUE);
                // make sure this hitString is in the map, and remove it
                boolean result = expectedHitTerms.get(uuid).remove(hitString);
                if (result == false) {
                    log.debug("failed to find hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms + " from hitTerms:" + hitTerms);
                    Assert.fail("failed to find hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms + " from hitTerms:" + hitTerms);
                } else {
                    log.debug("removed hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms + " from hitTerms:" + hitTerms);
                }
            }
        } else if (hitTermAttribute instanceof Attribute) {
            log.debug("hitTerm:" + (Attribute<?>) hitTermAttribute);
            String hitString = ((Attribute<?>) hitTermAttribute).getData().toString();
            log.debug("as string:" + hitString);
            log.debug("expectedHitTerms:" + expectedHitTerms);
            boolean result = expectedHitTerms.get(uuid).remove(hitString);
            if (result == false) {
                log.debug("failed to find hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms);
                Assert.fail("failed to find hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms);
            } else {
                log.debug("removed hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms + " from hitTerm:" + (Attribute<?>) hitTermAttribute);
            }
        }
        resultSet.add(uuid);
        docs.add(d);
    }
    if (expected.size() > resultSet.size()) {
        expectedSet.addAll(expected);
        expectedSet.removeAll(resultSet);
        for (String s : expectedSet) {
            log.warn("Missing: " + s);
        }
    }
    if (!expected.containsAll(resultSet)) {
        log.error("Expected results " + expected + " differ form actual results " + resultSet);
    }
    Assert.assertTrue("Expected results " + expected + " differ form actual results " + resultSet, expected.containsAll(resultSet));
    Assert.assertEquals("Unexpected number of records", expected.size(), resultSet.size());
    // the map is empty if there were no unexpected hit terms in it
    log.debug("expectedHitTerms:" + expectedHitTerms);
    Assert.assertTrue(expectedHitTerms.isEmpty());
}
Also used : Attribute(datawave.query.attributes.Attribute) TypeAttribute(datawave.query.attributes.TypeAttribute) PreNormalizedAttribute(datawave.query.attributes.PreNormalizedAttribute) Attributes(datawave.query.attributes.Attributes) PreNormalizedAttribute(datawave.query.attributes.PreNormalizedAttribute) Document(datawave.query.attributes.Document) GenericQueryConfiguration(datawave.webservice.query.configuration.GenericQueryConfiguration) QueryImpl(datawave.webservice.query.QueryImpl) TypeAttribute(datawave.query.attributes.TypeAttribute) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet)

Example 13 with PreNormalizedAttribute

use of datawave.query.attributes.PreNormalizedAttribute in project datawave by NationalSecurityAgency.

the class UseOccurrenceToCountInJexlContextTest method runTestQuery.

protected void runTestQuery(List<String> expected, String querystr, Date startDate, Date endDate, Map<String, String> extraParms, Multimap<String, String> expectedHitTerms, Connector connector) throws Exception {
    log.debug("runTestQuery");
    log.trace("Creating QueryImpl");
    QueryImpl settings = new QueryImpl();
    settings.setBeginDate(startDate);
    settings.setEndDate(endDate);
    settings.setPagesize(Integer.MAX_VALUE);
    settings.setQueryAuthorizations(auths.serialize());
    settings.setQuery(querystr);
    settings.setParameters(extraParms);
    settings.setId(UUID.randomUUID());
    settings.setParameters(Collections.singletonMap("hit.list", "true"));
    log.debug("query: " + settings.getQuery());
    log.debug("logic: " + settings.getQueryLogicName());
    GenericQueryConfiguration config = logic.initialize(connector, settings, authSet);
    logic.setupQuery(config);
    HashSet<String> expectedSet = new HashSet<>(expected);
    HashSet<String> resultSet;
    resultSet = new HashSet<>();
    Set<Document> docs = new HashSet<>();
    for (Entry<Key, Value> entry : logic) {
        Document d = deserializer.apply(entry).getValue();
        log.debug(entry.getKey() + " => " + d);
        Attribute<?> attr = d.get("UUID.0");
        Assert.assertNotNull("Result Document did not contain a 'UUID'", attr);
        Assert.assertTrue("Expected result to be an instance of DatwawaveTypeAttribute, was: " + attr.getClass().getName(), attr instanceof TypeAttribute || attr instanceof PreNormalizedAttribute);
        TypeAttribute<?> uuidAttr = (TypeAttribute<?>) attr;
        String uuid = uuidAttr.getType().getDelegate().toString();
        Assert.assertTrue("Received unexpected UUID: " + uuid, expected.contains(uuid));
        Attribute<?> hitTermAttribute = d.get(JexlEvaluation.HIT_TERM_FIELD);
        if (hitTermAttribute instanceof Attributes) {
            Attributes hitTerms = (Attributes) hitTermAttribute;
            for (Attribute<?> hitTerm : hitTerms.getAttributes()) {
                log.debug("hitTerm:" + hitTerm);
                String hitString = hitTerm.getData().toString();
                log.debug("as string:" + hitString);
                log.debug("expectedHitTerms:" + expectedHitTerms);
                // make sure this hitString is in the map, and remove it
                boolean result = expectedHitTerms.get(uuid).remove(hitString);
                if (result == false) {
                    log.debug("failed to find hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms + " from hitTerms:" + hitTerms);
                    Assert.fail("failed to find hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms + " from hitTerms:" + hitTerms);
                } else {
                    log.debug("removed hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms + " from hitTerms:" + hitTerms);
                }
            }
        } else if (hitTermAttribute instanceof Attribute) {
            log.debug("hitTerm:" + (Attribute<?>) hitTermAttribute);
            String hitString = ((Attribute<?>) hitTermAttribute).getData().toString();
            log.debug("as string:" + hitString);
            log.debug("expectedHitTerms:" + expectedHitTerms);
            boolean result = expectedHitTerms.get(uuid).remove(hitString);
            if (result == false) {
                log.debug("failed to find hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms);
                Assert.fail("failed to find hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms);
            } else {
                log.debug("removed hitString:" + hitString + " for uuid:" + uuid + " in expectedHitTerms:" + expectedHitTerms + " from hitTerm:" + (Attribute<?>) hitTermAttribute);
            }
        }
        resultSet.add(uuid);
        docs.add(d);
    }
    if (expected.size() > resultSet.size()) {
        expectedSet.addAll(expected);
        expectedSet.removeAll(resultSet);
        for (String s : expectedSet) {
            log.warn("Missing: " + s);
        }
    }
    if (!expected.containsAll(resultSet)) {
        log.error("Expected results " + expected + " differ form actual results " + resultSet);
    }
    Assert.assertTrue("Expected results " + expected + " differ form actual results " + resultSet, expected.containsAll(resultSet));
    Assert.assertEquals("Unexpected number of records", expected.size(), resultSet.size());
    // the map is empty if there were no unexpected hit terms in it
    log.debug("expectedHitTerms:" + expectedHitTerms);
    Assert.assertTrue(expectedHitTerms.isEmpty());
}
Also used : Attribute(datawave.query.attributes.Attribute) TypeAttribute(datawave.query.attributes.TypeAttribute) PreNormalizedAttribute(datawave.query.attributes.PreNormalizedAttribute) Attributes(datawave.query.attributes.Attributes) PreNormalizedAttribute(datawave.query.attributes.PreNormalizedAttribute) Document(datawave.query.attributes.Document) GenericQueryConfiguration(datawave.webservice.query.configuration.GenericQueryConfiguration) QueryImpl(datawave.webservice.query.QueryImpl) TypeAttribute(datawave.query.attributes.TypeAttribute) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet)

Aggregations

PreNormalizedAttribute (datawave.query.attributes.PreNormalizedAttribute)13 Document (datawave.query.attributes.Document)12 HashSet (java.util.HashSet)12 TypeAttribute (datawave.query.attributes.TypeAttribute)7 QueryImpl (datawave.webservice.query.QueryImpl)7 GenericQueryConfiguration (datawave.webservice.query.configuration.GenericQueryConfiguration)7 Key (org.apache.accumulo.core.data.Key)7 Value (org.apache.accumulo.core.data.Value)7 Set (java.util.Set)5 Range (org.apache.accumulo.core.data.Range)5 Test (org.junit.Test)5 TLDTermFrequencyAggregator (datawave.query.tld.TLDTermFrequencyAggregator)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Attribute (datawave.query.attributes.Attribute)2 Attributes (datawave.query.attributes.Attributes)2 EventDataQueryExpressionFilter (datawave.query.predicate.EventDataQueryExpressionFilter)2 ValueTuple (datawave.query.attributes.ValueTuple)1 TermFrequencyAggregator (datawave.query.jexl.functions.TermFrequencyAggregator)1 TLDEventDataFilter (datawave.query.predicate.TLDEventDataFilter)1