Search in sources :

Example 1 with IndexIteratorBuilder

use of datawave.query.iterator.builder.IndexIteratorBuilder in project datawave by NationalSecurityAgency.

the class IteratorBuildingVisitor method createExceededCheck.

/**
 * This method should only be used when we know it is not a term frequency or index only in the limited case, as we will subsequently evaluate this
 * expression during final evaluation
 *
 * @param identifier
 * @param range
 * @return
 */
protected NestedIterator<Key> createExceededCheck(String identifier, LiteralRange<?> range, JexlNode rootNode) {
    IndexIteratorBuilder builder = null;
    try {
        builder = iteratorBuilderClass.asSubclass(IndexIteratorBuilder.class).newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    IteratorToSortedKeyValueIterator kvIter = new IteratorToSortedKeyValueIterator(getExceededEntry(identifier, range).iterator());
    builder.setQueryId(queryId);
    builder.setSource(kvIter);
    builder.setValue(null != range.getLower() ? range.getLower().toString() : "null");
    builder.setField(identifier);
    builder.setTimeFilter(TimeFilter.alwaysTrue());
    builder.setTypeMetadata(typeMetadata);
    builder.setFieldsToAggregate(fieldsToAggregate);
    builder.setDatatypeFilter(datatypeFilter);
    builder.setKeyTransform(fiAggregator);
    builder.setEnv(env);
    builder.setNode(rootNode);
    return builder.build();
}
Also used : IndexIteratorBuilder(datawave.query.iterator.builder.IndexIteratorBuilder) IteratorToSortedKeyValueIterator(datawave.query.util.IteratorToSortedKeyValueIterator)

Example 2 with IndexIteratorBuilder

use of datawave.query.iterator.builder.IndexIteratorBuilder 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 3 with IndexIteratorBuilder

use of datawave.query.iterator.builder.IndexIteratorBuilder in project datawave by NationalSecurityAgency.

the class IteratorBuildingVisitor method visitDelayedIndexOnly.

protected Object visitDelayedIndexOnly(ASTEQNode node, Object data) {
    IndexIteratorBuilder builder = null;
    try {
        builder = iteratorBuilderClass.asSubclass(IndexIteratorBuilder.class).newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    /**
     * If we have an unindexed type enforced, we've been configured to assert whether the field is indexed.
     */
    if (isUnindexed(node)) {
        if (isQueryFullySatisfied == true) {
            log.warn("Determined that isQueryFullySatisfied should be false, but it was not preset to false in the SatisfactionVisitor");
        }
        return null;
    }
    // boolean to tell us if we've overridden our subtree due to
    // a negation or
    boolean isNegation = (null != data && data instanceof AbstractIteratorBuilder && ((AbstractIteratorBuilder) data).isInANot());
    builder.setSource(getSourceIterator(node, isNegation));
    builder.setQueryId(queryId);
    builder.setTimeFilter(getTimeFilter(node));
    builder.setTypeMetadata(typeMetadata);
    builder.setFieldsToAggregate(fieldsToAggregate);
    builder.setDatatypeFilter(datatypeFilter);
    builder.setKeyTransform(fiAggregator);
    builder.setEnv(env);
    node.childrenAccept(this, builder);
    // handle this, so we should just not build an IndexIterator for it.
    if (null == builder.getValue()) {
        if (isQueryFullySatisfied == true) {
            log.warn("Determined that isQueryFullySatisfied should be false, but it was not preset to false in the SatisfactionVisitor");
        }
        return null;
    }
    // We have no parent already defined
    if (data == null) {
        // Make this EQNode the root
        if (!includeReferences.contains(builder.getField()) && excludeReferences.contains(builder.getField())) {
            throw new IllegalStateException(builder.getField() + " is a blacklisted reference.");
        } else {
            root = builder.build();
            if (log.isTraceEnabled()) {
                log.trace("Build IndexIterator: " + root);
            }
        }
    } else {
        AbstractIteratorBuilder iterators = (AbstractIteratorBuilder) data;
        // Add this IndexIterator to the parent
        final boolean isNew = !iterators.hasSeen(builder.getField(), builder.getValue());
        final boolean inclusionReference = includeReferences.contains(builder.getField());
        final boolean notExcluded = !excludeReferences.contains(builder.getField());
        if (isNew && inclusionReference && notExcluded) {
            iterators.addInclude(builder.build());
        } else {
            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 : IndexIteratorBuilder(datawave.query.iterator.builder.IndexIteratorBuilder) AbstractIteratorBuilder(datawave.query.iterator.builder.AbstractIteratorBuilder)

Example 4 with IndexIteratorBuilder

use of datawave.query.iterator.builder.IndexIteratorBuilder in project datawave by NationalSecurityAgency.

the class IteratorBuildingVisitor method visit.

@Override
public Object visit(ASTIdentifier node, Object o) {
    // Set the literal in the IndexIterator
    if (o instanceof IndexIteratorBuilder) {
        IndexIteratorBuilder builder = (IndexIteratorBuilder) o;
        builder.setField(JexlASTHelper.deconstructIdentifier(node.image));
    }
    if (isUnindexed(node)) {
        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 : IndexIteratorBuilder(datawave.query.iterator.builder.IndexIteratorBuilder)

Example 5 with IndexIteratorBuilder

use of datawave.query.iterator.builder.IndexIteratorBuilder in project datawave by NationalSecurityAgency.

the class IteratorBuildingVisitor method visit.

@Override
public Object visit(ASTEQNode node, Object data) {
    IndexIteratorBuilder builder = null;
    try {
        builder = iteratorBuilderClass.asSubclass(IndexIteratorBuilder.class).newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    /**
     * If we have an unindexed type enforced, we've been configured to assert whether the field is indexed.
     */
    if (isUnindexed(node)) {
        if (isQueryFullySatisfied == true) {
            log.warn("Determined that isQueryFullySatisfied should be false, but it was not preset to false in the SatisfactionVisitor");
        }
        return null;
    }
    // boolean to tell us if we've overridden our subtree due to
    // a negation or
    boolean isNegation = false;
    if (data instanceof AbstractIteratorBuilder) {
        AbstractIteratorBuilder oib = (AbstractIteratorBuilder) data;
        isNegation = oib.isInANot();
    }
    builder.setQueryId(queryId);
    builder.setSource(getSourceIterator(node, isNegation));
    builder.setTimeFilter(getTimeFilter(node));
    builder.setTypeMetadata(typeMetadata);
    builder.setFieldsToAggregate(fieldsToAggregate);
    builder.setDatatypeFilter(datatypeFilter);
    builder.setKeyTransform(fiAggregator);
    builder.setEnv(env);
    builder.forceDocumentBuild(!limitLookup && this.isQueryFullySatisfied);
    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);
        }
        return null;
    }
    // We have no parent already defined
    if (data == null) {
        // Make this EQNode the root
        if (!includeReferences.contains(builder.getField()) && excludeReferences.contains(builder.getField())) {
            throw new IllegalStateException(builder.getField() + " is a blacklisted reference.");
        } else if (builder.getField() != null) {
            root = builder.build();
            if (log.isTraceEnabled()) {
                log.trace("Build IndexIterator: " + root);
            }
        }
    } else {
        AbstractIteratorBuilder iterators = (AbstractIteratorBuilder) data;
        // Add this IndexIterator to the parent
        final boolean isNew = !iterators.hasSeen(builder.getField(), builder.getValue());
        final boolean inclusionReference = includeReferences.contains(builder.getField());
        final boolean notExcluded = !excludeReferences.contains(builder.getField());
        if (isNew && inclusionReference && notExcluded) {
            iterators.addInclude(builder.build());
        } else {
            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)

Aggregations

IndexIteratorBuilder (datawave.query.iterator.builder.IndexIteratorBuilder)5 AbstractIteratorBuilder (datawave.query.iterator.builder.AbstractIteratorBuilder)3 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)2 QueryException (datawave.webservice.query.exception.QueryException)2 IteratorToSortedKeyValueIterator (datawave.query.util.IteratorToSortedKeyValueIterator)1