Skip to content

HBASE-22841 Add more factory functions to TimeRange #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
* <p>
* Evaluated according to minStamp &lt;= timestamp &lt; maxStamp
* or [minStamp,maxStamp) in interval notation.
* <p>
* Can be returned and read by clients. Should not be directly created by clients.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this comment is still valid until the deprecated constructors are removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this in the committed patch.

* Thus, all constructors are purposely @InterfaceAudience.Private.
*<p>Immutable. Thread-safe.
*/
@InterfaceAudience.Public
Expand All @@ -51,6 +48,34 @@ public static TimeRange at(long ts) {
return new TimeRange(ts, ts + 1);
}

/**
* Represents the time interval [minStamp, Long.MAX_VALUE)
* @param minStamp the minimum timestamp value, inclusive
*/
public static TimeRange from(long minStamp) {
check(minStamp, INITIAL_MAX_TIMESTAMP);
return new TimeRange(minStamp, INITIAL_MAX_TIMESTAMP);
}

/**
* Represents the time interval [0, maxStamp)
* @param maxStamp the minimum timestamp value, exclusive
*/
public static TimeRange until(long maxStamp) {
check(INITIAL_MIN_TIMESTAMP, maxStamp);
return new TimeRange(INITIAL_MIN_TIMESTAMP, maxStamp);
}

/**
* Represents the time interval [minStamp, maxStamp)
* @param minStamp the minimum timestamp, inclusive
* @param maxStamp the maximum timestamp, exclusive
*/
public static TimeRange between(long minStamp, long maxStamp) {
check(minStamp, maxStamp);
return new TimeRange(minStamp, maxStamp);
}

private final long minStamp;
private final long maxStamp;
private final boolean allTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4866,12 +4866,48 @@ public void testCheckAndMutateWithTimeRange() throws IOException {
.thenPut(put);
assertFalse(ok);

ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a short comment for every test what the purpose is (or move them into separate, small test cases)?

.timeRange(TimeRange.from(ts + 10000))
.ifEquals(VALUE)
.thenPut(put);
assertFalse(ok);

ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
.timeRange(TimeRange.between(ts + 10000, ts + 20000))
.ifEquals(VALUE)
.thenPut(put);
assertFalse(ok);

ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
.timeRange(TimeRange.until(ts))
.ifEquals(VALUE)
.thenPut(put);
assertFalse(ok);

ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
.timeRange(TimeRange.at(ts))
.ifEquals(VALUE)
.thenPut(put);
assertTrue(ok);

ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
.timeRange(TimeRange.from(ts))
.ifEquals(VALUE)
.thenPut(put);
assertTrue(ok);

ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
.timeRange(TimeRange.between(ts, ts + 20000))
.ifEquals(VALUE)
.thenPut(put);
assertTrue(ok);

ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
.timeRange(TimeRange.until(ts + 10000))
.ifEquals(VALUE)
.thenPut(put);
assertTrue(ok);

RowMutations rm = new RowMutations(ROW)
.add((Mutation) put);
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
Expand Down