public static TimeRange getDescTimeRange( KeyRange lowestKeyRange, KeyRange highestKeyRange, Field f) throws IOException { boolean lowerUnbound = lowestKeyRange.lowerUnbound(); boolean lowerInclusive = lowestKeyRange.isLowerInclusive(); boolean upperUnbound = highestKeyRange.upperUnbound(); boolean upperInclusive = highestKeyRange.isUpperInclusive(); long low = lowerUnbound ? -1 : f.getDataType() .getCodec() .decodeLong(lowestKeyRange.getLowerRange(), 0, SortOrder.DESC); long high = upperUnbound ? -1 : f.getDataType() .getCodec() .decodeLong(highestKeyRange.getUpperRange(), 0, SortOrder.DESC); long newHigh; long newLow; if (!lowerUnbound && !upperUnbound) { newHigh = lowerInclusive ? safelyIncrement(low) : low; newLow = upperInclusive ? high : safelyIncrement(high); return new TimeRange(newLow, newHigh); } else if (!lowerUnbound && upperUnbound) { newHigh = lowerInclusive ? safelyIncrement(low) : low; newLow = 0; return new TimeRange(newLow, newHigh); } else if (lowerUnbound && !upperUnbound) { newLow = upperInclusive ? high : safelyIncrement(high); newHigh = HConstants.LATEST_TIMESTAMP; return new TimeRange(newLow, newHigh); } else { newLow = 0; newHigh = HConstants.LATEST_TIMESTAMP; return new TimeRange(newLow, newHigh); } }
/** * Converts a partially qualified KeyRange into a KeyRange with a inclusive lower bound and an * exclusive upper bound, widening as necessary. */ public static KeyRange convertToInclusiveExclusiveRange( KeyRange partialRange, RowKeySchema schema, ImmutableBytesWritable ptr) { // Ensure minMaxRange is lower inclusive and upper exclusive, as that's // what we need to intersect against for the HBase scan. byte[] lowerRange = partialRange.getLowerRange(); if (!partialRange.lowerUnbound()) { if (!partialRange.isLowerInclusive()) { lowerRange = ScanUtil.nextKey(lowerRange, schema, ptr); } } byte[] upperRange = partialRange.getUpperRange(); if (!partialRange.upperUnbound()) { if (partialRange.isUpperInclusive()) { upperRange = ScanUtil.nextKey(upperRange, schema, ptr); } } if (partialRange.getLowerRange() != lowerRange || partialRange.getUpperRange() != upperRange) { partialRange = KeyRange.getKeyRange(lowerRange, upperRange); } return partialRange; }
private static TimeRange getAscTimeRange(KeyRange lowestRange, KeyRange highestRange, Field f) throws IOException { long low; long high; if (lowestRange.lowerUnbound()) { low = 0; } else { long lowerRange = f.getDataType().getCodec().decodeLong(lowestRange.getLowerRange(), 0, SortOrder.ASC); low = lowestRange.isLowerInclusive() ? lowerRange : safelyIncrement(lowerRange); } if (highestRange.upperUnbound()) { high = HConstants.LATEST_TIMESTAMP; } else { long upperRange = f.getDataType().getCodec().decodeLong(highestRange.getUpperRange(), 0, SortOrder.ASC); if (highestRange.isUpperInclusive()) { high = safelyIncrement(upperRange); } else { high = upperRange; } } return new TimeRange(low, high); }