startRow = scan.getStartRow(); includeStartRow = scan.includeStartRow(); stopRow = scan.getStopRow(); includeStopRow = scan.includeStopRow(); maxVersions = scan.getMaxVersions(); for (Map.Entry<byte[], TimeRange> entry : scan.getColumnFamilyTimeRange().entrySet()) { TimeRange tr = entry.getValue(); setColumnFamilyTimeRange(entry.getKey(), tr.getMin(), tr.getMax()); this.mvccReadPoint = scan.getMvccReadPoint();
/** * Get versions of columns only within the specified timestamp range, * [minStamp, maxStamp). * @param minStamp minimum timestamp value, inclusive * @param maxStamp maximum timestamp value, exclusive * @throws IOException * @return this for invocation chaining */ public Get setTimeRange(long minStamp, long maxStamp) throws IOException { tr = new TimeRange(minStamp, maxStamp); return this; }
/** * Represents interval [minStamp, maxStamp) * @param minStamp the minimum timestamp, inclusive * @param maxStamp the maximum timestamp, exclusive * @throws IllegalArgumentException if either <0, * @deprecated This is made @InterfaceAudience.Private in the 2.0 line and above and may be * changed to private or removed in 3.0. */ @Deprecated @InterfaceAudience.Private public TimeRange(long minStamp, long maxStamp) { check(minStamp, maxStamp); this.minStamp = minStamp; this.maxStamp = maxStamp; this.allTime = isAllTime(minStamp, maxStamp); }
/** * Check if this storeFile may contain keys within the TimeRange that * have not expired (i.e. not older than oldestUnexpiredTS). * @param tr the timeRange to restrict * @param oldestUnexpiredTS the oldest timestamp that is not expired, as * determined by the column family's TTL * @return false if queried keys definitely don't exist in this StoreFile */ boolean passesTimerangeFilter(TimeRange tr, long oldestUnexpiredTS) { return this.timeRange == null? true: this.timeRange.includesTimeRange(tr) && this.timeRange.getMax() >= oldestUnexpiredTS; }
/** * Check if the range has any overlap with TimeRange * @param tr TimeRange * @return True if there is overlap, false otherwise */ // This method came from TimeRangeTracker. We used to go there for this function but better // to come here to the immutable, unsynchronized datastructure at read time. public boolean includesTimeRange(final TimeRange tr) { if (this.allTime) { return true; } assert tr.getMin() >= 0; return getMin() < tr.getMax() && getMax() >= tr.getMin(); }
.setRowOffsetPerColumnFamily(5) .setTimeRange(0, 13) .setAttribute("att_v0", Bytes.toBytes("att_v0")) .setColumnFamilyTimeRange(Bytes.toBytes("cf"), 0, 123) .setReplicaId(3) .setACL("test_user", new Permission(Permission.Action.READ)) .setPriority(3); Scan scan = new Scan(get); assertEquals(get.getCacheBlocks(), scan.getCacheBlocks()); assertEquals(get.getConsistency(), scan.getConsistency()); assertEquals(get.getFilter(), scan.getFilter()); assertEquals(get.getId(), scan.getId()); assertEquals(get.getMaxVersions(), scan.getMaxVersions()); assertEquals(get.getRowOffsetPerColumnFamily(), scan.getRowOffsetPerColumnFamily()); assertEquals(get.getTimeRange().getMin(), scan.getTimeRange().getMin()); assertEquals(get.getTimeRange().getMax(), scan.getTimeRange().getMax()); assertTrue(Bytes.equals(get.getAttribute("att_v0"), scan.getAttribute("att_v0"))); assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin(), scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin()); assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMax(), scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMax()); assertEquals(get.getReplicaId(), scan.getReplicaId()); assertEquals(get.getACL(), scan.getACL());
new Scan().withStartRow(startRow, includeStartRow).withStopRow(stopRow, includeStopRow); if (proto.hasCacheBlocks()) { scan.setCacheBlocks(proto.getCacheBlocks()); TimeRange timeRange = protoToTimeRange(cftr.getTimeRange()); scan.setColumnFamilyTimeRange(cftr.getColumnFamily().toByteArray(), timeRange.getMin(), timeRange.getMax()); scan.setTimeRange(timeRange.getMin(), timeRange.getMax());
int maxVersions = 2; Scan scan = new Scan(startRow, stopRow); scan.addColumn(fam, qf1); scan.setTimeRange(ts, ts+1); scan.setMaxVersions(maxVersions); Scan desScan = ProtobufUtil.toScan(scanProto); assertTrue(Bytes.equals(scan.getStartRow(), desScan.getStartRow())); assertTrue(Bytes.equals(scan.getStopRow(), desScan.getStopRow())); assertEquals(scan.getCacheBlocks(), desScan.getCacheBlocks()); Set<byte[]> set = null; scan = new Scan(startRow); final String name = "testScan"; byte [] prefix = Bytes.toBytes(name); scan.setFilter(new PrefixFilter(prefix)); scanProto = ProtobufUtil.toScan(scan); TimeRange tr = scan.getTimeRange(); TimeRange desTr = desScan.getTimeRange(); assertEquals(tr.getMax(), desTr.getMax()); assertEquals(tr.getMin(), desTr.getMin());
if (proto == null) return null; byte[] row = proto.getRow().toByteArray(); Get get = new Get(row); if (proto.hasCacheBlocks()) { get.setCacheBlocks(proto.getCacheBlocks()); get.setMaxVersions(proto.getMaxVersions()); TimeRange timeRange = protoToTimeRange(cftr.getTimeRange()); get.setColumnFamilyTimeRange(cftr.getColumnFamily().toByteArray(), timeRange.getMin(), timeRange.getMax()); get.setTimeRange(timeRange.getMin(), timeRange.getMax());
public static TScan scanFromHBase(Scan in) throws IOException { TScan out = new TScan(); out.setStartRow(in.getStartRow()); out.setStopRow(in.getStopRow()); out.setCaching(in.getCaching()); out.setMaxVersions(in.getMaxVersions()); for (Map.Entry<byte[], NavigableSet<byte[]>> family : in.getFamilyMap().entrySet()) { tTimeRange.setMinStamp(in.getTimeRange().getMin()).setMaxStamp(in.getTimeRange().getMax()); out.setTimeRange(tTimeRange); out.setBatchSize(in.getBatch()); for (Map.Entry<String, byte[]> attribute : in.getAttributesMap().entrySet()) { out.putToAttributes(ByteBuffer.wrap(Bytes.toBytes(attribute.getKey())), ByteBuffer.wrap(attribute.getValue())); if (entry.getValue() != null) { TTimeRange timeRange = new TTimeRange(); timeRange.setMinStamp(entry.getValue().getMin()).setMaxStamp(entry.getValue().getMax()); out.putToColFamTimeRangeMap(ByteBuffer.wrap(entry.getKey()), timeRange);
this(get.getRow()); this.setFilter(get.getFilter()); this.setReplicaId(get.getReplicaId()); this.setConsistency(get.getConsistency()); for (Map.Entry<byte[], TimeRange> entry : get.getColumnFamilyTimeRange().entrySet()) { TimeRange tr = entry.getValue(); setColumnFamilyTimeRange(entry.getKey(), tr.getMin(), tr.getMax()); super.setPriority(get.getPriority());
@Test public void testGet() throws Exception{ byte[] row = "row".getBytes(); byte[] fam = "fam".getBytes(); byte[] qf1 = "qf1".getBytes(); long ts = System.currentTimeMillis(); int maxVersions = 2; Get get = new Get(row); get.addColumn(fam, qf1); get.setTimeRange(ts, ts+1); get.setMaxVersions(maxVersions); ClientProtos.Get getProto = ProtobufUtil.toGet(get); Get desGet = ProtobufUtil.toGet(getProto); assertTrue(Bytes.equals(get.getRow(), desGet.getRow())); Set<byte[]> set = null; Set<byte[]> desSet = null; for(Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()){ assertTrue(desGet.getFamilyMap().containsKey(entry.getKey())); set = entry.getValue(); desSet = desGet.getFamilyMap().get(entry.getKey()); for(byte [] qualifier : set){ assertTrue(desSet.contains(qualifier)); } } assertEquals(get.getMaxVersions(), desGet.getMaxVersions()); TimeRange tr = get.getTimeRange(); TimeRange desTr = desGet.getTimeRange(); assertEquals(tr.getMax(), desTr.getMax()); assertEquals(tr.getMin(), desTr.getMin()); }
get = new Get(Bytes.copy(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())); get.addColumn( Bytes.copy(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()), Bytes.copy(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())); get = new Get(row); for (ColumnValue column : proto.getColumnValueList()) { byte[] family = column.getFamily().toByteArray(); get.setTimeRange(timeRange.getMin(), timeRange.getMax());
public static TGet getFromHBase(Get in) { TGet out = new TGet(); out.setRow(in.getRow()); tTimeRange.setMaxStamp(in.getTimeRange().getMax()).setMinStamp(in.getTimeRange().getMin()); out.setTimeRange(tTimeRange); out.setMaxVersions(in.getMaxVersions()); for (Map.Entry<String, byte[]> attribute : in.getAttributesMap().entrySet()) { out.putToAttributes(ByteBuffer.wrap(Bytes.toBytes(attribute.getKey())), ByteBuffer.wrap(attribute.getValue()));
private void checkHTableInterfaceMethods() throws Exception { long time = EnvironmentEdgeManager.currentTime(); mee.setValue(time); hTableInterface.put(new Put(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, Bytes.toBytes(1L))); checkRowValue(ROW_A, Bytes.toBytes(1L)); TimeRange range10 = new TimeRange(1, time+10); hTableInterface.increment(new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 10L) .setTimeRange(range10.getMin(), range10.getMax())); checkRowValue(ROW_A, Bytes.toBytes(11L)); assertEquals(MyObserver.tr10.getMin(), range10.getMin()); assertEquals(MyObserver.tr10.getMax(), range10.getMax()); TimeRange range2 = new TimeRange(1, time+20); List<Row> actions = Arrays.asList(new Row[] { new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L) .setTimeRange(range2.getMin(), range2.getMax()), new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L) .setTimeRange(range2.getMin(), range2.getMax()) }); Object[] results3 = new Object[actions.size()]; Object[] results1 = results3; hTableInterface.batch(actions, results1); assertEquals(MyObserver.tr2.getMin(), range2.getMin()); assertEquals(MyObserver.tr2.getMax(), range2.getMax()); for (Object r2 : results1) { assertTrue(r2 instanceof Result);
/** {@inheritDoc} */ @Override public void adapt(Increment operation, ReadModifyWriteRow readModifyWriteRow) { if (!operation.getTimeRange().isAllTime()) { throw new UnsupportedOperationException( "Setting the time range in an Increment is not implemented"); } for (Map.Entry<byte[], NavigableMap<byte[], Long>> familyEntry : operation.getFamilyMapOfLongs().entrySet()) { String familyName = Bytes.toString(familyEntry.getKey()); // Bigtable applies all increments present in a single RPC. HBase applies only the last // mutation present, if any. We remove all but the last mutation for each qualifier here: List<Cell> mutationCells = CellDeduplicationHelper.deduplicateFamily(operation, familyEntry.getKey()); for (Cell cell : mutationCells) { readModifyWriteRow.increment( familyName, ByteString.copyFrom( cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()), Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()) ); } } } }
/** * Do a specific Get on passed <code>columnFamily</code> and column qualifiers. * @param mutation Mutation we are doing this Get for. * @param store Which column family on row (TODO: Go all Gets in one go) * @param coordinates Cells from <code>mutation</code> used as coordinates applied to Get. * @return Return list of Cells found. */ private List<Cell> get(Mutation mutation, HStore store, List<Cell> coordinates, IsolationLevel isolation, TimeRange tr) throws IOException { // Sort the cells so that they match the order that they appear in the Get results. Otherwise, // we won't be able to find the existing values if the cells are not specified in order by the // client since cells are in an array list. // TODO: I don't get why we are sorting. St.Ack 20150107 sort(coordinates, store.getComparator()); Get get = new Get(mutation.getRow()); if (isolation != null) { get.setIsolationLevel(isolation); } for (Cell cell: coordinates) { get.addColumn(store.getColumnFamilyDescriptor().getName(), CellUtil.cloneQualifier(cell)); } // Increments carry time range. If an Increment instance, put it on the Get. if (tr != null) { get.setTimeRange(tr.getMin(), tr.getMax()); } return get(get, false); }
model.setStartRow(scan.getStartRow()); model.setEndRow(scan.getStopRow()); Map<byte [], NavigableSet<byte []>> families = scan.getFamilyMap(); if (families != null) { for (Map.Entry<byte [], NavigableSet<byte []>> entry : families.entrySet()) { if (entry.getValue() != null) { for (byte[] qualifier: entry.getValue()) { model.addColumn(Bytes.add(entry.getKey(), COLUMN_DIVIDER, qualifier)); model.setStartTime(scan.getTimeRange().getMin()); model.setEndTime(scan.getTimeRange().getMax()); int caching = scan.getCaching(); if (caching > 0) {
ClientProtos.Scan.Builder scanBuilder = ClientProtos.Scan.newBuilder(); scanBuilder.setCacheBlocks(scan.getCacheBlocks()); if (scan.getBatch() > 0) { scanBuilder.setBatchSize(scan.getBatch()); if (scan.getMaxResultSize() > 0) { TimeRange timeRange = scan.getTimeRange(); if (!timeRange.isAllTime()) { HBaseProtos.TimeRange.Builder timeRangeBuilder = HBaseProtos.TimeRange.newBuilder(); timeRangeBuilder.setFrom(timeRange.getMin()); timeRangeBuilder.setTo(timeRange.getMax()); scanBuilder.setTimeRange(timeRangeBuilder.build());