/** * For use within an iterator stack. Apply an appropriate column filter based on the input string. * Four modes of operation: 1. Null or blank ("") `colFilter`: do nothing. 2. No ranges * `colFilter`: use Accumulo system ColumnQualifierFilter. 3. Singleton range `colFilter`: use * Accumulo user ColumnSliceFilter. 4. Multi-range `colFilter`: use Graphulo D4mRangeFilter. * * @param colFilter column filter string * @param skvi Parent / source iterator * @return SKVI with appropriate filter iterators placed in front of it. */ public static SortedKeyValueIterator<Key, Value> applyGeneralColumnFilter( String colFilter, SortedKeyValueIterator<Key, Value> skvi, IteratorEnvironment env) throws IOException { if (colFilter == null || colFilter.isEmpty()) return skvi; int pos1 = colFilter.indexOf(':'); if (pos1 == -1) { // no ranges - collection of singleton texts Set<Column> colset = new HashSet<>(); for (Text text : GraphuloUtil.d4mRowToTexts(colFilter)) { byte[] by = text.copyBytes(); // log.debug("Printing characters of string TEXT LIM: "+ Key.toPrintableString(by, 0, // text.getLength(), 100)); // log.debug("Printing characters of string TEXT : "+ Key.toPrintableString(by, 0, // by.length, 100)); colset.add(new Column(EMPTY_BYTES, text.copyBytes(), EMPTY_BYTES)); } return new ColumnQualifierFilter(skvi, colset); } else { SortedSet<Range> ranges = GraphuloUtil.d4mRowToRanges(colFilter); assert ranges.size() > 0; if (ranges.size() == 1) { // single range - use ColumnSliceFilter Range r = ranges.first(); Map<String, String> map = new HashMap<>(); String start = r.isInfiniteStartKey() ? null : r.getStartKey().getRow().toString(), end = r.isInfiniteStopKey() ? null : r.getEndKey().getRow().toString(); boolean startInclusive = true, endInclusive = true; if (start != null) map.put(ColumnSliceFilter.START_BOUND, start); if (end != null) map.put(ColumnSliceFilter.END_BOUND, end); map.put(ColumnSliceFilter.START_INCLUSIVE, String.valueOf(startInclusive)); map.put(ColumnSliceFilter.END_INCLUSIVE, String.valueOf(endInclusive)); SortedKeyValueIterator<Key, Value> filter = new ColumnSliceFilter(); filter.init(skvi, map, env); return filter; } else { // multiple ranges SortedKeyValueIterator<Key, Value> filter = new D4mRangeFilter(); filter.init( skvi, D4mRangeFilter.iteratorSetting(1, D4mRangeFilter.KeyPart.COLQ, colFilter).getOptions(), env); return filter; } } }
@Override public void seek( final Range range, final Collection<ByteSequence> columnFamilies, final boolean inclusive) throws IOException { source.seek(range, columnFamilies, inclusive); findTop(); }
@Override public synchronized void init( SortedKeyValueIterator<K, V> source, Map<String, String> options, IteratorEnvironment env) throws IOException { this.source = source; source.init(source, options, env); }
private void findTop() { topKey = null; topValue = null; while (source.hasTop()) { if (inBounds(source.getTopKey())) { topKey = source.getTopKey(); topValue = source.getTopValue(); return; } else { try { source.next(); } catch (final IOException e) { throw new RuntimeException(e); } } } }
@Override public SortedKeyValueIterator<Key, Value> deepCopy(final IteratorEnvironment env) { final NumericIndexStrategyFilterIterator iterator = new NumericIndexStrategyFilterIterator(); iterator.indexStrategy = indexStrategy; iterator.rangeCache = rangeCache; iterator.source = source.deepCopy(env); return iterator; }
@Override public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException { if (!range.isInfiniteStartKey() || !range.isInfiniteStopKey()) log.warn("Range is not infinite: " + range); source.seek(range, columnFamilies, inclusive); IteratorAdapter ia = new IteratorAdapter(source); SortedMap<Key, Value> map = MemMatrixUtil.matrixToMap( new TreeMap<Key, Value>(), MemMatrixUtil.doInverse(MemMatrixUtil.buildMatrix(ia, matrixSize), numIterations)); // DebugUtil.printMapFull(map.entrySet().iterator()); mapIterator = new MapIterator(map); mapIterator.init(null, null, null); mapIterator.seek(range, columnFamilies, inclusive); }
public static Map.Entry<Key, Value> copyTopEntry(SortedKeyValueIterator<Key, Value> skvi) { final Key k = keyCopy(skvi.getTopKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME_DEL); final Value v = new Value(skvi.getTopValue()); return new Map.Entry<Key, Value>() { @Override public Key getKey() { return k; } @Override public Value getValue() { return v; } @Override public Value setValue(Value value) { throw new UnsupportedOperationException(); } }; }
@Override public Iterator<Entry<Key, Value>> iterator() { smi.scanner.setBatchSize(size); smi.scanner.setTimeout(timeOut, TimeUnit.MILLISECONDS); if (isolated) smi.scanner.enableIsolation(); else smi.scanner.disableIsolation(); final TreeMap<Integer, IterInfo> tm = new TreeMap<Integer, IterInfo>(); for (IterInfo iterInfo : serverSideIteratorList) { tm.put(iterInfo.getPriority(), iterInfo); } SortedKeyValueIterator<Key, Value> skvi; try { skvi = IteratorUtil.loadIterators( smi, tm.values(), serverSideIteratorOptions, new IteratorEnvironment() { @Override public SortedKeyValueIterator<Key, Value> reserveMapFileReader( final String mapFileName) throws IOException { return null; } @Override public AccumuloConfiguration getConfig() { return null; } @Override public IteratorScope getIteratorScope() { return null; } @Override public boolean isFullMajorCompaction() { return false; } @Override public void registerSideChannel(final SortedKeyValueIterator<Key, Value> iter) {} }, false, null); } catch (IOException e) { throw new RuntimeException(e); } final Set<ByteSequence> colfs = new TreeSet<ByteSequence>(); for (Column c : this.getFetchedColumns()) { colfs.add(new ArrayByteSequence(c.getColumnFamily())); } try { skvi.seek(range, colfs, true); } catch (IOException e) { throw new RuntimeException(e); } return new IteratorAdapter(skvi); }
@Override public synchronized boolean hasTop() { return source.hasTop(); }
@Override public void next() throws IOException { source.next(); findTop(); }
@Override public synchronized void next() throws IOException { source.next(); }
@Override public synchronized void seek( Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException { source.seek(range, columnFamilies, inclusive); }
@Override public void next() throws IOException { mapIterator.next(); }
@Override public boolean hasTop() { return mapIterator.hasTop(); }
@Override public Value getTopValue() { return mapIterator.getTopValue(); }
@Override public Key getTopKey() { return mapIterator.getTopKey(); }
@Override public synchronized SortedKeyValueIterator<K, V> deepCopy(IteratorEnvironment env) { return new SynchronizedIterator<K, V>(source.deepCopy(env)); }
@Override public synchronized V getTopValue() { return source.getTopValue(); }
@Override public synchronized K getTopKey() { return source.getTopKey(); }