Search in sources :

Example 26 with QueryImpl

use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.

the class ExtendedEdgeQueryLogicTest method testSelectorExtractor.

@Test
public void testSelectorExtractor() throws Exception {
    QueryImpl q = configQuery("MARS,JUPITER,VENUS", auths);
    q.addParameter("delimiter", ",");
    q.addParameter("query.syntax", "LIST");
    List<String> expected = new ArrayList();
    expected.add("MARS");
    expected.add("JUPITER");
    expected.add("VENUS");
    List<String> sources = logic.getSelectors(q);
    Assert.assertTrue(sources.containsAll(expected));
    q = configQuery("SOURCE == 'MARS' OR SOURCE == 'JUPITER' OR SOURCE == 'VENUS'", auths);
    q.addParameter("query.syntax", "JEXL");
    sources = logic.getSelectors(q);
    Assert.assertTrue(sources.containsAll(expected));
}
Also used : QueryImpl(datawave.webservice.query.QueryImpl) ArrayList(java.util.ArrayList) Test(org.junit.Test) EdgeQueryFunctionalTest(datawave.query.tables.edge.EdgeQueryFunctionalTest)

Example 27 with QueryImpl

use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.

the class ExtendedEdgeQueryLogicTest method testEdgeQuerySyntax_WithQueryModel.

@Test
public void testEdgeQuerySyntax_WithQueryModel() throws Exception {
    QueryImpl q = configQuery("(VERTEXA =~ 'M.*') && (VERTEXB == 'JUPITER') && (RELATION == 'FROM-TO' || RELATION == 'TO-FROM')", auths);
    q.addParameter("stats", "true");
    DefaultExtendedEdgeQueryLogic logic = runLogic(q, auths);
    List<String> expected = new ArrayList<>();
    expected.add("mars%00;jupiter AdjacentPlanets/FROM-TO:20150713/COSMOS_DATA-COSMOS_DATA [A]");
    expected.add("mars STATS/ACTIVITY/Planets/TO:20150713/COSMOS_DATA [B]");
    expected.add("mercury STATS/ACTIVITY/Planets/TO:20150713/COSMOS_DATA [B]");
    compareResults(logic, expected);
}
Also used : QueryImpl(datawave.webservice.query.QueryImpl) ArrayList(java.util.ArrayList) Test(org.junit.Test) EdgeQueryFunctionalTest(datawave.query.tables.edge.EdgeQueryFunctionalTest)

Example 28 with QueryImpl

use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.

the class ExtendedEdgeQueryLogicTest method testEdgeSummaryQuerySyntax.

@Test
public void testEdgeSummaryQuerySyntax() throws Exception {
    QueryImpl q = configQuery("mars", auths);
    q.addParameter("stats", "true");
    q.addParameter("query.syntax", "LIST");
    DefaultExtendedEdgeQueryLogic logic = runLogic(q, auths);
    List<String> expected = new ArrayList<>();
    expected.add("mars%00;earth AdjacentPlanets/TO-FROM:20150713/COSMOS_DATA-COSMOS_DATA [A]");
    expected.add("mars%00;jupiter AdjacentPlanets/FROM-TO:20150713/COSMOS_DATA-COSMOS_DATA [A]");
    expected.add("mars%00;asteroid_belt AdjacentCelestialBodies/TO-FROM:20150713/COSMOS_DATA-COSMOS_DATA [A]");
    expected.add("mars%00;ceres AdjacentCelestialBodies/FROM-TO:20150713/COSMOS_DATA-COSMOS_DATA [B]");
    expected.add("mars%00;ceres AdjacentDwarfPlanets/TO-FROM:20150713/COSMOS_DATA-COSMOS_DATA [B]");
    expected.add("mars STATS/ACTIVITY/Planets/TO:20150713/COSMOS_DATA [B]");
    compareResults(logic, expected);
}
Also used : QueryImpl(datawave.webservice.query.QueryImpl) ArrayList(java.util.ArrayList) Test(org.junit.Test) EdgeQueryFunctionalTest(datawave.query.tables.edge.EdgeQueryFunctionalTest)

Example 29 with QueryImpl

use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.

the class ValueToAttributesTest 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());
    GenericQueryConfiguration config = logic.initialize(connector, settings, authSet);
    logic.setupQuery(config);
    String plannedScript = logic.getQueryPlanner().getPlannedScript();
    Assert.assertTrue("CompositeTerm was not substituted into query:" + plannedScript, plannedScript.contains("MAKE_COLOR"));
    HashSet<String> expectedSet = new HashSet<>(expected);
    HashSet<String> resultSet;
    resultSet = new HashSet<>();
    Set<Document> docs = new HashSet<>();
    for (Map.Entry<Key, Value> entry : logic) {
        Document d = deserializer.apply(entry).getValue();
        log.trace(entry.getKey() + " => " + d);
        Attribute<?> attr = d.get("UUID");
        if (attr == null)
            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));
        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());
}
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) Map(java.util.Map) HashMap(java.util.HashMap) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet)

Example 30 with QueryImpl

use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.

the class BaseEdgeQueryTest method configQuery.

public QueryImpl configQuery(String query, Set<Authorizations> auths) throws ParseException {
    Date startDate = simpleFormat.parse("20140701");
    Date endDate = simpleFormat.parse("20150730");
    Map<String, String> extraParams = new HashMap<>();
    QueryImpl q = new QueryImpl();
    q.setBeginDate(startDate);
    q.setEndDate(endDate);
    q.setQuery(query);
    q.setParameters(extraParams);
    q.setId(UUID.randomUUID());
    q.setPagesize(Integer.MAX_VALUE);
    q.setQueryAuthorizations(serializeAuths(auths));
    q.addParameter("model.name", "something");
    return q;
}
Also used : QueryImpl(datawave.webservice.query.QueryImpl) HashMap(java.util.HashMap) Date(java.util.Date)

Aggregations

QueryImpl (datawave.webservice.query.QueryImpl)131 Test (org.junit.Test)96 ArrayList (java.util.ArrayList)54 Query (datawave.webservice.query.Query)40 HashSet (java.util.HashSet)27 BaseQueryLogic (datawave.webservice.query.logic.BaseQueryLogic)18 GenericQueryConfiguration (datawave.webservice.query.configuration.GenericQueryConfiguration)16 Date (java.util.Date)16 QueryParametersImpl (datawave.webservice.query.QueryParametersImpl)14 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)13 QueryMetricFactoryImpl (datawave.microservice.querymetric.QueryMetricFactoryImpl)12 QueryParameters (datawave.webservice.query.QueryParameters)12 Value (org.apache.accumulo.core.data.Value)10 Document (datawave.query.attributes.Document)9 ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)9 EdgeQueryFunctionalTest (datawave.query.tables.edge.EdgeQueryFunctionalTest)9 QueryLogic (datawave.webservice.query.logic.QueryLogic)9 HashMap (java.util.HashMap)9 Key (org.apache.accumulo.core.data.Key)9 Authorizations (org.apache.accumulo.core.security.Authorizations)9