private static boolean isExact(Range range) { return !range.isInfiniteStartKey() && !range.isInfiniteStopKey() && range.getStartKey().followingKey(PartialKey.ROW).equals(range.getEndKey()); }
Key end = defaultTabletRow.followingKey(PartialKey.ROW); scanner.setRange(new Range(start, end));
protected Key buildFollowingPartitionKey(Key key) { return key.followingKey(PartialKey.ROW); }
/** * Creates a range that covers an exact row and column family. * * @param row * row row to cover * @param cf * column family to cover */ public static Range exact(Text row, Text cf) { Key startKey = new Key(row, cf); return new Range(startKey, true, startKey.followingKey(PartialKey.ROW_COLFAM), false); }
/** * Creates a range that covers an exact row, column family, and column qualifier. * * @param row * row row to cover * @param cf * column family to cover * @param cq * column qualifier to cover */ public static Range exact(Text row, Text cf, Text cq) { Key startKey = new Key(row, cf, cq); return new Range(startKey, true, startKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL), false); }
/** * Creates a range that covers an exact row, column family, column qualifier, and column * visibility. * * @param row * row row to cover * @param cf * column family to cover * @param cq * column qualifier to cover * @param cv * column visibility to cover */ public static Range exact(Text row, Text cf, Text cq, Text cv) { Key startKey = new Key(row, cf, cq, cv); return new Range(startKey, true, startKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS), false); }
/** * Creates a range that covers an exact row, column family, column qualifier, column visibility, * and timestamp. * * @param row * row row to cover * @param cf * column family to cover * @param cq * column qualifier to cover * @param cv * column visibility to cover * @param ts * timestamp to cover */ public static Range exact(Text row, Text cf, Text cq, Text cv, long ts) { Key startKey = new Key(row, cf, cq, cv, ts); return new Range(startKey, true, startKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME), false); }
@Override public Key getNextKeyHint(Key k, Value v) throws IllegalArgumentException { if (cso.minCf.getLength() > 0) { int minCfCmp = k.compareColumnFamily(cso.minCf); if (minCfCmp < 0) { Key hint = new Key(k.getRow(), cso.minCf); return cso.minInclusive ? hint : hint.followingKey(PartialKey.ROW_COLFAM); } } if (cso.minCq.getLength() > 0) { int minCqCmp = k.compareColumnQualifier(cso.minCq); if (minCqCmp < 0) { Key hint = new Key(k.getRow(), k.getColumnFamily(), cso.minCq); return cso.minInclusive ? hint : hint.followingKey(PartialKey.ROW_COLFAM_COLQUAL); } } // If we get here it means that we were asked to provide a hint for a key that we // didn't return USE_HINT for. throw new IllegalArgumentException("Don't know how to provide hint for key " + k); }
public static SortedMap<FileRef,DataFileValue> getDataFileSizes(KeyExtent extent, ServerContext context) { TreeMap<FileRef,DataFileValue> sizes = new TreeMap<>(); try (Scanner mdScanner = new ScannerImpl(context, MetadataTable.ID, Authorizations.EMPTY)) { mdScanner.fetchColumnFamily(DataFileColumnFamily.NAME); Text row = extent.getMetadataEntry(); Key endKey = new Key(row, DataFileColumnFamily.NAME, new Text("")); endKey = endKey.followingKey(PartialKey.ROW_COLFAM); mdScanner.setRange(new Range(new Key(row), endKey)); for (Entry<Key,Value> entry : mdScanner) { if (!entry.getKey().getRow().equals(row)) break; DataFileValue dfv = new DataFileValue(entry.getValue().get()); sizes.put(new FileRef(context.getVolumeManager(), entry.getKey()), dfv); } return sizes; } }
private void consumeRow(ByteSequence row) throws IOException { // try reading a few and if still not to next row, then seek int count = 0; while (source.hasTop() && source.getTopKey().getRowData().equals(row)) { source.next(); count++; if (count >= 10) { Key nextRowStart = new Key(new Text(row.toArray())).followingKey(PartialKey.ROW); reseek(nextRowStart); count = 0; } } }
private void resetSource() { if (prevTablet == null) { source = iteratorFactory.apply(range); } else { // get the metadata table row for the previous tablet Text prevMetaRow = TabletsSection.getRow(prevTablet.getTableId(), prevTablet.getEndRow()); // ensure the previous tablet still exists in the metadata table if (Iterators.size(iteratorFactory.apply(new Range(prevMetaRow))) == 0) { throw new TabletDeletedException("Tablet " + prevMetaRow + " was deleted while iterating"); } // start scanning at next possible row in metadata table Range seekRange = new Range(new Key(prevMetaRow).followingKey(PartialKey.ROW), true, range.getEndKey(), range.isEndKeyInclusive()); log.info("Resetting scanner to {}", seekRange); source = iteratorFactory.apply(seekRange); } }
public static Range getRange(Table.ID tableId) { return new Range(new Key(tableId.canonicalID() + ';'), true, new Key(tableId.canonicalID() + '<').followingKey(PartialKey.ROW), false); }
/** * Returns a Range that covers all column families beginning with a prefix within a given row. * * @param row * row to cover * @param cfPrefix * prefix of column families to cover */ public static Range prefix(Text row, Text cfPrefix) { Text fp = followingPrefix(cfPrefix); return new Range(new Key(row, cfPrefix), true, fp == null ? new Key(row).followingKey(PartialKey.ROW) : new Key(row, fp), false); }
private void skipRowColumn() throws IOException { Key keyToSkip = currentKey; super.next(); int count = 0; SortedKeyValueIterator<Key,Value> source = getSource(); while (source.hasTop() && source.getTopKey().equals(keyToSkip, PartialKey.ROW_COLFAM_COLQUAL_COLVIS)) { if (count < maxCount) { // it is quicker to call next if we are close, but we never know if we are close // so give next a try a few times source.next(); count++; } else { reseek(keyToSkip.followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS)); count = 0; } } }
static boolean isRangeInBloomFilter(Range range, PartialKey keyDepth) { if (range.getStartKey() == null || range.getEndKey() == null) { return false; } if (range.getStartKey().equals(range.getEndKey(), keyDepth)) return true; // include everything but the deleted flag in the comparison... return range.getStartKey().followingKey(keyDepth).equals(range.getEndKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME) && !range.isEndKeyInclusive(); } }
private static Scanner getTabletLogScanner(ServerContext context, KeyExtent extent) { Table.ID tableId = MetadataTable.ID; if (extent.isMeta()) tableId = RootTable.ID; Scanner scanner = new ScannerImpl(context, tableId, Authorizations.EMPTY); scanner.fetchColumnFamily(LogColumnFamily.NAME); Text start = extent.getMetadataEntry(); Key endKey = new Key(start, LogColumnFamily.NAME); endKey = endKey.followingKey(PartialKey.ROW_COLFAM); scanner.setRange(new Range(new Key(start), endKey)); return scanner; }
/** * Returns a Range that covers all column qualifiers beginning with a prefix within a given row * and column family. * * @param row * row to cover * @param cf * column family to cover * @param cqPrefix * prefix of column qualifiers to cover */ public static Range prefix(Text row, Text cf, Text cqPrefix) { Text fp = followingPrefix(cqPrefix); return new Range(new Key(row, cf, cqPrefix), true, fp == null ? new Key(row, cf).followingKey(PartialKey.ROW_COLFAM) : new Key(row, cf, fp), false); }
@Override public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException { topKey = null; topValue = null; Key sk = range.getStartKey(); if (sk != null && sk.getColumnQualifierData().length() == 0 && sk.getColumnVisibilityData().length() == 0 && sk.getTimestamp() == Long.MAX_VALUE && !range.isStartKeyInclusive()) { // assuming that we are seeking using a key previously returned by // this iterator // therefore go to the next row/cf Key followingRowKey = sk.followingKey(PartialKey.ROW_COLFAM); if (range.getEndKey() != null && followingRowKey.compareTo(range.getEndKey()) > 0) return; range = new Range(sk.followingKey(PartialKey.ROW_COLFAM), true, range.getEndKey(), range.isEndKeyInclusive()); } sourceIter.seek(range, columnFamilies, inclusive); prepKeys(); }
/** * Returns a Range that covers all column visibilities beginning with a prefix within a given row, * column family, and column qualifier. * * @param row * row to cover * @param cf * column family to cover * @param cq * column qualifier to cover * @param cvPrefix * prefix of column visibilities to cover */ public static Range prefix(Text row, Text cf, Text cq, Text cvPrefix) { Text fp = followingPrefix(cvPrefix); return new Range(new Key(row, cf, cq, cvPrefix), true, fp == null ? new Key(row, cf, cq).followingKey(PartialKey.ROW_COLFAM_COLQUAL) : new Key(row, cf, cq, fp), false); }
@Override public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException { topKey = null; topValue = null; Key sk = range.getStartKey(); if (sk != null && sk.getColumnFamilyData().length() == 0 && sk.getColumnQualifierData().length() == 0 && sk.getColumnVisibilityData().length() == 0 && sk.getTimestamp() == Long.MAX_VALUE && !range.isStartKeyInclusive()) { // assuming that we are seeking using a key previously returned by this iterator // therefore go to the next row Key followingRowKey = sk.followingKey(PartialKey.ROW); if (range.getEndKey() != null && followingRowKey.compareTo(range.getEndKey()) > 0) return; range = new Range(sk.followingKey(PartialKey.ROW), true, range.getEndKey(), range.isEndKeyInclusive()); } sourceIter.seek(range, columnFamilies, inclusive); prepKeys(); }