Search in sources :

Example 26 with TraceStopwatch

use of datawave.util.time.TraceStopwatch in project datawave by NationalSecurityAgency.

the class DefaultQueryPlanner method timedAddDelayedPredicates.

protected ASTJexlScript timedAddDelayedPredicates(QueryStopwatch timers, String stage, final ASTJexlScript script, ShardQueryConfiguration config, MetadataHelper metadataHelper, Set<String> indexedFields, Set<String> indexOnlyFields, Set<String> nonEventFields, List<String> debugOutput) {
    TraceStopwatch stopwatch = timers.newStartedStopwatch("DefaultQueryPlanner - " + stage);
    config.setQueryTree(script);
    if (log.isDebugEnabled()) {
        debugOutput.clear();
    }
    if (!ExecutableDeterminationVisitor.isExecutable(config.getQueryTree(), config, indexedFields, indexOnlyFields, nonEventFields, debugOutput, metadataHelper)) {
        config.setQueryTree((ASTJexlScript) PushdownUnexecutableNodesVisitor.pushdownPredicates(config.getQueryTree(), false, config, indexedFields, indexOnlyFields, nonEventFields, metadataHelper));
        if (log.isDebugEnabled()) {
            logDebug(debugOutput, "Executable state after expanding ranges and regex again:");
            logQuery(config.getQueryTree(), "Query after partially executable pushdown:");
        }
    }
    stopwatch.stop();
    return config.getQueryTree();
}
Also used : TraceStopwatch(datawave.util.time.TraceStopwatch)

Example 27 with TraceStopwatch

use of datawave.util.time.TraceStopwatch in project datawave by NationalSecurityAgency.

the class DefaultQueryPlanner method timedRemoveDelayedPredicates.

protected ASTJexlScript timedRemoveDelayedPredicates(QueryStopwatch timers, String stage, ASTJexlScript script, ShardQueryConfiguration config, MetadataHelper metadataHelper, Set<String> indexedFields, Set<String> indexOnlyFields, Set<String> nonEventFields, Map<String, IndexLookup> indexLookupMap, ScannerFactory scannerFactory, MetadataHelper helper, List<String> debugOutput) throws TableNotFoundException {
    TraceStopwatch stopwatch = timers.newStartedStopwatch("DefaultQueryPlanner - " + stage);
    config.setQueryTree((ASTJexlScript) PullupUnexecutableNodesVisitor.pullupDelayedPredicates(config.getQueryTree(), false, config, indexedFields, indexOnlyFields, nonEventFields, metadataHelper));
    if (log.isDebugEnabled()) {
        logDebug(debugOutput, "Executable state after expanding ranges:");
        logQuery(config.getQueryTree(), "Query after delayed pullup:");
    }
    boolean expandAllTerms = config.isExpandAllTerms();
    // set the expand all terms flag to avoid any more delayed
    // predicates based on cost...
    config.setExpandAllTerms(true);
    // Check if there is any regex to expand after pulling up delayed predicates.
    NodeTypeCount nodeCount = NodeTypeCountVisitor.countNodes(config.getQueryTree());
    if (nodeCount.hasAny(ASTNRNode.class, ASTERNode.class)) {
        config.setQueryTree(RegexIndexExpansionVisitor.expandRegex(config, scannerFactory, helper, indexLookupMap, config.getQueryTree()));
        if (log.isDebugEnabled()) {
            logQuery(config.getQueryTree(), "Query after expanding regex again:");
        }
    }
    // Check if there are any bounded ranges to expand.
    if (nodeCount.isPresent(BoundedRange.class)) {
        try {
            config.setQueryTree(BoundedRangeIndexExpansionVisitor.expandBoundedRanges(config, scannerFactory, metadataHelper, config.getQueryTree()));
        } catch (TableNotFoundException e) {
            QueryException qe = new QueryException(DatawaveErrorCode.METADATA_ACCESS_ERROR, e);
            throw new DatawaveFatalQueryException(qe);
        }
        if (log.isDebugEnabled()) {
            logQuery(config.getQueryTree(), "Query after expanding ranges again:");
        }
    }
    if (reduceQuery) {
        // only show pruned sections of the tree's via assignments if debug to reduce runtime when possible
        config.setQueryTree((ASTJexlScript) QueryPruningVisitor.reduce(config.getQueryTree(), showReducedQueryPrune));
        if (log.isDebugEnabled()) {
            logQuery(config.getQueryTree(), "Query after range expansion reduction again:");
        }
    }
    // Check if there are functions that can be pushed into exceeded value ranges.
    if (nodeCount.hasAll(ASTFunctionNode.class, ExceededValueThresholdMarkerJexlNode.class)) {
        config.setQueryTree(PushFunctionsIntoExceededValueRanges.pushFunctions(config.getQueryTree(), metadataHelper, config.getDatatypeFilter()));
        if (log.isDebugEnabled()) {
            logQuery(config.getQueryTree(), "Query after expanding pushing functions into exceeded value ranges again:");
        }
    }
    // Reset the original expandAllTerms value.
    config.setExpandAllTerms(expandAllTerms);
    stopwatch.stop();
    return config.getQueryTree();
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) DatawaveQueryException(datawave.query.exceptions.DatawaveQueryException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) DoNotPerformOptimizedQueryException(datawave.query.exceptions.DoNotPerformOptimizedQueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) QueryException(datawave.webservice.query.exception.QueryException) InvalidQueryException(datawave.query.exceptions.InvalidQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) TraceStopwatch(datawave.util.time.TraceStopwatch) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) NodeTypeCount(datawave.query.jexl.NodeTypeCount)

Example 28 with TraceStopwatch

use of datawave.util.time.TraceStopwatch in project datawave by NationalSecurityAgency.

the class DefaultQueryPlanner method timedFetchDatatypes.

protected void timedFetchDatatypes(QueryStopwatch timers, String stage, final ASTJexlScript script, ShardQueryConfiguration config) throws DatawaveQueryException {
    TraceStopwatch stopwatch = timers.newStartedStopwatch("DefaultQueryPlanner - " + stage);
    try {
        Multimap<String, Type<?>> fieldToDatatypeMap = null;
        if (cacheDataTypes) {
            fieldToDatatypeMap = dataTypeMap.getIfPresent(String.valueOf(config.getDatatypeFilter().hashCode()));
        }
        if (null != fieldToDatatypeMap) {
            Set<String> indexedFields = Sets.newHashSet();
            Set<String> reverseIndexedFields = Sets.newHashSet();
            Set<String> normalizedFields = Sets.newHashSet();
            loadDataTypeMetadata(fieldToDatatypeMap, indexedFields, reverseIndexedFields, normalizedFields, false);
            if (null == queryFieldsAsDataTypeMap) {
                queryFieldsAsDataTypeMap = HashMultimap.create(Multimaps.filterKeys(fieldToDatatypeMap, input -> !cachedNormalizedFields.contains(input)));
            }
            if (null == normalizedFieldAsDataTypeMap) {
                normalizedFieldAsDataTypeMap = HashMultimap.create(Multimaps.filterKeys(fieldToDatatypeMap, input -> cachedNormalizedFields.contains(input)));
            }
            setCachedFields(indexedFields, reverseIndexedFields, queryFieldsAsDataTypeMap, normalizedFieldAsDataTypeMap, config);
        } else {
            fieldToDatatypeMap = configureIndexedAndNormalizedFields(metadataHelper, config, script);
            if (cacheDataTypes) {
                loadDataTypeMetadata(null, null, null, null, true);
                dataTypeMap.put(String.valueOf(config.getDatatypeFilter().hashCode()), metadataHelper.getFieldsToDatatypes(config.getDatatypeFilter()));
            }
        }
    } catch (InstantiationException | IllegalAccessException | AccumuloException | AccumuloSecurityException | TableNotFoundException | ExecutionException e) {
        throw new DatawaveFatalQueryException(e);
    } finally {
        stopwatch.stop();
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AbstractGeometryType(datawave.data.type.AbstractGeometryType) Type(datawave.data.type.Type) TraceStopwatch(datawave.util.time.TraceStopwatch) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ExecutionException(java.util.concurrent.ExecutionException)

Example 29 with TraceStopwatch

use of datawave.util.time.TraceStopwatch in project datawave by NationalSecurityAgency.

the class TimedVisitorManager method timedVisit.

/**
 * Wrap visitor execution with a timer and debug msg
 *
 * @param timers
 *            a {@link QueryStopwatch}
 * @param stageName
 *            the name for this operation, for example "Fix Not Null Intent" or "Expand Regex Nodes"
 * @param visitorManager
 *            an interface that allows us to pass a lambda operation {@link VisitorManager}
 * @return the query tree, a {@link ASTJexlScript}
 * @throws DatawaveQueryException
 *             if something goes wrong
 */
public ASTJexlScript timedVisit(QueryStopwatch timers, String stageName, VisitorManager visitorManager) throws DatawaveQueryException {
    ASTJexlScript script;
    TraceStopwatch stopwatch = timers.newStartedStopwatch("DefaultQueryPlanner - " + stageName);
    try {
        script = visitorManager.apply();
        if (isDebugEnabled) {
            logQuery(script, "Query after visit: " + stageName);
        }
        if (validateAst) {
            try {
                ASTValidator.isValid(script, stageName);
            } catch (InvalidQueryTreeException e) {
                throw new DatawaveQueryException(e);
            }
        }
    } finally {
        stopwatch.stop();
    }
    return script;
}
Also used : InvalidQueryTreeException(datawave.query.exceptions.InvalidQueryTreeException) DatawaveQueryException(datawave.query.exceptions.DatawaveQueryException) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) TraceStopwatch(datawave.util.time.TraceStopwatch)

Aggregations

TraceStopwatch (datawave.util.time.TraceStopwatch)29 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)10 DatawaveQueryException (datawave.query.exceptions.DatawaveQueryException)10 QueryException (datawave.webservice.query.exception.QueryException)9 InvalidQueryException (datawave.query.exceptions.InvalidQueryException)8 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)8 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)8 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)8 DoNotPerformOptimizedQueryException (datawave.query.exceptions.DoNotPerformOptimizedQueryException)7 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)7 QueryStopwatch (datawave.query.util.QueryStopwatch)5 FullTableScansDisallowedException (datawave.query.exceptions.FullTableScansDisallowedException)3 HashSet (java.util.HashSet)3 AbstractGeometryType (datawave.data.type.AbstractGeometryType)2 Type (datawave.data.type.Type)2 ExtendedDataTypeHandler (datawave.ingest.mapreduce.handler.ExtendedDataTypeHandler)2 CannotExpandUnfieldedTermFatalException (datawave.query.exceptions.CannotExpandUnfieldedTermFatalException)2 NoResultsException (datawave.query.exceptions.NoResultsException)2 NodeTypeCount (datawave.query.jexl.NodeTypeCount)2 ArrayList (java.util.ArrayList)2