-
Notifications
You must be signed in to change notification settings - Fork 98
feat: introduce java.time
#2415
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
Changes from 37 commits
71aa9a8
62dd45f
959a469
ca275dc
a7746ad
321c952
d25d6ef
796aa4b
a7e6167
0072191
99600a6
3765977
38b13e9
f6efe6b
41bc6ea
e06a104
fc920b0
9b6927a
987c343
173d961
de505d2
dc19a86
ff1b0fa
5b6d8af
efe806b
812c5a5
7deadf3
e2b1621
dde9326
6122ff1
70d6712
413703d
21c4614
253d351
ad9fa48
07c939a
d13c96b
540b19d
ce6a279
51657d8
06501e7
ed0213d
5994e4f
7ce813f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,18 @@ | |
*/ | ||
package com.google.cloud.bigtable.data.v2.models; | ||
|
||
import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; | ||
import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; | ||
|
||
import com.google.api.core.InternalApi; | ||
import com.google.api.core.ObsoleteApi; | ||
import com.google.auto.value.AutoValue; | ||
import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; | ||
import com.google.cloud.bigtable.data.v2.stub.changestream.ChangeStreamRecordMerger; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.protobuf.ByteString; | ||
import java.io.Serializable; | ||
import javax.annotation.Nonnull; | ||
import org.threeten.bp.Instant; | ||
|
||
/** | ||
* A ChangeStreamMutation represents a list of mods(represented by List<{@link Entry}>) targeted at | ||
|
@@ -73,13 +76,13 @@ public enum MutationType { | |
static Builder createUserMutation( | ||
@Nonnull ByteString rowKey, | ||
@Nonnull String sourceClusterId, | ||
Instant commitTimestamp, | ||
java.time.Instant commitTimestamp, | ||
int tieBreaker) { | ||
return builder() | ||
.setRowKey(rowKey) | ||
.setType(MutationType.USER) | ||
.setSourceClusterId(sourceClusterId) | ||
.setCommitTimestamp(commitTimestamp) | ||
.setCommitTime(commitTimestamp) | ||
.setTieBreaker(tieBreaker); | ||
} | ||
|
||
|
@@ -89,12 +92,12 @@ static Builder createUserMutation( | |
* mutation. | ||
*/ | ||
static Builder createGcMutation( | ||
@Nonnull ByteString rowKey, Instant commitTimestamp, int tieBreaker) { | ||
@Nonnull ByteString rowKey, java.time.Instant commitTimestamp, int tieBreaker) { | ||
return builder() | ||
.setRowKey(rowKey) | ||
.setType(MutationType.GARBAGE_COLLECTION) | ||
.setSourceClusterId("") | ||
.setCommitTimestamp(commitTimestamp) | ||
.setCommitTime(commitTimestamp) | ||
.setTieBreaker(tieBreaker); | ||
} | ||
|
||
|
@@ -110,8 +113,14 @@ static Builder createGcMutation( | |
@Nonnull | ||
public abstract String getSourceClusterId(); | ||
|
||
/** This method is obsolete. Use {@link #getCommitTime()} instead. */ | ||
@ObsoleteApi("Use getCommitTime() instead") | ||
public abstract org.threeten.bp.Instant getCommitTimestamp(); | ||
|
||
/** Get the commit timestamp of the current mutation. */ | ||
public abstract Instant getCommitTimestamp(); | ||
public java.time.Instant getCommitTime() { | ||
return toJavaTimeInstant(getCommitTimestamp()); | ||
} | ||
|
||
/** | ||
* Get the tie breaker of the current mutation. This is used to resolve conflicts when multiple | ||
|
@@ -123,8 +132,14 @@ static Builder createGcMutation( | |
@Nonnull | ||
public abstract String getToken(); | ||
|
||
/** This method is obsolete. Use {@link #getEstimatedLowWatermarkTime()} instead. */ | ||
@ObsoleteApi("Use getEstimatedLowWatermarkTime() instead") | ||
public abstract org.threeten.bp.Instant getEstimatedLowWatermark(); | ||
|
||
/** Get the low watermark of the current mutation. */ | ||
public abstract Instant getEstimatedLowWatermark(); | ||
public java.time.Instant getEstimatedLowWatermarkTime() { | ||
return toJavaTimeInstant(getEstimatedLowWatermark()); | ||
} | ||
|
||
/** Get the list of mods of the current mutation. */ | ||
@Nonnull | ||
|
@@ -145,15 +160,27 @@ abstract static class Builder { | |
|
||
abstract Builder setSourceClusterId(@Nonnull String sourceClusterId); | ||
|
||
abstract Builder setCommitTimestamp(Instant commitTimestamp); | ||
Builder setCommitTime(java.time.Instant commitTimestamp) { | ||
return setCommitTimestamp(toThreetenInstant(commitTimestamp)); | ||
} | ||
|
||
/** This method is obsolete. Use {@link #setCommitTime(java.time.Instant)} instead. */ | ||
@ObsoleteApi("Use setCommitTime(java.time.Instant) instead") | ||
abstract Builder setCommitTimestamp(org.threeten.bp.Instant commitTimestamp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to remove the threeten setter, only store it as java.time.Instant, and then reverse the overload of getCommitTime(stamp) above. The builder is fully internal, we just need to maintain backwards compatibility for the getter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the catch. This was indeed stated in the tracking sheet. I'll update this as an internal class. |
||
|
||
abstract Builder setTieBreaker(int tieBreaker); | ||
|
||
abstract ImmutableList.Builder<Entry> entriesBuilder(); | ||
|
||
abstract Builder setToken(@Nonnull String token); | ||
|
||
abstract Builder setEstimatedLowWatermark(Instant estimatedLowWatermark); | ||
Builder setLowWatermarkTime(java.time.Instant estimatedLowWatermark) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as for commit time. Also if we need to keep both setters this should be 'setEstimatedLowWatermarkTime' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, done. |
||
return setEstimatedLowWatermark(toThreetenInstant(estimatedLowWatermark)); | ||
} | ||
|
||
/** This method is obsolete. Use {@link #setLowWatermarkTime(java.time.Instant)} instead. */ | ||
@ObsoleteApi("Use setEstimatedLowWatermarkInstant(java.time.Instant) instead") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setEstimatedLowWatermarkInstant should be setEstimatedLowWatermarkTime There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be removed since it's an internal api change as per #2415 (comment) |
||
abstract Builder setEstimatedLowWatermark(org.threeten.bp.Instant estimatedLowWatermark); | ||
|
||
Builder setCell( | ||
@Nonnull String familyName, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,15 @@ | |
*/ | ||
package com.google.cloud.bigtable.data.v2.models; | ||
|
||
import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; | ||
import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; | ||
|
||
import com.google.api.core.InternalApi; | ||
import com.google.api.core.ObsoleteApi; | ||
import com.google.auto.value.AutoValue; | ||
import com.google.bigtable.v2.ReadChangeStreamResponse; | ||
import java.io.Serializable; | ||
import javax.annotation.Nonnull; | ||
import org.threeten.bp.Instant; | ||
|
||
/** A simple wrapper for {@link ReadChangeStreamResponse.Heartbeat}. */ | ||
@InternalApi("Intended for use by the BigtableIO in apache/beam only.") | ||
|
@@ -29,22 +32,30 @@ public abstract class Heartbeat implements ChangeStreamRecord, Serializable { | |
private static final long serialVersionUID = 7316215828353608504L; | ||
|
||
private static Heartbeat create( | ||
ChangeStreamContinuationToken changeStreamContinuationToken, Instant estimatedLowWatermark) { | ||
return new AutoValue_Heartbeat(changeStreamContinuationToken, estimatedLowWatermark); | ||
ChangeStreamContinuationToken changeStreamContinuationToken, | ||
java.time.Instant estimatedLowWatermark) { | ||
return new AutoValue_Heartbeat( | ||
changeStreamContinuationToken, toThreetenInstant(estimatedLowWatermark)); | ||
} | ||
|
||
/** Wraps the protobuf {@link ReadChangeStreamResponse.Heartbeat}. */ | ||
static Heartbeat fromProto(@Nonnull ReadChangeStreamResponse.Heartbeat heartbeat) { | ||
return create( | ||
ChangeStreamContinuationToken.fromProto(heartbeat.getContinuationToken()), | ||
Instant.ofEpochSecond( | ||
java.time.Instant.ofEpochSecond( | ||
heartbeat.getEstimatedLowWatermark().getSeconds(), | ||
heartbeat.getEstimatedLowWatermark().getNanos())); | ||
} | ||
|
||
@InternalApi("Intended for use by the BigtableIO in apache/beam only.") | ||
public abstract ChangeStreamContinuationToken getChangeStreamContinuationToken(); | ||
|
||
/** This method is obsolete. Use {@link #getEstimatedLowWatermarkInstant()} instead. */ | ||
@ObsoleteApi("Use getEstimatedLowWatermarkInstant() instead") | ||
public abstract org.threeten.bp.Instant getEstimatedLowWatermark(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as in ChangeStreamMutation. Wouldn't it be better to store this as java.time.Instant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, done. |
||
|
||
@InternalApi("Intended for use by the BigtableIO in apache/beam only.") | ||
public abstract Instant getEstimatedLowWatermark(); | ||
public java.time.Instant getEstimatedLowWatermarkInstant() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In ChangeStreamMutation we call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed as this is an internal api. I only kept the java.time version |
||
return toJavaTimeInstant(getEstimatedLowWatermark()); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.