Search in sources :

Example 1 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.

the class QueryPlanTest method verifyQueryStringUpdatesWithQueryTree.

@Test
public void verifyQueryStringUpdatesWithQueryTree() throws ParseException {
    ShardQueryConfiguration config = new ShardQueryConfiguration();
    config.setQueryString("1");
    assertEquals("1", config.getQueryString());
    config.setQueryTree(JexlASTHelper.parseAndFlattenJexlQuery("A == B"));
    assertEquals("A == B", config.getQueryString());
    config.setQueryTree(JexlASTHelper.parseAndFlattenJexlQuery("B == B"));
    assertEquals("B == B", config.getQueryString());
}
Also used : ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) Test(org.junit.Test)

Example 2 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.

the class ShardQueryLogic method setupQuery.

@Override
public void setupQuery(GenericQueryConfiguration genericConfig) throws Exception {
    if (!ShardQueryConfiguration.class.isAssignableFrom(genericConfig.getClass())) {
        throw new QueryException("Did not receive a ShardQueryConfiguration instance!!");
    }
    ShardQueryConfiguration config = (ShardQueryConfiguration) genericConfig;
    final QueryStopwatch timers = config.getTimers();
    TraceStopwatch stopwatch = timers.newStartedStopwatch("ShardQueryLogic - Setup Query");
    // Ensure we have all of the information needed to run a query
    if (!config.canRunQuery()) {
        log.warn("The given query '" + config + "' could not be run, most likely due to not matching any records in the global index.");
        // Stub out an iterator to correctly present "no results"
        this.iterator = new Iterator<Map.Entry<Key, Value>>() {

            @Override
            public boolean hasNext() {
                return false;
            }

            @Override
            public Map.Entry<Key, Value> next() {
                return null;
            }

            @Override
            public void remove() {
                return;
            }
        };
        this.scanner = null;
        stopwatch.stop();
        log.info(getStopwatchHeader(config));
        List<String> timings = timers.summarizeAsList();
        for (String timing : timings) {
            log.info(timing);
        }
        return;
    }
    // Instantiate the scheduler for the queries
    this.scheduler = getScheduler(config, scannerFactory);
    this.scanner = null;
    this.iterator = this.scheduler.iterator();
    if (!config.isSortedUIDs()) {
        this.iterator = new DedupingIterator(this.iterator);
    }
    stopwatch.stop();
    log.info(getStopwatchHeader(config));
    List<String> timings = timers.summarizeAsList();
    for (String timing : timings) {
        log.info(timing);
    }
}
Also used : QueryException(datawave.webservice.query.exception.QueryException) Entry(java.util.Map.Entry) TraceStopwatch(datawave.util.time.TraceStopwatch) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) QueryStopwatch(datawave.query.util.QueryStopwatch)

Example 3 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.

the class DefaultQueryPlanner method initializeRangeStream.

/**
 * Initializes the range stream, whether it is configured to be a different class than the Default Range stream or not.
 *
 * @param config
 * @param scannerFactory
 * @param metadataHelper
 * @return
 */
private RangeStream initializeRangeStream(ShardQueryConfiguration config, ScannerFactory scannerFactory, MetadataHelper metadataHelper) {
    Class<? extends RangeStream> rstream;
    try {
        rstream = Class.forName(rangeStreamClass).asSubclass(RangeStream.class);
        RangeStream stream = rstream.getConstructor(ShardQueryConfiguration.class, ScannerFactory.class, MetadataHelper.class).newInstance(config, scannerFactory, metadataHelper);
        return stream.setUidIntersector(uidIntersector).setLimitScanners(limitScanners).setCreateUidsIteratorClass(createUidsIteratorClass);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new RuntimeException(e);
    }
}
Also used : AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ScannerFactory(datawave.query.tables.ScannerFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) MetadataHelper(datawave.query.util.MetadataHelper) RangeStream(datawave.query.index.lookup.RangeStream) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration)

Example 4 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.

the class DefaultQueryPlanner method process.

@Override
public CloseableIterable<QueryData> process(GenericQueryConfiguration genericConfig, String query, Query settings, ScannerFactory scannerFactory) throws DatawaveQueryException {
    if (!(genericConfig instanceof ShardQueryConfiguration)) {
        throw new ClassCastException("Config object must be an instance of ShardQueryConfiguration");
    }
    builderThread = Executors.newSingleThreadExecutor();
    ShardQueryConfiguration config = (ShardQueryConfiguration) genericConfig;
    // lets mark the query as started (used by ivarators at a minimum)
    try {
        markQueryStarted(config, settings);
    } catch (Exception e) {
        throw new DatawaveQueryException("Failed to mark query as started" + settings.getId(), e);
    }
    return process(scannerFactory, getMetadataHelper(config), getDateIndexHelper(config), config, query, settings);
}
Also used : DatawaveQueryException(datawave.query.exceptions.DatawaveQueryException) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) DatawaveQueryException(datawave.query.exceptions.DatawaveQueryException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DoNotPerformOptimizedQueryException(datawave.query.exceptions.DoNotPerformOptimizedQueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) ParseException(org.apache.commons.jexl2.parser.ParseException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) QueryException(datawave.webservice.query.exception.QueryException) InvalidQueryException(datawave.query.exceptions.InvalidQueryException) FullTableScansDisallowedException(datawave.query.exceptions.FullTableScansDisallowedException) PatternSyntaxException(java.util.regex.PatternSyntaxException) CannotExpandUnfieldedTermFatalException(datawave.query.exceptions.CannotExpandUnfieldedTermFatalException) NoResultsException(datawave.query.exceptions.NoResultsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) EmptyUnfieldedTermExpansionException(datawave.query.exceptions.EmptyUnfieldedTermExpansionException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 5 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.

the class CompositeIndexTest method getQueryRangesIterator.

private Iterator getQueryRangesIterator(String queryString, ShardQueryLogic logic) throws Exception {
    MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
    params.putSingle(QUERY_STRING, queryString);
    params.putSingle(QUERY_NAME, "geoQuery");
    params.putSingle(QUERY_LOGIC_NAME, "EventQueryLogic");
    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 config.getQueries();
}
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)

Aggregations

ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)108 Test (org.junit.Test)75 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)48 HashSet (java.util.HashSet)42 Date (java.util.Date)38 GeometryType (datawave.data.type.GeometryType)17 MetadataHelper (datawave.query.util.MetadataHelper)17 HashMap (java.util.HashMap)16 CompositeFunctionsTest (datawave.query.CompositeFunctionsTest)13 Query (datawave.webservice.query.Query)10 Authorizations (org.apache.accumulo.core.security.Authorizations)10 Before (org.junit.Before)10 QueryImpl (datawave.webservice.query.QueryImpl)9 QueryParameters (datawave.webservice.query.QueryParameters)9 QueryParametersImpl (datawave.webservice.query.QueryParametersImpl)9 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)8 MockMetadataHelper (datawave.query.util.MockMetadataHelper)7 JexlNode (org.apache.commons.jexl2.parser.JexlNode)6 ExceededOrThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode)5 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)5