Search in sources :

Example 61 with QueryImpl

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

the class ExceededOrThresholdMarkerJexlNodeTest method getResultsIterator.

private Iterator getResultsIterator(String queryString, ShardQueryLogic logic) throws Exception {
    MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
    params.putSingle(QUERY_LOGIC_NAME, "EventQuery");
    params.putSingle(QUERY_STRING, queryString);
    params.putSingle(QUERY_NAME, "geoQuery");
    params.putSingle(QUERY_PERSISTENCE, "PERSISTENT");
    params.putSingle(QUERY_AUTHORIZATIONS, AUTHS);
    params.putSingle(QUERY_EXPIRATION, "20200101 000000.000");
    params.putSingle(QUERY_BEGIN, BEGIN_DATE);
    params.putSingle(QUERY_END, END_DATE);
    QueryParameters queryParams = new QueryParametersImpl();
    queryParams.validate(params);
    Set<Authorizations> auths = new HashSet<>();
    auths.add(new Authorizations(AUTHS));
    Query query = new QueryImpl();
    query.initialize(USER, Arrays.asList(USER_DN), null, queryParams, null);
    ShardQueryConfiguration config = ShardQueryConfiguration.create(logic, query);
    logic.initialize(config, instance.getConnector("root", PASSWORD), query, auths);
    logic.setupQuery(config);
    return logic.getTransformIterator(query);
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) QueryImpl(datawave.webservice.query.QueryImpl) Query(datawave.webservice.query.Query) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) QueryParameters(datawave.webservice.query.QueryParameters) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) HashSet(java.util.HashSet)

Example 62 with QueryImpl

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

the class AbstractFunctionalQuery method getPlan.

/**
 * Used by test cases that verify the plan
 *
 * @param queryStr
 *            query string for evaluation
 * @param expandFields
 *            whether to use the index for anyfield expansion
 * @param expandValues
 *            whether to use the index for regex/range expansion
 * @return query configuration
 * @throws Exception
 *             error condition from query initialization
 */
protected String getPlan(final String queryStr, boolean expandFields, boolean expandValues) throws Exception {
    Date[] startEndDate = this.dataManager.getShardStartEndDate();
    if (log.isDebugEnabled()) {
        log.debug("  query[" + queryStr + "]  start(" + YMD_DateFormat.format(startEndDate[0]) + ")  end(" + YMD_DateFormat.format(startEndDate[1]) + ")");
    }
    QueryImpl q = new QueryImpl();
    q.setBeginDate(startEndDate[0]);
    q.setEndDate(startEndDate[1]);
    q.setQuery(queryStr);
    q.setId(UUID.randomUUID());
    q.setPagesize(Integer.MAX_VALUE);
    q.setQueryAuthorizations(auths.toString());
    return this.logic.getPlan(connector, q, this.authSet, expandFields, expandValues);
}
Also used : QueryImpl(datawave.webservice.query.QueryImpl) Date(java.util.Date)

Example 63 with QueryImpl

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

the class AbstractFunctionalQuery method runCountTest.

/**
 * Executes test cases that use {@link CountingShardQueryLogic}.
 *
 * @param query
 *            query for evaluation
 * @throws Exception
 *             error condition during execution of query
 */
protected void runCountTest(String query) throws Exception {
    Date[] startEndDate = this.dataManager.getShardStartEndDate();
    if (log.isDebugEnabled()) {
        log.debug("  count query[" + query + "]  start(" + YMD_DateFormat.format(startEndDate[0]) + ")  end(" + YMD_DateFormat.format(startEndDate[1]) + ")");
    }
    QueryImpl q = new QueryImpl();
    q.setBeginDate(startEndDate[0]);
    q.setEndDate(startEndDate[1]);
    q.setQuery(query);
    q.setId(UUID.randomUUID());
    q.setPagesize(Integer.MAX_VALUE);
    q.setQueryAuthorizations(auths.toString());
    RunningQuery runner = new RunningQuery(connector, AccumuloConnectionFactory.Priority.NORMAL, this.countLogic, q, "", principal, new QueryMetricFactoryImpl());
    TransformIterator it = runner.getTransformIterator();
    ShardQueryCountTableTransformer ctt = (ShardQueryCountTableTransformer) it.getTransformer();
    EventQueryResponseBase resp = (EventQueryResponseBase) ctt.createResponse(runner.next());
    Collection<String> expect = getExpectedKeyResponse(query);
    List<EventBase> events = resp.getEvents();
    Assert.assertEquals(1, events.size());
    EventBase<?, ?> event = events.get(0);
    List<?> fields = event.getFields();
    Assert.assertEquals(1, fields.size());
    FieldBase<?> count = (FieldBase) fields.get(0);
    String val = count.getValueString();
    if (log.isDebugEnabled()) {
        log.debug("expected count(" + expect.size() + ") actual count(" + val + ")");
    }
    Assert.assertEquals("" + expect.size(), val);
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) TransformIterator(org.apache.commons.collections4.iterators.TransformIterator) ShardQueryCountTableTransformer(datawave.query.transformer.ShardQueryCountTableTransformer) Date(java.util.Date) EventQueryResponseBase(datawave.webservice.result.EventQueryResponseBase) QueryImpl(datawave.webservice.query.QueryImpl) RunningQuery(datawave.webservice.query.runner.RunningQuery) FieldBase(datawave.webservice.query.result.event.FieldBase) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl)

Example 64 with QueryImpl

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

the class AbstractFunctionalQuery method setupConfig.

/**
 * Used by test cases that verify the configuration.
 *
 * @param queryStr
 *            query string for evaluation
 * @return query configuration
 * @throws Exception
 *             error condition from query initialization
 */
protected GenericQueryConfiguration setupConfig(final String queryStr) throws Exception {
    Date[] startEndDate = this.dataManager.getShardStartEndDate();
    if (log.isDebugEnabled()) {
        log.debug("  query[" + queryStr + "]  start(" + YMD_DateFormat.format(startEndDate[0]) + ")  end(" + YMD_DateFormat.format(startEndDate[1]) + ")");
    }
    QueryImpl q = new QueryImpl();
    q.setBeginDate(startEndDate[0]);
    q.setEndDate(startEndDate[1]);
    q.setQuery(queryStr);
    q.setId(UUID.randomUUID());
    q.setPagesize(Integer.MAX_VALUE);
    q.setQueryAuthorizations(auths.toString());
    return this.logic.initialize(connector, q, this.authSet);
}
Also used : QueryImpl(datawave.webservice.query.QueryImpl) Date(java.util.Date)

Example 65 with QueryImpl

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

the class DefaultEdgeEventQueryLogicTest method testEdgesWithComplexPreconditions.

@Test
public void testEdgesWithComplexPreconditions() throws Exception {
    Query query = new QueryImpl();
    query.setQuery("SOURCE == '$609_1_R' AND SINK == '$604_1_R' AND TYPE == 'TEST11' AND RELATION == 'REL42-REL42'");
    String transformed = logic.getEventQuery(query);
    assertEquals("($609_1_R == '$609_1_R' AND $604_1_R == '$604_1_R' AND F05_3_R == 'enrichValue' AND ($609_3 == '2384' && $600_7 == '2'))", transformed);
}
Also used : QueryImpl(datawave.webservice.query.QueryImpl) Query(datawave.webservice.query.Query) Test(org.junit.Test)

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