use of org.apache.commons.jexl2.parser.ASTLTNode in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method buildNullNode.
public static JexlNode buildNullNode(JexlNode original, ASTIdentifier identifier) {
JexlNode copy;
if (original instanceof ASTEQNode) {
copy = new ASTEQNode(ParserTreeConstants.JJTEQNODE);
} else if (original instanceof ASTNENode) {
copy = new ASTNENode(ParserTreeConstants.JJTNENODE);
} else if (original instanceof ASTERNode) {
copy = new ASTERNode(ParserTreeConstants.JJTERNODE);
} else if (original instanceof ASTNRNode) {
copy = new ASTNRNode(ParserTreeConstants.JJTNRNODE);
} else if (original instanceof ASTGTNode) {
copy = new ASTGTNode(ParserTreeConstants.JJTGTNODE);
} else if (original instanceof ASTGENode) {
copy = new ASTGENode(ParserTreeConstants.JJTGENODE);
} else if (original instanceof ASTLTNode) {
copy = new ASTLTNode(ParserTreeConstants.JJTLTNODE);
} else if (original instanceof ASTLENode) {
copy = new ASTLENode(ParserTreeConstants.JJTLENODE);
} else {
throw new UnsupportedOperationException("Cannot handle " + original);
}
copy.jjtSetParent(original.jjtGetParent());
ASTNullLiteral literalNode = new ASTNullLiteral(ParserTreeConstants.JJTNULLLITERAL);
return buildUntypedNewLiteralNode(copy, identifier, literalNode);
}
use of org.apache.commons.jexl2.parser.ASTLTNode in project datawave by NationalSecurityAgency.
the class CompositeRange method isValid.
// this composite range is invalid if
// - it doesn't contain any nodes, or they are all null
// - it contains an invalid leaf node, or doesn't contain a valid leaf node
// - it contains a regex node
// - it represents an unbounded range (i.e. contains all GT/GE nodes, or all LT/LE nodes)
// - there are gaps in the upper or lower bound
@Override
public boolean isValid() {
// if we have no nodes, or they are all null
if (jexlNodeList.isEmpty() || jexlNodeList.stream().allMatch(Objects::isNull) || jexlNodeListLowerBound.stream().allMatch(Objects::isNull) || jexlNodeListUpperBound.stream().allMatch(Objects::isNull))
return false;
boolean allGTOrGENodes = true;
boolean allLTOrLENodes = true;
for (JexlNode node : jexlNodeList) {
Class nodeClass = node.getClass();
// if this is an invalid leaf node, or not a valid leaf node, we're done
if (INVALID_LEAF_NODE_CLASSES.contains(nodeClass) || !VALID_LEAF_NODE_CLASSES.contains(nodeClass))
return false;
// regex and not equals nodes are not allowed in a bounded range
if (node instanceof ASTERNode || node instanceof ASTNENode)
return false;
// keeping track of whether all the nodes are GT or GE
if (!(node instanceof ASTGTNode || node instanceof ASTGENode))
allGTOrGENodes = false;
// keeping track of whether all the nodes are LT or LE
if (!(node instanceof ASTLTNode || node instanceof ASTLENode))
allLTOrLENodes = false;
}
// there's no value in creating composites for unbounded ranges
if (allGTOrGENodes || allLTOrLENodes)
return false;
// look for gaps in the lower bound. trailing nulls are ok, but nulls followed by non-nulls are not
boolean hasNullNode = false;
for (JexlNode lowerNode : jexlNodeListLowerBound) {
if (hasNullNode && lowerNode != null)
return false;
hasNullNode = hasNullNode || lowerNode == null;
}
// look for gaps in the upper bound. trailing nulls are ok, but nulls followed by non-nulls are not
hasNullNode = false;
for (JexlNode upperNode : jexlNodeListUpperBound) {
if (hasNullNode && upperNode != null)
return false;
hasNullNode = hasNullNode || upperNode == null;
}
return true;
}
use of org.apache.commons.jexl2.parser.ASTLTNode in project datawave by NationalSecurityAgency.
the class DatawaveInterpreter method evaluateRange.
/**
* * This will determine if this ANDNode contains a range, and will invoke the appropriate range function instead of evaluating the LT/LE and GT/GE nodes *
* independently as that does not work when there are sets of values in the context. * * @param node * @return a collection of hits (or empty set) if we
* evaluated a range. null otherwise.
*/
private Collection<?> evaluateRange(ASTAndNode node) {
Collection<?> evaluation = null;
LiteralRange range = JexlASTHelper.findRange().getRange(node);
if (range != null) {
JexlNode left = range.getLowerNode();
JexlNode right = range.getUpperNode();
if (left instanceof ASTLENode || left instanceof ASTLTNode) {
JexlNode temp = left;
left = right;
right = temp;
}
if ((left instanceof ASTGENode || left instanceof ASTGTNode) && (right instanceof ASTLENode || right instanceof ASTLTNode)) {
JexlNode leftIdentifier = dereference(left.jjtGetChild(0));
JexlNode rightIdentifier = dereference(right.jjtGetChild(0));
if (leftIdentifier instanceof ASTIdentifier && rightIdentifier instanceof ASTIdentifier) {
String fieldName = leftIdentifier.image;
if (fieldName.equals(rightIdentifier.image)) {
Object fieldValue = leftIdentifier.jjtAccept(this, null);
Object leftValue = left.jjtGetChild(1).jjtAccept(this, null);
boolean leftInclusive = left instanceof ASTGENode;
Object rightValue = right.jjtGetChild(1).jjtAccept(this, null);
boolean rightInclusive = right instanceof ASTLENode;
if (leftValue instanceof Number && rightValue instanceof Number) {
if (fieldValue instanceof Collection) {
evaluation = QueryFunctions.between((Collection) fieldValue, ((Number) leftValue).floatValue(), leftInclusive, ((Number) rightValue).floatValue(), rightInclusive);
} else {
evaluation = QueryFunctions.between(fieldValue, ((Number) leftValue).floatValue(), leftInclusive, ((Number) rightValue).floatValue(), rightInclusive);
}
} else {
if (fieldValue instanceof Collection) {
evaluation = QueryFunctions.between((Collection) fieldValue, String.valueOf(leftValue), leftInclusive, String.valueOf(rightValue), rightInclusive);
} else {
evaluation = QueryFunctions.between(fieldValue, String.valueOf(leftValue), leftInclusive, String.valueOf(rightValue), rightInclusive);
}
}
addHits(fieldValue);
}
}
}
}
return evaluation;
}
use of org.apache.commons.jexl2.parser.ASTLTNode in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method buildBooleanNode.
public static JexlNode buildBooleanNode(JexlNode original, ASTIdentifier identifier, Boolean literal) {
JexlNode copy;
if (original instanceof ASTEQNode) {
copy = new ASTEQNode(ParserTreeConstants.JJTEQNODE);
} else if (original instanceof ASTNENode) {
copy = new ASTNENode(ParserTreeConstants.JJTNENODE);
} else if (original instanceof ASTERNode) {
copy = new ASTERNode(ParserTreeConstants.JJTERNODE);
} else if (original instanceof ASTNRNode) {
copy = new ASTNRNode(ParserTreeConstants.JJTNRNODE);
} else if (original instanceof ASTGTNode) {
copy = new ASTGTNode(ParserTreeConstants.JJTGTNODE);
} else if (original instanceof ASTGENode) {
copy = new ASTGENode(ParserTreeConstants.JJTGENODE);
} else if (original instanceof ASTLTNode) {
copy = new ASTLTNode(ParserTreeConstants.JJTLTNODE);
} else if (original instanceof ASTLENode) {
copy = new ASTLENode(ParserTreeConstants.JJTLENODE);
} else {
throw new UnsupportedOperationException("Cannot handle " + original);
}
copy.jjtSetParent(original.jjtGetParent());
JexlNode literalNode;
if (literal) {
literalNode = new ASTTrueNode(ParserTreeConstants.JJTTRUENODE);
} else {
literalNode = new ASTFalseNode(ParserTreeConstants.JJTFALSENODE);
}
return buildUntypedNewLiteralNode(copy, identifier, literalNode);
}
Aggregations