use of org.apache.commons.jexl2.parser.Node in project datawave by NationalSecurityAgency.
the class CompositeRange method addComponent.
@Override
public void addComponent(JexlNode node) {
List<JexlNode> nodes = new ArrayList<>();
LiteralRange range = JexlASTHelper.findRange().getRange(node);
if (range != null) {
nodes.add(range.getLowerNode());
nodes.add(range.getUpperNode());
} else if (node instanceof ASTEQNode) {
String fieldName = JexlASTHelper.getIdentifier(node);
String expression = JexlASTHelper.getLiteralValue(node).toString();
nodes.add(JexlNodeFactory.buildNode((ASTGENode) null, fieldName, expression));
nodes.add(JexlNodeFactory.buildNode((ASTLENode) null, fieldName, expression));
} else {
nodes.add(node);
}
jexlNodeList.add(node);
fieldNameList.add(JexlASTHelper.getIdentifier(nodes.get(0)));
for (JexlNode boundNode : nodes) {
String expression = JexlASTHelper.getLiteralValue(boundNode).toString();
if (boundNode instanceof ASTGENode || boundNode instanceof ASTGTNode) {
jexlNodeListLowerBound.add(boundNode);
expressionListLowerBound.add(expression);
if (nodes.size() < 2) {
jexlNodeListUpperBound.add(null);
expressionListUpperBound.add(null);
}
} else if (boundNode instanceof ASTLENode || boundNode instanceof ASTLTNode) {
jexlNodeListUpperBound.add(boundNode);
expressionListUpperBound.add(expression);
if (nodes.size() < 2) {
jexlNodeListLowerBound.add(null);
expressionListLowerBound.add(null);
}
}
}
}
use of org.apache.commons.jexl2.parser.Node in project datawave by NationalSecurityAgency.
the class CompositeRange method getUpperBoundExpression.
private String getUpperBoundExpression(Map<String, DiscreteIndexType<?>> discreteIndexTypeMap) {
StringBuilder buf = new StringBuilder();
boolean lastNode = false;
for (int i = 0; i < expressionListUpperBound.size(); i++) {
String expression = expressionListUpperBound.get(i);
JexlNode node = jexlNodeListUpperBound.get(i);
if (expression != null && node != null) {
if (i != (expressionListUpperBound.size() - 1)) {
// Convert LE node to LT node if it is the last valid node in the list
if (node instanceof ASTLENode && expressionListUpperBound.get(i + 1) == null) {
String exclusiveUpperBound = CompositeUtils.getExclusiveUpperBound(expression, discreteIndexTypeMap.get(fieldNameList.get(i)));
// bound, and signal that this is the last expression
if (exclusiveUpperBound.length() != expression.length())
lastNode = true;
else
expression = exclusiveUpperBound;
} else // Convert LT nodes to inclusive LE nodes if they are not the last valid node in the list
if (node instanceof ASTLTNode && expressionListUpperBound.get(i + 1) != null) {
String inclusiveUpperBound = CompositeUtils.getInclusiveUpperBound(expression, discreteIndexTypeMap.get(fieldNameList.get(i)));
// bound, and signal that this is the last expression
if (inclusiveUpperBound.length() != expression.length())
lastNode = true;
else
expression = inclusiveUpperBound;
}
}
if (i > 0)
buf.append(separator);
buf.append(expression);
} else {
break;
}
if (lastNode)
break;
}
return buf.toString();
}
use of org.apache.commons.jexl2.parser.Node in project datawave by NationalSecurityAgency.
the class IndexInfo method applyNode.
public void applyNode(JexlNode node) {
JexlNode copy = RebuildingVisitor.copy(node);
copy.jjtSetParent(null);
myNode = copy;
for (IndexMatch match : uids) {
match.add(node);
}
}
use of org.apache.commons.jexl2.parser.Node in project datawave by NationalSecurityAgency.
the class ExecutableDeterminationVisitor method getState.
public static STATE getState(JexlNode node, ShardQueryConfiguration config, MetadataHelper helper, boolean forFieldIndex, List<String> debugOutput) {
ExecutableDeterminationVisitor visitor = new ExecutableDeterminationVisitor(config, helper, forFieldIndex, debugOutput);
// push down any negations to ensure the state is accurate
JexlNode pushedDownTree = PushdownNegationVisitor.pushdownNegations(node);
return (STATE) pushedDownTree.jjtAccept(visitor, "");
}
use of org.apache.commons.jexl2.parser.Node in project datawave by NationalSecurityAgency.
the class ExecutableExpansionVisitor method canExpand.
/**
* Test if the current node should be expanded by this visitor. Update the tracker with the current andChild if expansion is possible
*
* @param node
* the node to test
* @param tracker
* the tracker holding supplementary information about the expansion
* @return true if the expansion should occur, false otherwise
*/
private boolean canExpand(JexlNode node, ExecutableDeterminationVisitor.STATE state, ExpansionTracker tracker) {
// only process if state is ERROR or PARTIAL
if (!(state == ExecutableDeterminationVisitor.STATE.ERROR || state == ExecutableDeterminationVisitor.STATE.PARTIAL)) {
return false;
}
// if deeper down in the tree there was a failed expansion attempt, don't try again
if (tracker.isFailedExpansion()) {
return false;
}
// there must be an andNode further up the tree to distribute into the or
ASTAndNode lastAnd = tracker.getLastAnd();
// as long as there is a lastAnd there is work to do
if (lastAnd == null) {
return false;
}
// verify there is nothing but compatible nodes between the andNode and the orNode
JexlNode current = node.jjtGetParent();
JexlNode last = node;
while (current != lastAnd) {
if (!(current instanceof ASTReference || current instanceof ASTReferenceExpression)) {
return false;
}
last = current;
current = current.jjtGetParent();
}
// if we got here the expansion is good and we should track the andChild for later use
tracker.setAndChild(last);
return true;
}
Aggregations