use of datawave.query.language.parser.jexl.JexlNode in project datawave by NationalSecurityAgency.
the class FunctionQueryNodeBuilder method build.
public JexlNode build(QueryNode queryNode) {
JexlNode returnNode = null;
int depth = 0;
QueryNode parent = queryNode;
while ((parent = parent.getParent()) != null) {
depth++;
}
if (queryNode instanceof FunctionQueryNode) {
FunctionQueryNode functionQueryNode = (FunctionQueryNode) queryNode;
String functionName = functionQueryNode.getFunction();
List<String> parameterList = functionQueryNode.getParameterList();
JexlQueryFunction referenceFunction = allowedFunctionMap.get(functionName.toUpperCase());
if (referenceFunction == null) {
NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.FUNCTION_NOT_FOUND, MessageFormat.format("{0}", functionName));
throw new IllegalArgumentException(qe);
}
// if more than one term in quotes, use an AdjNode
JexlQueryFunction function = (JexlQueryFunction) referenceFunction.duplicate();
returnNode = new JexlFunctionNode(function, parameterList, depth, queryNode.getParent());
}
return returnNode;
}
use of datawave.query.language.parser.jexl.JexlNode in project datawave by NationalSecurityAgency.
the class RegexpQueryNodeBuilder method build.
public JexlNode build(QueryNode queryNode) throws QueryNodeException {
JexlNode returnNode = null;
if (queryNode instanceof RegexpQueryNode) {
RegexpQueryNode regexpQueryNode = (RegexpQueryNode) queryNode;
String field = regexpQueryNode.getFieldAsString();
UnescapedCharSequence ecs = (UnescapedCharSequence) regexpQueryNode.getText();
if (field == null || field.isEmpty()) {
returnNode = new JexlSelectorNode(JexlSelectorNode.Type.REGEX, "", ecs.toString());
} else {
returnNode = new JexlSelectorNode(JexlSelectorNode.Type.REGEX, field, ecs.toString());
}
}
return returnNode;
}
use of datawave.query.language.parser.jexl.JexlNode in project datawave by NationalSecurityAgency.
the class BooleanQueryNodeBuilder method build.
public JexlNode build(QueryNode queryNode) throws QueryNodeException {
BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode;
JexlNode bNode = null;
List<QueryNode> children = booleanNode.getChildren();
if (children != null) {
List<JexlNode> childrenList = new ArrayList<>();
LinkedList<QueryNode> extraNodeList = new LinkedList<>();
boolean isNegation = false;
for (QueryNode child : children) {
Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
if (obj != null) {
JexlNode query = (JexlNode) obj;
childrenList.add(query);
}
}
bNode = createNode(queryNode, childrenList, isNegation, extraNodeList);
}
return bNode;
}
use of datawave.query.language.parser.jexl.JexlNode in project datawave by NationalSecurityAgency.
the class FieldQueryNodeBuilder method build.
public JexlNode build(QueryNode queryNode) throws QueryNodeException {
JexlNode returnNode = null;
if (queryNode instanceof QuotedFieldQueryNode) {
List<String> phraseWordList = new ArrayList<>();
FieldQueryNode quotedFieldNode = (QuotedFieldQueryNode) queryNode;
String field = quotedFieldNode.getFieldAsString();
String selector = quotedFieldNode.getTextAsString();
// check if spaces were escaped
FieldQueryNode fieldQueryNode = (QuotedFieldQueryNode) queryNode;
UnescapedCharSequence origChars = (UnescapedCharSequence) fieldQueryNode.getText();
int nextWordStart = 0;
ArrayList<String> words = new ArrayList<>();
for (int x = 0; x < origChars.length(); x++) {
if (origChars.charAt(x) == ' ' && !origChars.wasEscaped(x)) {
words.add(selector.substring(nextWordStart, x));
nextWordStart = x + 1;
} else if (x == origChars.length() - 1) {
// last word in the list
words.add(selector.substring(nextWordStart));
}
}
replaceEscapeCharsWithSpace(words);
for (String s : words) {
String currWord = s.trim();
if (!currWord.isEmpty()) {
phraseWordList.add(currWord);
}
}
if (phraseWordList.size() == 1) {
// if only one term in quotes, just use a SelectorNode
String firstWord = phraseWordList.get(0);
if (field == null || field.isEmpty()) {
returnNode = new JexlSelectorNode(JexlSelectorNode.Type.EXACT, "", firstWord);
} else {
returnNode = new JexlSelectorNode(JexlSelectorNode.Type.EXACT, field, firstWord);
}
} else {
// if more than one term in quotes, use an AdjNode
returnNode = new JexlPhraseNode(field, phraseWordList);
}
} else if (queryNode instanceof FuzzyQueryNode) {
throw new UnsupportedOperationException(queryNode.getClass().getName() + " not implemented");
} else {
// queryNode instanceof WildcardQueryNode
// queryNode instanceof QuotedFieldQueryNode
// queryNode instanceof FieldQueryNode
FieldQueryNode fieldNode = (FieldQueryNode) queryNode;
boolean hasUnescapedWildcard = WildcardFieldedTerm.hasUnescapedWildcard(fieldNode, Sets.newHashSet(' ', '/'));
String field = fieldNode.getFieldAsString();
String selector;
JexlSelectorNode.Type type;
if (hasUnescapedWildcard) {
// When we have a regular expression, we want to maintain the original escaped characters in the term
selector = EscapedNodes.getEscapedTerm(fieldNode, new EscapeQuerySyntaxImpl());
type = JexlSelectorNode.Type.WILDCARDS;
} else {
selector = fieldNode.getTextAsString();
type = JexlSelectorNode.Type.EXACT;
}
if (field == null || field.isEmpty()) {
returnNode = new JexlSelectorNode(type, "", selector);
} else {
returnNode = new JexlSelectorNode(type, field, selector);
}
}
return returnNode;
}
use of datawave.query.language.parser.jexl.JexlNode in project datawave by NationalSecurityAgency.
the class GroupQueryNodeBuilder method build.
public JexlNode build(QueryNode queryNode) throws QueryNodeException {
GroupQueryNode groupNode = (GroupQueryNode) queryNode;
JexlNode child = (JexlNode) groupNode.getChild().getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
return new JexlGroupingNode(Collections.singletonList(child));
}
Aggregations