Search in sources :

Example 1 with BoundedRange

use of datawave.query.jexl.nodes.BoundedRange in project datawave by NationalSecurityAgency.

the class ExpandMultiNormalizedTerms method expandRangeForNormalizers.

private Object expandRangeForNormalizers(LiteralRange<?> range, JexlNode node) {
    List<BoundedRange> aliasedBounds = Lists.newArrayList();
    String field = range.getFieldName();
    // Get all of the indexed or normalized dataTypes for the field name
    Set<Type<?>> dataTypes = Sets.newHashSet(config.getQueryFieldsDatatypes().get(field));
    dataTypes.addAll(config.getNormalizedFieldsDatatypes().get(field));
    for (Type<?> normalizer : dataTypes) {
        JexlNode lowerBound = range.getLowerNode(), upperBound = range.getUpperNode();
        JexlNode left = null;
        try {
            left = JexlASTHelper.applyNormalization(copy(lowerBound), normalizer);
        } catch (Exception ne) {
            if (log.isTraceEnabled()) {
                log.trace("Could not normalize " + PrintingVisitor.formattedQueryString(lowerBound) + " using " + normalizer.getClass() + ". " + ne.getMessage());
            }
            continue;
        }
        JexlNode right = null;
        try {
            right = JexlASTHelper.applyNormalization(copy(upperBound), normalizer);
        } catch (Exception ne) {
            if (log.isTraceEnabled()) {
                log.trace("Could not normalize " + PrintingVisitor.formattedQueryString(upperBound) + " using " + normalizer.getClass() + ". " + ne.getMessage());
            }
            continue;
        }
        aliasedBounds.add(new BoundedRange(JexlNodes.children(new ASTAndNode(ParserTreeConstants.JJTANDNODE), left, right)));
    }
    if (aliasedBounds.isEmpty()) {
        return node;
    } else {
        this.expandedNodes.addAll(aliasedBounds);
        // Avoid extra parens around the expansion
        if (1 == aliasedBounds.size()) {
            return aliasedBounds.get(0);
        } else {
            List<ASTReferenceExpression> var = JexlASTHelper.wrapInParens(aliasedBounds);
            return JexlNodes.wrap(JexlNodes.children(new ASTOrNode(ParserTreeConstants.JJTORNODE), var.toArray(new JexlNode[var.size()])));
        }
    }
}
Also used : ASTOrNode(org.apache.commons.jexl2.parser.ASTOrNode) ASTReferenceExpression(org.apache.commons.jexl2.parser.ASTReferenceExpression) ContainerType(datawave.query.jexl.JexlNodeFactory.ContainerType) IpAddressType(datawave.data.type.IpAddressType) Type(datawave.data.type.Type) JexlNode(org.apache.commons.jexl2.parser.JexlNode) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) BoundedRange(datawave.query.jexl.nodes.BoundedRange) ASTAndNode(org.apache.commons.jexl2.parser.ASTAndNode)

Example 2 with BoundedRange

use of datawave.query.jexl.nodes.BoundedRange in project datawave by NationalSecurityAgency.

the class QueryModelVisitor method expandRangeNodeFromModel.

public Object expandRangeNodeFromModel(LiteralRange range, ASTAndNode node, Object data) {
    if (isFieldExcluded(range.getFieldName())) {
        return node;
    }
    // this is the set of fields that have an upper and a lower bound operand
    // make a copy of the intersection, as I will be modifying lowererBounds and upperBounds below
    List<JexlNode> aliasedBounds = Lists.newArrayList();
    Collection<String> aliases = getAliasesForField(range.getFieldName());
    if (aliases.isEmpty()) {
        aliases = Lists.newArrayList(range.getFieldName());
    }
    for (String alias : aliases) {
        if (alias != null) {
            BoundedRange rangeNode = BoundedRange.create(JexlNodes.children(new ASTAndNode(ParserTreeConstants.JJTANDNODE), JexlASTHelper.setField(RebuildingVisitor.copy(range.getLowerNode()), alias), JexlASTHelper.setField(RebuildingVisitor.copy(range.getUpperNode()), alias)));
            aliasedBounds.add(rangeNode);
            this.expandedNodes.add((ASTAndNode) JexlASTHelper.dereference(rangeNode));
        }
    }
    JexlNode nodeToAdd;
    if (1 == aliasedBounds.size()) {
        nodeToAdd = JexlASTHelper.dereference(aliasedBounds.get(0));
    } else {
        ASTOrNode unionOfAliases = new ASTOrNode(ParserTreeConstants.JJTORNODE);
        nodeToAdd = JexlNodes.children(unionOfAliases, aliasedBounds.toArray(new JexlNode[aliasedBounds.size()]));
    }
    return nodeToAdd;
}
Also used : ASTOrNode(org.apache.commons.jexl2.parser.ASTOrNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) BoundedRange(datawave.query.jexl.nodes.BoundedRange) ASTAndNode(org.apache.commons.jexl2.parser.ASTAndNode)

Aggregations

BoundedRange (datawave.query.jexl.nodes.BoundedRange)2 ASTAndNode (org.apache.commons.jexl2.parser.ASTAndNode)2 ASTOrNode (org.apache.commons.jexl2.parser.ASTOrNode)2 JexlNode (org.apache.commons.jexl2.parser.JexlNode)2 IpAddressType (datawave.data.type.IpAddressType)1 Type (datawave.data.type.Type)1 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)1 ContainerType (datawave.query.jexl.JexlNodeFactory.ContainerType)1 QueryException (datawave.webservice.query.exception.QueryException)1 ASTReferenceExpression (org.apache.commons.jexl2.parser.ASTReferenceExpression)1