use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class MockBatchScanner method iterator.
@SuppressWarnings("unchecked")
@Override
public Iterator<Entry<Key, Value>> iterator() {
if (ranges == null) {
throw new IllegalStateException("ranges not set");
}
IteratorChain chain = new IteratorChain();
for (Range range : ranges) {
SortedKeyValueIterator<Key, Value> i = new SortedMapIterator(table.table);
try {
i = createFilter(i);
i.seek(range, createColumnBSS(fetchedColumns), !fetchedColumns.isEmpty());
chain.addIterator(new IteratorAdapter(i));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return chain;
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class CollectTabletStats method createScanIterator.
private static SortedKeyValueIterator<Key, Value> createScanIterator(KeyExtent ke, Collection<SortedKeyValueIterator<Key, Value>> mapfiles, Authorizations authorizations, byte[] defaultLabels, HashSet<Column> columnSet, List<IterInfo> ssiList, Map<String, Map<String, String>> ssio, boolean useTableIterators, TableConfiguration conf) throws IOException {
SortedMapIterator smi = new SortedMapIterator(new TreeMap<>());
List<SortedKeyValueIterator<Key, Value>> iters = new ArrayList<>(mapfiles.size() + 1);
iters.addAll(mapfiles);
iters.add(smi);
MultiIterator multiIter = new MultiIterator(iters, ke);
DeletingIterator delIter = new DeletingIterator(multiIter, false);
ColumnFamilySkippingIterator cfsi = new ColumnFamilySkippingIterator(delIter);
SortedKeyValueIterator<Key, Value> colFilter = ColumnQualifierFilter.wrap(cfsi, columnSet);
SortedKeyValueIterator<Key, Value> visFilter = VisibilityFilter.wrap(colFilter, authorizations, defaultLabels);
if (useTableIterators)
return IteratorUtil.loadIterators(IteratorScope.scan, visFilter, ke, conf, ssiList, ssio, null);
return visFilter;
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RegExTest method runTest.
private void runTest(Range range, String rowRegEx, String cfRegEx, String cqRegEx, String valRegEx, int expected) throws Exception {
SortedKeyValueIterator<Key, Value> source = new SortedMapIterator(data);
Set<ByteSequence> es = ImmutableSet.of();
IteratorSetting is = new IteratorSetting(50, "regex", RegExFilter.class);
RegExFilter.setRegexs(is, rowRegEx, cfRegEx, cqRegEx, valRegEx, false);
RegExFilter iter = new RegExFilter();
iter.init(source, is.getOptions(), null);
iter.seek(range, es, false);
runTest(iter, rowRegEx, cfRegEx, cqRegEx, valRegEx, expected);
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class MetadataBulkLoadFilterTest method testBasic.
@Test
public void testBasic() throws IOException {
TreeMap<Key, Value> tm1 = new TreeMap<>();
TreeMap<Key, Value> expected = new TreeMap<>();
// following should not be deleted by filter
put(tm1, "2;m", TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN, "/t1");
put(tm1, "2;m", DataFileColumnFamily.NAME, "/t1/file1", new DataFileValue(1, 1).encodeAsString());
put(tm1, "2;m", TabletsSection.BulkFileColumnFamily.NAME, "/t1/file1", "5");
put(tm1, "2;m", TabletsSection.BulkFileColumnFamily.NAME, "/t1/file3", "7");
put(tm1, "2;m", TabletsSection.BulkFileColumnFamily.NAME, "/t1/file4", "9");
put(tm1, "2<", TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN, "/t2");
put(tm1, "2<", DataFileColumnFamily.NAME, "/t2/file2", new DataFileValue(1, 1).encodeAsString());
put(tm1, "2<", TabletsSection.BulkFileColumnFamily.NAME, "/t2/file6", "5");
put(tm1, "2<", TabletsSection.BulkFileColumnFamily.NAME, "/t2/file7", "7");
put(tm1, "2<", TabletsSection.BulkFileColumnFamily.NAME, "/t2/file8", "9");
put(tm1, "2<", TabletsSection.BulkFileColumnFamily.NAME, "/t2/fileC", null);
expected.putAll(tm1);
// the following should be deleted by filter
put(tm1, "2;m", TabletsSection.BulkFileColumnFamily.NAME, "/t1/file5", "8");
put(tm1, "2<", TabletsSection.BulkFileColumnFamily.NAME, "/t2/file9", "8");
put(tm1, "2<", TabletsSection.BulkFileColumnFamily.NAME, "/t2/fileA", "2");
TestMetadataBulkLoadFilter iter = new TestMetadataBulkLoadFilter();
iter.init(new SortedMapIterator(tm1), new HashMap<>(), new BaseIteratorEnvironment() {
@Override
public boolean isFullMajorCompaction() {
return false;
}
@Override
public IteratorScope getIteratorScope() {
return IteratorScope.majc;
}
});
iter.seek(new Range(), new ArrayList<>(), false);
TreeMap<Key, Value> actual = new TreeMap<>();
while (iter.hasTop()) {
actual.put(iter.getTopKey(), iter.getTopValue());
iter.next();
}
Assert.assertEquals(expected, actual);
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class CombinerTest method testDeepCopy.
@Test
public void testDeepCopy() throws IOException {
Encoder<Long> encoder = LongCombiner.FIXED_LEN_ENCODER;
TreeMap<Key, Value> tm1 = new TreeMap<>();
// keys that aggregate
newKeyValue(tm1, 1, 1, 1, 1, false, 2l, encoder);
newKeyValue(tm1, 1, 1, 1, 2, false, 3l, encoder);
newKeyValue(tm1, 1, 1, 1, 3, false, 4l, encoder);
// keys that do not aggregate
newKeyValue(tm1, 2, 2, 1, 1, false, 2l, encoder);
newKeyValue(tm1, 2, 2, 1, 2, false, 3l, encoder);
Combiner ai = new SummingCombiner();
IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
LongCombiner.setEncodingType(is, FixedLenEncoder.class.getName());
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
SortedKeyValueIterator<Key, Value> ai2 = ai.deepCopy(null);
SortedKeyValueIterator<Key, Value> ai3 = ai.deepCopy(null);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
assertEquals("9", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(2, 2, 1, 2), ai.getTopKey());
assertEquals("3", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(2, 2, 1, 1), ai.getTopKey());
assertEquals("2", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertFalse(ai.hasTop());
// seek after key that aggregates
ai2.seek(newRow(1, 1, 1, 2), EMPTY_COL_FAMS, false);
assertTrue(ai2.hasTop());
assertEquals(newKey(2, 2, 1, 2), ai2.getTopKey());
assertEquals("3", encoder.decode(ai2.getTopValue().get()).toString());
// seek before key that aggregates
ai3.seek(newRow(1, 1, 1, 4), EMPTY_COL_FAMS, false);
assertTrue(ai3.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai3.getTopKey());
assertEquals("9", encoder.decode(ai3.getTopValue().get()).toString());
ai3.next();
assertTrue(ai3.hasTop());
assertEquals(newKey(2, 2, 1, 2), ai3.getTopKey());
assertEquals("3", encoder.decode(ai3.getTopValue().get()).toString());
}
Aggregations