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()])));
}
}
}
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;
}
Aggregations