/** * Encode columns and NOT flags indicating which columns should be negated (docIDs will be * excluded if matching negated columns, instead of included). */ public static void setColumnFamilies(IteratorSetting cfg, Text[] columns, boolean[] notFlags) { if (columns.length < 1) throw new IllegalArgumentException("Must supply at least one terms to intersect"); if (columns.length != notFlags.length) throw new IllegalArgumentException("columns and notFlags arrays must be the same length"); setColumnFamilies(cfg, columns); cfg.addOption(IntersectingIterator.notFlagOptionName, IntersectingIterator.encodeBooleans(notFlags)); } }
@Override public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) { return new IntersectingIterator(this, env); }
@Override public void seek(Range range, Collection<ByteSequence> seekColumnFamilies, boolean inclusive) throws IOException { overallRange = new Range(range); currentPartition = new Text(); currentDocID.set(emptyByteArray); // seek each of the sources to the right column family within the row given by key for (int i = 0; i < sourcesCount; i++) { Key sourceKey; if (range.getStartKey() != null) { if (range.getStartKey().getColumnQualifier() != null) { sourceKey = buildKey(getPartition(range.getStartKey()), sources[i].term, range.getStartKey().getColumnQualifier()); } else { sourceKey = buildKey(getPartition(range.getStartKey()), sources[i].term); } // Seek only to the term for this source as a column family sources[i].iter.seek(new Range(sourceKey, true, null, false), sources[i].seekColfams, true); } else { // Seek only to the term for this source as a column family sources[i].iter.seek(range, sources[i].seekColfams, true); } } advanceToIntersection(); }
protected void advanceToIntersection() throws IOException { boolean cursorChanged = true; while (cursorChanged) { // seek all of the sources to at least the highest seen column qualifier in the current row cursorChanged = false; for (int i = 0; i < sourcesCount; i++) { if (currentPartition == null) { topKey = null; return; } if (seekOneSource(i)) { cursorChanged = true; break; } } } topKey = buildKey(currentPartition, nullText, currentDocID); }
@Override public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { Text[] terms = decodeColumns(options.get(columnFamiliesOptionName)); boolean[] notFlag = decodeBooleans(options.get(notFlagOptionName));
IntersectingIterator.setColumnFamilies(ii, columns); bs.addScanIterator(ii); bs.setRanges(Collections.singleton(new Range()));
.compareTo(getPartition(sources[sourceID].iter.getTopKey())); Key seekKey = buildKey(currentPartition, sources[sourceID].term); sources[sourceID].iter.seek(new Range(seekKey, true, null, false), sources[sourceID].seekColfams, true); .compareTo(getTerm(sources[sourceID].iter.getTopKey())); Key seekKey = buildKey(currentPartition, sources[sourceID].term, currentDocID); sources[sourceID].iter.seek(new Range(seekKey, true, null, false), sources[sourceID].seekColfams, true); Text docID = getDocID(sources[sourceID].iter.getTopKey()); int docIDCompare = currentDocID.compareTo(docID); Key seekKey = buildKey(currentPartition, sources[sourceID].term, currentDocID); sources[sourceID].iter.seek(new Range(seekKey, true, null, false), sources[sourceID].seekColfams, true); .compareTo(getPartition(sources[sourceID].iter.getTopKey())); Key seekKey = buildKey(currentPartition, sources[sourceID].term); sources[sourceID].iter.seek(new Range(seekKey, true, null, false), sources[sourceID].seekColfams, true); currentPartition.set(getPartition(sources[sourceID].iter.getTopKey())); currentDocID.set(emptyByteArray); advancedCursor = true;
@Override public void next() throws IOException { if (currentPartition == null) { return; } // precondition: the current row is set up and the sources all have the same column qualifier // while we don't have a match, seek in the source with the smallest column qualifier sources[0].iter.next(); advanceToIntersection(); }
/** * Encode the columns to be used when iterating. */ public static void setColumnFamilies(IteratorSetting cfg, Text[] columns) { if (columns.length < 1) throw new IllegalArgumentException("Must supply at least one term to intersect"); cfg.addOption(IntersectingIterator.columnFamiliesOptionName, IntersectingIterator.encodeColumns(columns)); }
IntersectingIterator.setColumnFamilies(ii, columns); bs.addScanIterator(ii); bs.setRanges(Collections.singleton(new Range()));
.compareTo(getPartition(sources[sourceID].iter.getTopKey())); Key seekKey = buildKey(currentPartition, sources[sourceID].term); sources[sourceID].iter.seek(new Range(seekKey, true, null, false), sources[sourceID].seekColfams, true); .compareTo(getTerm(sources[sourceID].iter.getTopKey())); Key seekKey = buildKey(currentPartition, sources[sourceID].term, currentDocID); sources[sourceID].iter.seek(new Range(seekKey, true, null, false), sources[sourceID].seekColfams, true); Text docID = getDocID(sources[sourceID].iter.getTopKey()); int docIDCompare = currentDocID.compareTo(docID); Key seekKey = buildKey(currentPartition, sources[sourceID].term, currentDocID); sources[sourceID].iter.seek(new Range(seekKey, true, null, false), sources[sourceID].seekColfams, true); .compareTo(getPartition(sources[sourceID].iter.getTopKey())); Key seekKey = buildKey(currentPartition, sources[sourceID].term); sources[sourceID].iter.seek(new Range(seekKey, true, null, false), sources[sourceID].seekColfams, true); currentPartition.set(getPartition(sources[sourceID].iter.getTopKey())); currentDocID.set(emptyByteArray); advancedCursor = true;
protected void advanceToIntersection() throws IOException { boolean cursorChanged = true; while (cursorChanged) { // seek all of the sources to at least the highest seen column qualifier in the current row cursorChanged = false; for (int i = 0; i < sourcesCount; i++) { if (currentPartition == null) { topKey = null; return; } if (seekOneSource(i)) { cursorChanged = true; break; } } } topKey = buildKey(currentPartition, nullText, currentDocID); }
@Override public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { Text[] terms = decodeColumns(options.get(columnFamiliesOptionName)); boolean[] notFlag = decodeBooleans(options.get(notFlagOptionName));
@Override protected void advanceToIntersection() throws IOException { super.advanceToIntersection(); if (topKey == null) return; if (log.isTraceEnabled()) log.trace("using top key to seek for doc: {}", topKey); Key docKey = buildDocKey(); docSource.seek(new Range(docKey, true, null, false), docColfSet, true); log.debug("got doc key: {}", docSource.getTopKey()); if (docSource.hasTop() && docKey.equals(docSource.getTopKey(), PartialKey.ROW_COLFAM_COLQUAL)) { value = docSource.getTopValue(); } log.debug("got doc value: {}", value); }
/** * Encode the columns to be used when iterating. */ public static void setColumnFamilies(IteratorSetting cfg, Text[] columns) { if (columns.length < 1) throw new IllegalArgumentException("Must supply at least one term to intersect"); cfg.addOption(IntersectingIterator.columnFamiliesOptionName, IntersectingIterator.encodeColumns(columns)); }
10); IteratorSetting ii = new IteratorSetting(20, "ii", IntersectingIterator.class); IntersectingIterator.setColumnFamilies(ii, columns); bs.addScanIterator(ii); bs.setRanges(Collections.singleton(new Range()));
/** * Encode columns and NOT flags indicating which columns should be negated (docIDs will be * excluded if matching negated columns, instead of included). */ public static void setColumnFamilies(IteratorSetting cfg, Text[] columns, boolean[] notFlags) { if (columns.length < 1) throw new IllegalArgumentException("Must supply at least one terms to intersect"); if (columns.length != notFlags.length) throw new IllegalArgumentException("columns and notFlags arrays must be the same length"); setColumnFamilies(cfg, columns); cfg.addOption(IntersectingIterator.notFlagOptionName, IntersectingIterator.encodeBooleans(notFlags)); } }
@Override public void seek(Range range, Collection<ByteSequence> seekColumnFamilies, boolean inclusive) throws IOException { overallRange = new Range(range); currentPartition = new Text(); currentDocID.set(emptyByteArray); // seek each of the sources to the right column family within the row given by key for (int i = 0; i < sourcesCount; i++) { Key sourceKey; if (range.getStartKey() != null) { if (range.getStartKey().getColumnQualifier() != null) { sourceKey = buildKey(getPartition(range.getStartKey()), sources[i].term, range.getStartKey().getColumnQualifier()); } else { sourceKey = buildKey(getPartition(range.getStartKey()), sources[i].term); } // Seek only to the term for this source as a column family sources[i].iter.seek(new Range(sourceKey, true, null, false), sources[i].seekColfams, true); } else { // Seek only to the term for this source as a column family sources[i].iter.seek(range, sources[i].seekColfams, true); } } advanceToIntersection(); }
@Override public void next() throws IOException { if (currentPartition == null) { return; } // precondition: the current row is set up and the sources all have the same column qualifier // while we don't have a match, seek in the source with the smallest column qualifier sources[0].iter.next(); advanceToIntersection(); }
@Override public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) { return new IntersectingIterator(this, env); }