use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method buildExceededFromTermFrequency.
/**
* @param data
*/
private NestedIterator<Key> buildExceededFromTermFrequency(String identifier, JexlNode rootNode, JexlNode sourceNode, LiteralRange<?> range, Object data) {
if (limitLookup) {
ChainableEventDataQueryFilter wrapped = createWrappedTermFrequencyFilter(identifier, sourceNode, attrFilter);
NestedIterator<Key> eventFieldIterator = new EventFieldIterator(rangeLimiter, source.deepCopy(env), identifier, new AttributeFactory(this.typeMetadata), getEventFieldAggregator(identifier, wrapped));
TermFrequencyIndexBuilder builder = new TermFrequencyIndexBuilder();
builder.setSource(source.deepCopy(env));
builder.setTypeMetadata(typeMetadata);
builder.setFieldsToAggregate(fieldsToAggregate);
builder.setTimeFilter(timeFilter);
builder.setAttrFilter(attrFilter);
builder.setDatatypeFilter(datatypeFilter);
builder.setEnv(env);
builder.setTermFrequencyAggregator(getTermFrequencyAggregator(identifier, sourceNode, attrFilter, attrFilter != null ? attrFilter.getMaxNextCount() : -1));
builder.setNode(rootNode);
Range fiRange = getFiRangeForTF(range);
builder.setRange(fiRange);
builder.setField(identifier);
NestedIterator<Key> tfIterator = builder.build();
OrIterator tfMerge = new OrIterator(Arrays.asList(tfIterator, eventFieldIterator));
return tfMerge;
} else {
QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "buildExceededFromTermFrequency"));
throw new DatawaveFatalQueryException(qe);
}
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method ivarateRange.
/**
* Build the iterator stack using the regex ivarator (field index caching regex iterator)
*
* @param rootNode
* the node that was processed to generated this builder
* @param sourceNode
* the source node derived from the root
* @param data
*/
public void ivarateRange(JexlNode rootNode, JexlNode sourceNode, Object data) throws IOException {
IndexRangeIteratorBuilder builder = new IndexRangeIteratorBuilder();
builder.negateAsNeeded(data);
// hence the "IndexAgnostic" method can be used here
if (sourceNode instanceof ASTAndNode) {
LiteralRange range = JexlASTHelper.findRange().recursively().getRange(sourceNode);
if (range == null) {
QueryException qe = new QueryException(DatawaveErrorCode.MULTIPLE_RANGES_IN_EXPRESSION);
throw new DatawaveFatalQueryException(qe);
}
builder.setRange(range);
} else {
QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "ExceededValueThresholdMarkerJexlNode"));
throw new DatawaveFatalQueryException(qe);
}
builder.forceDocumentBuild(!limitLookup && this.isQueryFullySatisfied);
ivarate(builder, rootNode, sourceNode, data);
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class ExpandCompositeTerms method visitLeafNode.
/**
* The default leaf node visitor, which uses the anded nodes to determine whether a composite can be formed with this leaf node.
*
* @param node
* A leaf node from the original script
* @param eData
* ExpandData, containing ancestor anded nodes, used anded nodes, and a flag indicating whether composites were found
* @return Returns a composite node if one can be made, otherwise returns the original node
*/
private JexlNode visitLeafNode(JexlNode node, ExpandData eData) {
LiteralRange range = JexlASTHelper.findRange().getRange(node);
String fieldName = (range != null) ? range.getFieldName() : JexlASTHelper.getIdentifier(node);
Multimap<String, JexlNode> leafNodes = LinkedHashMultimap.create();
leafNodes.put(fieldName, node);
List<Composite> foundComposites = findComposites(leafNodes, eData.andedNodes, eData.usedAndedNodes);
JexlNode resultNode = node;
// if composites were found, create JexlNodes from them
if (!foundComposites.isEmpty()) {
List<JexlNode> compositeNodes = createCompositeNodes(foundComposites);
if (!compositeNodes.isEmpty()) {
eData.foundComposite = true;
resultNode = createUnwrappedAndNode(compositeNodes);
}
}
return resultNode;
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class ShardIndexQueryTableStaticMethods method getBoundedRangeRange.
/**
* Get the accumulo range for a literal query range. Note that it is assumed that the column family set will include the fieldname.
*
* @param literalRange
* @return
* @throws IllegalRangeArgumentException
*/
public static Range getBoundedRangeRange(LiteralRange<?> literalRange) throws IllegalRangeArgumentException {
String lower = literalRange.getLower().toString(), upper = literalRange.getUpper().toString();
Key startKey = new Key(new Text(lower));
Key endKey = new Key(new Text(literalRange.isUpperInclusive() ? upper + Constants.MAX_UNICODE_STRING : upper));
Range range = null;
try {
range = new Range(startKey, literalRange.isLowerInclusive(), endKey, literalRange.isUpperInclusive());
} catch (IllegalArgumentException e) {
QueryException qe = new QueryException(DatawaveErrorCode.RANGE_CREATE_ERROR, e, MessageFormat.format("{0}", literalRange));
log.debug(qe);
throw new IllegalRangeArgumentException(qe);
}
return range;
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class EventDataQueryExpressionVisitorTest method testNormalizedValuesMatching.
@Test
public void testNormalizedValuesMatching() {
ExpressionFilter f = new ExpressionFilter(attrFactory, "FOO");
f.addFieldValue("BAR");
f.addFieldPattern("BA[YZ]");
f.addFieldRange(new LiteralRange("Y", true, "Z", true, "FOO", LiteralRange.NodeOperand.OR));
f.addFieldRange(new LiteralRange("R", false, "S", false, "FOO", LiteralRange.NodeOperand.OR));
Key k1 = createKey("FOO", "BaR");
Key k2 = createKey("FOO", "baz");
Key k3 = createKey("FOO", "baY");
Key k4 = createKey("FOO", "y");
Key k5 = createKey("FOO", "Y");
Key k6 = createKey("FOO", "yap");
Key k7 = createKey("FOO", "YAP");
Key k8 = createKey("FOO", "z");
Key k9 = createKey("FOO", "Z");
Key k10 = createKey("FOO", "r");
Key k11 = createKey("FOO", "R");
Key k12 = createKey("FOO", "rat");
Key k13 = createKey("FOO", "RAT");
Key k14 = createKey("FOO", "s");
Key k15 = createKey("FOO", "S");
assertTrue(f.apply(k1));
assertTrue(f.apply(k2));
assertTrue(f.apply(k3));
assertTrue(f.apply(k4));
assertTrue(f.apply(k5));
assertTrue(f.apply(k6));
assertTrue(f.apply(k7));
assertTrue(f.apply(k8));
assertTrue(f.apply(k9));
assertFalse(f.apply(k10));
assertFalse(f.apply(k11));
assertTrue(f.apply(k12));
assertTrue(f.apply(k13));
assertFalse(f.apply(k14));
assertFalse(f.apply(k15));
}
Aggregations