use of org.apache.commons.jexl2.parser.JexlNode 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.JexlNode 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.JexlNode 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.JexlNode in project datawave by NationalSecurityAgency.
the class IndexInfo method buildNodeList.
protected Set<IndexMatch> buildNodeList(HashMultimap<String, JexlNode> ids, IndexMatchType type, boolean allowsDelayed, List<JexlNode> delayedNodes) {
Set<IndexMatch> matches = Sets.newHashSet();
for (String uid : ids.keySet()) {
Set<JexlNode> nodes = ids.get(uid);
// make sure that we have nodes, otherwise we are pruned to nothing
if (nodes.size() > 1 || (allowsDelayed && (nodes.size() + delayedNodes.size()) > 1)) {
JexlNodeSet nodeSet = new JexlNodeSet();
nodeSet.addAll(nodes);
nodeSet.addAll(delayedNodes);
IndexMatch currentMatch = new IndexMatch(Sets.newHashSet(nodeSet.getNodes()), uid, type);
matches.add(currentMatch);
}
}
return matches;
}
use of org.apache.commons.jexl2.parser.JexlNode 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, "");
}
Aggregations