/** * 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 synchronized void init( SortedKeyValueIterator<K, V> source, Map<String, String> options, IteratorEnvironment env) throws IOException { this.source = source; source.init(source, options, env); }
@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); }