Search in sources :

Example 1 with CannotExpandUnfieldedTermFatalException

use of datawave.query.exceptions.CannotExpandUnfieldedTermFatalException in project datawave by NationalSecurityAgency.

the class DefaultQueryPlanner method processTree.

protected ASTJexlScript processTree(final ASTJexlScript originalQueryTree, ShardQueryConfiguration config, Query settings, MetadataHelper metadataHelper, ScannerFactory scannerFactory, QueryData queryData, QueryStopwatch timers, QueryModel queryModel) throws DatawaveQueryException {
    config.setQueryTree(originalQueryTree);
    TraceStopwatch stopwatch = null;
    if (!disableWhindexFieldMappings) {
        // apply the value-specific field mappings for GeoWave functions
        config.setQueryTree(timedApplyWhindexFieldMappings(timers, config.getQueryTree(), config, metadataHelper, settings));
    }
    if (!disableExpandIndexFunction) {
        // expand the index queries for the functions
        config.setQueryTree(timedExpandIndexQueriesForFunctions(timers, config.getQueryTree(), config, metadataHelper));
    }
    // apply the node transform rules
    // running it here before any unfielded expansions to enable potentially pushing down terms before index lookups
    config.setQueryTree(timedApplyNodeTransformRules(timers, "Apply Node Transform Rules - Pre Unfielded Expansions", config.getQueryTree(), config, metadataHelper, getTransformRules()));
    // left as a regex
    if (!disableAnyFieldLookup) {
        config.setQueryTree(timedExpandAnyFieldRegexNodes(timers, config.getQueryTree(), config, metadataHelper, scannerFactory, settings.getQuery()));
    }
    if (reduceQuery) {
        config.setQueryTree(timedReduce(timers, "Reduce Query After ANYFIELD Expansions", config.getQueryTree()));
    }
    if (!disableTestNonExistentFields) {
        timedTestForNonExistentFields(timers, config.getQueryTree(), config, metadataHelper, queryModel, settings);
    }
    // apply the node transform rules
    // running it here before any regex or range expansions to enable potentially pushing down terms before index lookups
    config.setQueryTree(timedApplyNodeTransformRules(timers, "Apply Node Transform Rules - Pre Regex/Range Expansions", config.getQueryTree(), config, metadataHelper, getTransformRules()));
    timedFetchDatatypes(timers, "Fetch Required Datatypes", config.getQueryTree(), config);
    config.setQueryTree(timedFixUnindexedNumerics(timers, config.getQueryTree(), config));
    config.setQueryTree(timedExpandMultiNormalizedTerms(timers, config.getQueryTree(), config, metadataHelper));
    // if we have any index holes, then mark em
    if (!config.getIndexHoles().isEmpty()) {
        config.setQueryTree(timedMarkIndexHoles(timers, config.getQueryTree(), config, metadataHelper));
    }
    // lets precompute the indexed fields and index only fields for the specific datatype if needed below
    Set<String> indexedFields = null;
    Set<String> indexOnlyFields = null;
    Set<String> nonEventFields = null;
    if (config.getMinSelectivity() > 0 || !disableBoundedLookup) {
        try {
            indexedFields = metadataHelper.getIndexedFields(config.getDatatypeFilter());
            indexOnlyFields = metadataHelper.getIndexOnlyFields(config.getDatatypeFilter());
            nonEventFields = metadataHelper.getNonEventFields(config.getDatatypeFilter());
        } catch (TableNotFoundException te) {
            QueryException qe = new QueryException(DatawaveErrorCode.METADATA_ACCESS_ERROR, te);
            throw new DatawaveFatalQueryException(qe);
        }
    }
    // apply the node transform rules
    config.setQueryTree(timedApplyNodeTransformRules(timers, "Apply Node Transform Rules - Pre Pushdown/Pullup Expansions", config.getQueryTree(), config, metadataHelper, getTransformRules()));
    // push down terms that are over the min selectivity
    if (config.getMinSelectivity() > 0) {
        config.setQueryTree(timedPushdownLowSelectiveTerms(timers, config.getQueryTree(), config, indexedFields, indexOnlyFields, nonEventFields));
    }
    config.setQueryTree(timedForceFieldToFieldComparison(timers, config.getQueryTree()));
    if (!disableCompositeFields) {
        config.setQueryTree(timedExpandCompositeFields(timers, config.getQueryTree(), config));
    }
    if (!disableBoundedLookup) {
        stopwatch = timers.newStartedStopwatch("DefaultQueryPlanner - Expand bounded query ranges (total)");
        // Expand any bounded ranges into a conjunction of discrete terms
        try {
            Map<String, IndexLookup> indexLookupMap = new HashMap<>();
            // Check if there is any regex to expand.
            NodeTypeCount nodeCount = NodeTypeCountVisitor.countNodes(config.getQueryTree());
            if (nodeCount.hasAny(ASTNRNode.class, ASTERNode.class)) {
                config.setQueryTree(timedExpandRegex(timers, "Expand Regex", config.getQueryTree(), config, metadataHelper, scannerFactory, indexLookupMap));
            }
            // Check if there are any bounded ranges to expand.
            if (nodeCount.isPresent(BoundedRange.class)) {
                config.setQueryTree(timedExpandRanges(timers, "Expand Ranges", config.getQueryTree(), config, metadataHelper, scannerFactory));
            }
            // NOTE: GeoWavePruningVisitor should run before QueryPruningVisitor. If it runs after, there is a chance
            // that GeoWavePruningVisitor will prune all of the remaining indexed terms, which would leave a GeoWave
            // function without any indexed terms or ranges, which should evaluate to false. That case won't be handled
            // properly if we run GeoWavePruningVisitor after QueryPruningVisitor.
            config.setQueryTree(timedPruneGeoWaveTerms(timers, config.getQueryTree(), metadataHelper));
            if (reduceQuery) {
                config.setQueryTree(timedReduce(timers, "Reduce Query After Range Expansion", config.getQueryTree()));
            }
            // Check if there are functions that can be pushed into exceeded value ranges.
            if (nodeCount.hasAll(ASTFunctionNode.class, ExceededValueThresholdMarkerJexlNode.class)) {
                config.setQueryTree(timedPushFunctions(timers, config.getQueryTree(), config, metadataHelper));
            }
            if (executableExpansion) {
                config.setQueryTree(timedExecutableExpansion(timers, config.getQueryTree(), config, metadataHelper));
            }
            List<String> debugOutput = null;
            if (log.isDebugEnabled()) {
                debugOutput = new ArrayList<>(32);
            }
            // the terms to be delayed.
            if (!ExecutableDeterminationVisitor.isExecutable(config.getQueryTree(), config, indexedFields, indexOnlyFields, nonEventFields, debugOutput, metadataHelper)) {
                // if we now have an unexecutable tree because of delayed
                // predicates, then remove delayed predicates as needed and
                // reexpand
                config.setQueryTree(timedRemoveDelayedPredicates(timers, "Remove Delayed Predicates", config.getQueryTree(), config, metadataHelper, indexedFields, indexOnlyFields, nonEventFields, indexLookupMap, scannerFactory, metadataHelper, debugOutput));
            }
            // if we now have an unexecutable tree because of missing
            // delayed predicates, then add delayed predicates where
            // possible
            config.setQueryTree(timedAddDelayedPredicates(timers, "Add Delayed Predicates", config.getQueryTree(), config, metadataHelper, indexedFields, indexOnlyFields, nonEventFields, debugOutput));
        } catch (TableNotFoundException e) {
            stopwatch.stop();
            QueryException qe = new QueryException(DatawaveErrorCode.METADATA_ACCESS_ERROR, e);
            throw new DatawaveFatalQueryException(qe);
        } catch (CannotExpandUnfieldedTermFatalException e) {
            if (null != e.getCause() && e.getCause() instanceof DoNotPerformOptimizedQueryException)
                throw (DoNotPerformOptimizedQueryException) e.getCause();
            QueryException qe = new QueryException(DatawaveErrorCode.INDETERMINATE_INDEX_STATUS, e);
            throw new DatawaveFatalQueryException(qe);
        }
        stopwatch.stop();
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Bounded range and regex conversion has been disabled");
        }
    }
    return config.getQueryTree();
}
Also used : HashMap(java.util.HashMap) CannotExpandUnfieldedTermFatalException(datawave.query.exceptions.CannotExpandUnfieldedTermFatalException) IndexLookup(datawave.query.jexl.lookups.IndexLookup) NodeTypeCount(datawave.query.jexl.NodeTypeCount) 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) DoNotPerformOptimizedQueryException(datawave.query.exceptions.DoNotPerformOptimizedQueryException)

Aggregations

CannotExpandUnfieldedTermFatalException (datawave.query.exceptions.CannotExpandUnfieldedTermFatalException)1 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)1 DatawaveQueryException (datawave.query.exceptions.DatawaveQueryException)1 DoNotPerformOptimizedQueryException (datawave.query.exceptions.DoNotPerformOptimizedQueryException)1 InvalidQueryException (datawave.query.exceptions.InvalidQueryException)1 NodeTypeCount (datawave.query.jexl.NodeTypeCount)1 IndexLookup (datawave.query.jexl.lookups.IndexLookup)1 TraceStopwatch (datawave.util.time.TraceStopwatch)1 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)1 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)1 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)1 QueryException (datawave.webservice.query.exception.QueryException)1 HashMap (java.util.HashMap)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1