Search in sources :

Example 16 with DatawaveFatalQueryException

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

the class IteratorBuildingVisitor method visit.

@Override
public Object visit(ASTNENode node, Object data) {
    // We have no parent already defined
    if (data == null) {
        // We don't support querying only on a negation
        throw new IllegalStateException("Root node cannot be a negation");
    }
    IndexIteratorBuilder builder = null;
    try {
        builder = iteratorBuilderClass.asSubclass(IndexIteratorBuilder.class).newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    builder.setQueryId(queryId);
    builder.setSource(source.deepCopy(env));
    builder.setTypeMetadata(typeMetadata);
    builder.setFieldsToAggregate(fieldsToAggregate);
    builder.setTimeFilter(timeFilter);
    builder.setDatatypeFilter(datatypeFilter);
    builder.setKeyTransform(fiAggregator);
    builder.setEnv(env);
    builder.setNode(node);
    node.childrenAccept(this, builder);
    // handle this, so we should just not build an IndexIterator for it.
    if (null == builder.getValue()) {
        if (this.indexOnlyFields.contains(builder.getField())) {
            QueryException qe = new QueryException(DatawaveErrorCode.INDEX_ONLY_FIELDS_RETRIEVAL_ERROR, MessageFormat.format("{0} {1} {2}", "Unable to compare index only field", builder.getField(), "against null"));
            throw new DatawaveFatalQueryException(qe);
        }
        // SatisfactionVisitor should have already initialized this to false
        if (isQueryFullySatisfied == true) {
            log.warn("Determined that isQueryFullySatisfied should be false, but it was not preset to false in the SatisfactionVisitor");
        }
        return null;
    }
    AbstractIteratorBuilder iterators = (AbstractIteratorBuilder) data;
    // Add the negated IndexIteratorBuilder to the parent as an *exclude*
    if (!iterators.hasSeen(builder.getField(), builder.getValue()) && includeReferences.contains(builder.getField()) && !excludeReferences.contains(builder.getField())) {
        iterators.addExclude(builder.build());
    } else {
        // SatisfactionVisitor should have already initialized this to false
        if (isQueryFullySatisfied == true) {
            log.warn("Determined that isQueryFullySatisfied should be false, but it was not preset to false in the SatisfactionVisitor");
        }
    }
    return null;
}
Also used : DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) IndexIteratorBuilder(datawave.query.iterator.builder.IndexIteratorBuilder) AbstractIteratorBuilder(datawave.query.iterator.builder.AbstractIteratorBuilder) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException)

Example 17 with DatawaveFatalQueryException

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

the class IteratorBuildingVisitor method ivarateRange.

/**
 * Build the iterator stack using the regex ivarator (field index caching regex iterator)
 *
 * @param rootNode
 *            the node that was processed to generated this builder
 * @param sourceNode
 *            the source node derived from the root
 * @param data
 */
public void ivarateRange(JexlNode rootNode, JexlNode sourceNode, Object data) throws IOException {
    IndexRangeIteratorBuilder builder = new IndexRangeIteratorBuilder();
    builder.negateAsNeeded(data);
    // hence the "IndexAgnostic" method can be used here
    if (sourceNode instanceof ASTAndNode) {
        LiteralRange range = JexlASTHelper.findRange().recursively().getRange(sourceNode);
        if (range == null) {
            QueryException qe = new QueryException(DatawaveErrorCode.MULTIPLE_RANGES_IN_EXPRESSION);
            throw new DatawaveFatalQueryException(qe);
        }
        builder.setRange(range);
    } else {
        QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "ExceededValueThresholdMarkerJexlNode"));
        throw new DatawaveFatalQueryException(qe);
    }
    builder.forceDocumentBuild(!limitLookup && this.isQueryFullySatisfied);
    ivarate(builder, rootNode, sourceNode, data);
}
Also used : DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) IndexRangeIteratorBuilder(datawave.query.iterator.builder.IndexRangeIteratorBuilder) LiteralRange(datawave.query.jexl.LiteralRange) ASTAndNode(org.apache.commons.jexl2.parser.ASTAndNode)

Example 18 with DatawaveFatalQueryException

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

the class IteratorBuildingVisitor method ivarateRegex.

/**
 * Build the iterator stack using the regex ivarator (field index caching regex iterator)
 *
 * @param rootNode
 *            the node that was processed to generated this builder
 * @param sourceNode
 *            the source node derived from the root
 * @param data
 */
public void ivarateRegex(JexlNode rootNode, JexlNode sourceNode, Object data) throws IOException {
    IndexRegexIteratorBuilder builder = new IndexRegexIteratorBuilder();
    if (sourceNode instanceof ASTERNode || sourceNode instanceof ASTNRNode) {
        builder.setNegated(sourceNode instanceof ASTNRNode);
        builder.setField(JexlASTHelper.getIdentifier(sourceNode));
        builder.setValue(String.valueOf(JexlASTHelper.getLiteralValue(sourceNode)));
    } else {
        QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "ExceededValueThresholdMarkerJexlNode"));
        throw new DatawaveFatalQueryException(qe);
    }
    builder.negateAsNeeded(data);
    builder.forceDocumentBuild(!limitLookup && this.isQueryFullySatisfied);
    ivarate(builder, rootNode, sourceNode, data);
}
Also used : IndexRegexIteratorBuilder(datawave.query.iterator.builder.IndexRegexIteratorBuilder) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) ASTERNode(org.apache.commons.jexl2.parser.ASTERNode) ASTNRNode(org.apache.commons.jexl2.parser.ASTNRNode) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException)

Example 19 with DatawaveFatalQueryException

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

the class JexlStringBuildingVisitor method buildQuery.

/**
 * Build a String that is the equivalent JEXL query.
 *
 * @param script
 *            An ASTJexlScript
 * @param sortDedupeChildren
 *            Whether or not to sort the child nodes, and dedupe them. Note: Only siblings (children with the same parent node) will be deduped. Flatten
 *            beforehand for maximum 'dedupeage'.
 * @return
 */
public static String buildQuery(JexlNode script, boolean sortDedupeChildren) {
    JexlStringBuildingVisitor visitor = new JexlStringBuildingVisitor(sortDedupeChildren);
    String s = null;
    try {
        StringBuilder sb = (StringBuilder) script.jjtAccept(visitor, new StringBuilder());
        s = sb.toString();
        try {
            JexlASTHelper.parseJexlQuery(s);
        } catch (ParseException e) {
            log.error("Could not parse JEXL AST after performing transformations to run the query", e);
            for (String line : PrintingVisitor.formattedQueryStringList(script)) {
                log.error(line);
            }
            log.error("");
            QueryException qe = new QueryException(DatawaveErrorCode.QUERY_EXECUTION_ERROR, e);
            throw new DatawaveFatalQueryException(qe);
        }
    } catch (StackOverflowError e) {
        throw e;
    }
    return s;
}
Also used : DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) ParseException(org.apache.commons.jexl2.parser.ParseException)

Example 20 with DatawaveFatalQueryException

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

the class ExpandCompositeTerms method expandTerms.

/**
 * Expand all nodes which have multiple dataTypes for the field.
 *
 * @param config
 *            Configuration parameters relevant to our query
 * @param script
 *            The jexl node representing the query
 * @return An expanded version of the passed-in script containing composite nodes
 */
@SuppressWarnings("unchecked")
public static <T extends JexlNode> T expandTerms(ShardQueryConfiguration config, T script) {
    ExpandCompositeTerms visitor = new ExpandCompositeTerms(config);
    // need to flatten the tree so i get all and nodes at the same level
    script = TreeFlatteningRebuildingVisitor.flatten(script);
    if (null == visitor.config.getCompositeToFieldMap()) {
        QueryException qe = new QueryException(DatawaveErrorCode.DATATYPESFORINDEXFIELDS_MULTIMAP_MISSING);
        throw new DatawaveFatalQueryException(qe);
    }
    return (T) script.jjtAccept(visitor, new ExpandData());
}
Also used : DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException)

Aggregations

DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)51 QueryException (datawave.webservice.query.exception.QueryException)32 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)16 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)14 IOException (java.io.IOException)12 LiteralRange (datawave.query.jexl.LiteralRange)11 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)11 InvalidQueryException (datawave.query.exceptions.InvalidQueryException)10 DoNotPerformOptimizedQueryException (datawave.query.exceptions.DoNotPerformOptimizedQueryException)9 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)9 Range (org.apache.accumulo.core.data.Range)9 DatawaveQueryException (datawave.query.exceptions.DatawaveQueryException)8 Key (org.apache.accumulo.core.data.Key)7 JexlNode (org.apache.commons.jexl2.parser.JexlNode)7 TraceStopwatch (datawave.util.time.TraceStopwatch)6 Entry (java.util.Map.Entry)5 Type (datawave.data.type.Type)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 PartialKey (org.apache.accumulo.core.data.PartialKey)4