Search in sources :

Example 1 with IteratorToSortedKeyValueIterator

use of datawave.query.util.IteratorToSortedKeyValueIterator in project datawave by NationalSecurityAgency.

the class AncestorIndexBuildingVisitor method getSourceIterator.

@Override
protected SortedKeyValueIterator<Key, Value> getSourceIterator(final ASTEQNode node, boolean negation) {
    SortedKeyValueIterator<Key, Value> kvIter = null;
    try {
        if (limitLookup && !negation) {
            final String identifier = JexlASTHelper.getIdentifier(node);
            if (!disableFiEval && fieldsToAggregate.contains(identifier)) {
                final SortedKeyValueIterator<Key, Value> baseIterator = source.deepCopy(env);
                kvIter = new AncestorChildExpansionIterator(baseIterator, getMembers(), equality);
                seekIndexOnlyDocument(kvIter, node);
            } else {
                kvIter = new IteratorToSortedKeyValueIterator(getNodeEntry(node).iterator());
            }
        } else {
            kvIter = source.deepCopy(env);
            seekIndexOnlyDocument(kvIter, node);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return kvIter;
}
Also used : IteratorToSortedKeyValueIterator(datawave.query.util.IteratorToSortedKeyValueIterator) Value(org.apache.accumulo.core.data.Value) IOException(java.io.IOException) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 2 with IteratorToSortedKeyValueIterator

use of datawave.query.util.IteratorToSortedKeyValueIterator in project datawave by NationalSecurityAgency.

the class IteratorBuildingVisitor method createExceededCheck.

/**
 * This method should only be used when we know it is not a term frequency or index only in the limited case, as we will subsequently evaluate this
 * expression during final evaluation
 *
 * @param identifier
 * @param range
 * @return
 */
protected NestedIterator<Key> createExceededCheck(String identifier, LiteralRange<?> range, JexlNode rootNode) {
    IndexIteratorBuilder builder = null;
    try {
        builder = iteratorBuilderClass.asSubclass(IndexIteratorBuilder.class).newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    IteratorToSortedKeyValueIterator kvIter = new IteratorToSortedKeyValueIterator(getExceededEntry(identifier, range).iterator());
    builder.setQueryId(queryId);
    builder.setSource(kvIter);
    builder.setValue(null != range.getLower() ? range.getLower().toString() : "null");
    builder.setField(identifier);
    builder.setTimeFilter(TimeFilter.alwaysTrue());
    builder.setTypeMetadata(typeMetadata);
    builder.setFieldsToAggregate(fieldsToAggregate);
    builder.setDatatypeFilter(datatypeFilter);
    builder.setKeyTransform(fiAggregator);
    builder.setEnv(env);
    builder.setNode(rootNode);
    return builder.build();
}
Also used : IndexIteratorBuilder(datawave.query.iterator.builder.IndexIteratorBuilder) IteratorToSortedKeyValueIterator(datawave.query.util.IteratorToSortedKeyValueIterator)

Example 3 with IteratorToSortedKeyValueIterator

use of datawave.query.util.IteratorToSortedKeyValueIterator in project datawave by NationalSecurityAgency.

the class AncestorChildExpansionIteratorTest method testFamilyMatch.

@Test
public void testFamilyMatch() throws IOException {
    baseValues.add(new AbstractMap.SimpleImmutableEntry<>(generateFiKey("a.1"), new Value()));
    baseIterator = new IteratorToSortedKeyValueIterator(baseValues.iterator());
    iterator = new AncestorChildExpansionIterator(baseIterator, children, equality);
    iterator.seek(new Range(), Collections.EMPTY_LIST, false);
    Assert.assertTrue(iterator.hasTop());
    Key topKey = iterator.getTopKey();
    assertKey(topKey, "a.1");
    Value topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.1.1");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.1.2");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.1.2.1");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertFalse(iterator.hasTop());
}
Also used : AbstractMap(java.util.AbstractMap) IteratorToSortedKeyValueIterator(datawave.query.util.IteratorToSortedKeyValueIterator) Value(org.apache.accumulo.core.data.Value) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 4 with IteratorToSortedKeyValueIterator

use of datawave.query.util.IteratorToSortedKeyValueIterator in project datawave by NationalSecurityAgency.

the class AncestorChildExpansionIteratorTest method testMultipleGappedRanges.

@Test
public void testMultipleGappedRanges() throws IOException {
    baseValues.add(new AbstractMap.SimpleImmutableEntry<>(generateFiKey("a.1"), new Value()));
    baseValues.add(new AbstractMap.SimpleImmutableEntry<>(generateFiKey("a.3"), new Value()));
    baseValues.add(new AbstractMap.SimpleImmutableEntry<>(generateFiKey("a.4.1.1"), new Value()));
    baseValues.add(new AbstractMap.SimpleImmutableEntry<>(generateFiKey("a.9"), new Value()));
    baseIterator = new IteratorToSortedKeyValueIterator(baseValues.iterator());
    iterator = new AncestorChildExpansionIterator(baseIterator, children, equality);
    iterator.seek(new Range(), Collections.EMPTY_LIST, false);
    Assert.assertTrue(iterator.hasTop());
    Key topKey = iterator.getTopKey();
    assertKey(topKey, "a.1");
    Value topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.1.1");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.1.2");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.1.2.1");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.3");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.4.1.1");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.9");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertFalse(iterator.hasTop());
}
Also used : AbstractMap(java.util.AbstractMap) IteratorToSortedKeyValueIterator(datawave.query.util.IteratorToSortedKeyValueIterator) Value(org.apache.accumulo.core.data.Value) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 5 with IteratorToSortedKeyValueIterator

use of datawave.query.util.IteratorToSortedKeyValueIterator in project datawave by NationalSecurityAgency.

the class AncestorChildExpansionIteratorTest method testFamilyMatchWithOverlaps.

@Test
public void testFamilyMatchWithOverlaps() throws IOException {
    baseValues.add(new AbstractMap.SimpleImmutableEntry<>(generateFiKey("a.1"), new Value()));
    baseValues.add(new AbstractMap.SimpleImmutableEntry<>(generateFiKey("a.1.1"), new Value()));
    baseValues.add(new AbstractMap.SimpleImmutableEntry<>(generateFiKey("a.1.2.1"), new Value()));
    baseIterator = new IteratorToSortedKeyValueIterator(baseValues.iterator());
    iterator = new AncestorChildExpansionIterator(baseIterator, children, equality);
    iterator.seek(new Range(), Collections.EMPTY_LIST, false);
    Assert.assertTrue(iterator.hasTop());
    Key topKey = iterator.getTopKey();
    assertKey(topKey, "a.1");
    Value topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.1.1");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.1.2");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertTrue(iterator.hasTop());
    topKey = iterator.getTopKey();
    assertKey(topKey, "a.1.2.1");
    topValue = iterator.getTopValue();
    Assert.assertNotNull(topValue);
    iterator.next();
    Assert.assertFalse(iterator.hasTop());
}
Also used : AbstractMap(java.util.AbstractMap) IteratorToSortedKeyValueIterator(datawave.query.util.IteratorToSortedKeyValueIterator) Value(org.apache.accumulo.core.data.Value) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Aggregations

IteratorToSortedKeyValueIterator (datawave.query.util.IteratorToSortedKeyValueIterator)11 Key (org.apache.accumulo.core.data.Key)9 Value (org.apache.accumulo.core.data.Value)9 Range (org.apache.accumulo.core.data.Range)7 AbstractMap (java.util.AbstractMap)5 Test (org.junit.Test)5 PartialKey (org.apache.accumulo.core.data.PartialKey)4 IdentifierOpLiteral (datawave.query.jexl.JexlASTHelper.IdentifierOpLiteral)2 LiteralRange (datawave.query.jexl.LiteralRange)2 IOException (java.io.IOException)2 Entry (java.util.Map.Entry)2 DatawaveKey (datawave.query.data.parsers.DatawaveKey)1 AncestorEquality (datawave.query.function.AncestorEquality)1 IndexIteratorBuilder (datawave.query.iterator.builder.IndexIteratorBuilder)1 Before (org.junit.Before)1