Skip to content
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

feat: introduce java.time #2415

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
71aa9a8
feat: introduce java.time to java-bigtable
diegomarquezp Nov 14, 2024
62dd45f
fix tests i
diegomarquezp Nov 14, 2024
959a469
chore: generate libraries at Thu Nov 14 16:52:48 UTC 2024
cloud-java-bot Nov 14, 2024
ca275dc
fix tests
diegomarquezp Nov 14, 2024
a7746ad
make protobuf timestamp conversion fully precise (epoch seconds + nanos)
diegomarquezp Nov 14, 2024
321c952
Merge branch 'introduce-java-time' of https://github.com/googleapis/j…
diegomarquezp Nov 14, 2024
d25d6ef
resolve to microsecond level
diegomarquezp Nov 18, 2024
796aa4b
Revert "make protobuf timestamp conversion fully precise (epoch secon…
diegomarquezp Nov 18, 2024
a7e6167
restore ms precision
diegomarquezp Nov 18, 2024
0072191
fix precision in tests
diegomarquezp Nov 19, 2024
99600a6
fix tests
diegomarquezp Nov 19, 2024
3765977
fix tests, clirr
diegomarquezp Nov 19, 2024
38b13e9
fix test proxy
diegomarquezp Nov 20, 2024
f6efe6b
format
diegomarquezp Nov 20, 2024
41bc6ea
format ii
diegomarquezp Nov 20, 2024
e06a104
fix ITs
diegomarquezp Nov 22, 2024
fc920b0
fix it, timestamp precision
diegomarquezp Nov 22, 2024
9b6927a
Merge branch 'main' into introduce-java-time
diegomarquezp Nov 22, 2024
987c343
Merge remote-tracking branch 'origin/main' into introduce-java-time
diegomarquezp Nov 25, 2024
173d961
Merge remote-tracking branch 'refs/remotes/origin/introduce-java-time…
diegomarquezp Nov 25, 2024
de505d2
solve review comments
diegomarquezp Nov 25, 2024
dc19a86
treat tracer classes as internal
diegomarquezp Dec 5, 2024
ff1b0fa
Merge remote-tracking branch 'origin/main' into introduce-java-time
diegomarquezp Dec 5, 2024
5b6d8af
reset admin changes
diegomarquezp Dec 5, 2024
efe806b
update sql files (internal)
diegomarquezp Dec 5, 2024
812c5a5
format tracer files
diegomarquezp Dec 5, 2024
7deadf3
adapt admin tests
diegomarquezp Dec 5, 2024
e2b1621
adapt sql tests
diegomarquezp Dec 5, 2024
dde9326
changes in change stream
diegomarquezp Dec 5, 2024
6122ff1
chore: generate libraries at Thu Dec 5 23:02:28 UTC 2024
cloud-java-bot Dec 5, 2024
70d6712
ignore changes in beta and internal surface
diegomarquezp Dec 6, 2024
413703d
Merge branch 'introduce-java-time' of https://github.com/googleapis/j…
diegomarquezp Dec 6, 2024
21c4614
change imports instead of using full qualified names
diegomarquezp Dec 6, 2024
253d351
chore: generate libraries at Fri Dec 6 18:47:10 UTC 2024
cloud-java-bot Dec 6, 2024
ad9fa48
simplify imports
diegomarquezp Dec 6, 2024
07c939a
fix test proxy i
diegomarquezp Dec 6, 2024
d13c96b
Merge branch 'introduce-java-time' of https://github.com/googleapis/j…
diegomarquezp Dec 6, 2024
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
6 changes: 6 additions & 0 deletions google-cloud-bigtable/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,10 @@
<className>com/google/cloud/bigtable/data/v2/stub/metrics/DefaultMetricsProvider</className>
<method>*</method>
</difference>
<difference>
<!-- We ignore these methods because they have `default` behavior -->
<differenceType>7012</differenceType>
<className>com/google/cloud/bigtable/data/v2/models/sql/StructReader</className>
<method>java.time.Instant getTimestampInstant(*)</method>
</difference>
</differences>
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@

package com.google.cloud.bigtable.admin.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant;

import com.google.api.core.InternalApi;
import com.google.api.core.ObsoleteApi;
import com.google.bigtable.admin.v2.BackupName;
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.protobuf.util.Timestamps;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.threeten.bp.Instant;

/**
* A backup lets you save a copy of a table's schema and data and restore the backup to a new table
Expand Down Expand Up @@ -166,23 +168,42 @@ public String getInstanceId() {
return instanceId;
}

/** This method is obsolete. Use {@link #getExpireTimeInstant()} instead. */
@ObsoleteApi("Use getExpireTimeInstant() instead")
public org.threeten.bp.Instant getExpireTime() {
return toThreetenInstant(getExpireTimeInstant());
}

/** Get the expire time of this backup. */
public Instant getExpireTime() {
return Instant.ofEpochMilli(Timestamps.toMillis(proto.getExpireTime()));
public java.time.Instant getExpireTimeInstant() {
return java.time.Instant.ofEpochSecond(
proto.getExpireTime().getSeconds(), proto.getExpireTime().getNanos());
}

/** This method is obsolete. Use {@link #getStartTimeInstant()} instead. */
@ObsoleteApi("Use getStartTimeInstant() instead")
public @Nullable org.threeten.bp.Instant getStartTime() {
return toThreetenInstant(getStartTimeInstant());
}

/** Get the start time when this backup is taken. */
public @Nullable Instant getStartTime() {
public @Nullable java.time.Instant getStartTimeInstant() {
if (proto.hasStartTime()) {
return Instant.ofEpochMilli(Timestamps.toMillis(proto.getStartTime()));
return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getStartTime()));
}
return null;
}

/** This method is obsolete. Use {@link #getStartTimeInstant()} instead. */
@ObsoleteApi("Use getStartTimeInstant() instead")
public @Nullable org.threeten.bp.Instant getEndTime() {
return toThreetenInstant(getEndTimeInstant());
}

/** Get the end time when the creation of this backup has completed. */
public @Nullable Instant getEndTime() {
public @Nullable java.time.Instant getEndTimeInstant() {
if (proto.hasEndTime()) {
return Instant.ofEpochMilli(Timestamps.toMillis(proto.getEndTime()));
return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getEndTime()));
}
return null;
}
Expand All @@ -202,11 +223,18 @@ public BackupType getBackupType() {
return BackupType.fromProto(proto.getBackupType());
}

/** This method is obsolete. Use {@link #getHotToStandardTimeInstant()} instead. */
@ObsoleteApi("Use getHotToStandardTimeInstant() instead.")
@Nullable
public org.threeten.bp.Instant getHotToStandardTime() {
return toThreetenInstant(getHotToStandardTimeInstant());
}

/** Get the time at which this backup will be converted from a hot backup to a standard backup. */
@Nullable
public Instant getHotToStandardTime() {
public java.time.Instant getHotToStandardTimeInstant() {
if (proto.hasHotToStandardTime()) {
return Instant.ofEpochMilli(Timestamps.toMillis(proto.getHotToStandardTime()));
return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getHotToStandardTime()));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
*/
package com.google.cloud.bigtable.admin.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant;

import com.google.api.core.InternalApi;
import com.google.api.core.ObsoleteApi;
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.protobuf.Timestamp;
import com.google.protobuf.util.Timestamps;
import javax.annotation.Nonnull;
import org.threeten.bp.Instant;

/** Build CopyBackupRequest for {@link com.google.bigtable.admin.v2.CopyBackupRequest}. */
public final class CopyBackupRequest {
Expand Down Expand Up @@ -75,9 +78,16 @@ public CopyBackupRequest setDestination(String clusterId, String backupId) {
return this;
}

public CopyBackupRequest setExpireTime(Instant expireTime) {
/** This method is obsolete. Use {@link #setExpireTimeInstant(java.time.Instant)} instead. */
@ObsoleteApi("Use setExpireTimeInstant(java.time.Instant) instead.")
public CopyBackupRequest setExpireTime(org.threeten.bp.Instant expireTime) {
return setExpireTimeInstant(toJavaTimeInstant(expireTime));
}

public CopyBackupRequest setExpireTimeInstant(java.time.Instant expireTime) {
Preconditions.checkNotNull(expireTime);
requestBuilder.setExpireTime(Timestamps.fromMillis(expireTime.toEpochMilli()));
Timestamp value = Timestamps.fromMillis(expireTime.toEpochMilli());
requestBuilder.setExpireTime(value);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
*/
package com.google.cloud.bigtable.admin.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant;

import com.google.api.core.InternalApi;
import com.google.api.core.ObsoleteApi;
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.protobuf.util.Timestamps;
import javax.annotation.Nonnull;
import org.threeten.bp.Instant;

/** Fluent wrapper for {@link com.google.bigtable.admin.v2.CreateBackupRequest} */
public final class CreateBackupRequest {
Expand Down Expand Up @@ -50,7 +52,13 @@ public CreateBackupRequest setSourceTableId(String sourceTableId) {
return this;
}

public CreateBackupRequest setExpireTime(Instant expireTime) {
/** This method is obsolete. Use {@link #setExpireTimeInstant(java.time.Instant)} instead. */
@ObsoleteApi("Use setExpireTimeInstant(java.time.Instant) instead.")
public CreateBackupRequest setExpireTime(org.threeten.bp.Instant expireTime) {
return setExpireTimeInstant(toJavaTimeInstant(expireTime));
}

public CreateBackupRequest setExpireTimeInstant(java.time.Instant expireTime) {
Preconditions.checkNotNull(expireTime);
requestBuilder
.getBackupBuilder()
Expand All @@ -64,10 +72,18 @@ public CreateBackupRequest setBackupType(Backup.BackupType backupType) {
return this;
}

/**
* This method is obsolete. Use {@link #setHotToStandardTimeInstant(java.time.Instant)} instead.
*/
@ObsoleteApi("Use setHotToStandardTimeInstant(java.time.Instant) instead.")
public CreateBackupRequest setHotToStandardTime(org.threeten.bp.Instant hotToStandardTime) {
return setHotToStandardTimeInstant(toJavaTimeInstant(hotToStandardTime));
}

// The time at which this backup will be converted from a hot backup to a standard backup. Only
// applicable for hot backups. If not set, the backup will remain as a hot backup until it is
// deleted.
public CreateBackupRequest setHotToStandardTime(Instant hotToStandardTime) {
public CreateBackupRequest setHotToStandardTimeInstant(java.time.Instant hotToStandardTime) {
Preconditions.checkNotNull(hotToStandardTime);
requestBuilder
.getBackupBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
*/
package com.google.cloud.bigtable.admin.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration;

import com.google.api.core.InternalApi;
import com.google.api.core.ObsoleteApi;
import com.google.bigtable.admin.v2.ChangeStreamConfig;
import com.google.bigtable.admin.v2.ColumnFamily;
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
import com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import com.google.protobuf.Duration;
import javax.annotation.Nonnull;
import org.threeten.bp.Duration;

/**
* Fluent wrapper for {@link com.google.bigtable.admin.v2.CreateTableRequest}
Expand Down Expand Up @@ -107,15 +110,24 @@ public CreateTableRequest addSplit(ByteString key) {
return this;
}

/**
* This method is obsolete. Use {@link #addChangeStreamRetentionDuration(java.time.Duration)}
* instead.
*/
@ObsoleteApi("Use addChangeStreamRetentionDuration(java.time.Duration) instead.")
public CreateTableRequest addChangeStreamRetention(org.threeten.bp.Duration retention) {
return addChangeStreamRetentionDuration(toJavaTimeDuration(retention));
}

/** Add change stream retention period between 1 day and 7 days */
public CreateTableRequest addChangeStreamRetention(Duration retention) {
public CreateTableRequest addChangeStreamRetentionDuration(java.time.Duration retention) {
Preconditions.checkNotNull(retention);
requestBuilder
.getTableBuilder()
.setChangeStreamConfig(
ChangeStreamConfig.newBuilder()
.setRetentionPeriod(
com.google.protobuf.Duration.newBuilder()
Duration.newBuilder()
.setSeconds(retention.getSeconds())
.setNanos(retention.getNano())
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
*/
package com.google.cloud.bigtable.admin.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration;
import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration;

import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.api.core.ObsoleteApi;
import com.google.bigtable.admin.v2.GcRule;
import com.google.bigtable.admin.v2.GcRule.Intersection;
import com.google.bigtable.admin.v2.GcRule.Union;
Expand All @@ -26,7 +30,6 @@
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import org.threeten.bp.Duration;

// TODO(igorbernstein2): the distinction between GcRule & GCRule is too subtle, use fully qualified
// names for the protos.
Expand Down Expand Up @@ -70,15 +73,21 @@ public VersionRule maxVersions(int maxVersion) {
* @param timeUnit - timeunit for the age
*/
public DurationRule maxAge(long maxAge, TimeUnit timeUnit) {
return maxAge(Duration.ofNanos(TimeUnit.NANOSECONDS.convert(maxAge, timeUnit)));
return maxAgeDuration(
java.time.Duration.ofNanos(TimeUnit.NANOSECONDS.convert(maxAge, timeUnit)));
}

/** This method is obsolete. Use {@link #maxAgeDuration(java.time.Duration)} instead. */
@ObsoleteApi("Use maxAgeDuration(java.time.Duration) instead.")
public DurationRule maxAge(org.threeten.bp.Duration duration) {
return maxAgeDuration(toJavaTimeDuration(duration));
}
/**
* Creates a new instance of the DurationRule
*
* @param duration - age expressed as duration
*/
public DurationRule maxAge(Duration duration) {
public DurationRule maxAgeDuration(java.time.Duration duration) {
return new DurationRule(duration);
}

Expand All @@ -91,8 +100,9 @@ public DefaultRule defaultRule() {
public GCRule fromProto(GcRule source) {
switch (source.getRuleCase()) {
case MAX_AGE:
return GCRULES.maxAge(
Duration.ofSeconds(source.getMaxAge().getSeconds(), source.getMaxAge().getNanos()));
return GCRULES.maxAgeDuration(
java.time.Duration.ofSeconds(
source.getMaxAge().getSeconds(), source.getMaxAge().getNanos()));

case MAX_NUM_VERSIONS:
return GCRULES.maxVersions(source.getMaxNumVersions());
Expand Down Expand Up @@ -287,16 +297,22 @@ public GcRule toProto() {
public static final class DurationRule implements GCRule {
private final com.google.protobuf.Duration.Builder builder;

private DurationRule(Duration duration) {
private DurationRule(java.time.Duration duration) {
this.builder =
com.google.protobuf.Duration.newBuilder()
.setSeconds(duration.getSeconds())
.setNanos(duration.getNano());
}

/** This method is obsolete. Use {@link #getMaxAgeDuration()} instead. */
@ObsoleteApi("Use getMaxAgeDuration() instead.")
public org.threeten.bp.Duration getMaxAge() {
return toThreetenDuration(getMaxAgeDuration());
}

/** Gets the configured maximum age */
public Duration getMaxAge() {
return Duration.ofSeconds(builder.getSeconds(), builder.getNanos());
public java.time.Duration getMaxAgeDuration() {
return java.time.Duration.ofSeconds(builder.getSeconds(), builder.getNanos());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/
package com.google.cloud.bigtable.admin.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration;

import com.google.api.core.InternalApi;
import com.google.api.core.ObsoleteApi;
import com.google.bigtable.admin.v2.TableName;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
Expand All @@ -25,7 +28,6 @@
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import org.threeten.bp.Duration;

/** Wrapper for {@link Table} protocol buffer object */
public final class Table {
Expand Down Expand Up @@ -104,7 +106,7 @@ public com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState toProto(
private final Map<String, ReplicationState> replicationStatesByClusterId;
private final List<ColumnFamily> columnFamilies;

private final Duration changeStreamRetention;
private final java.time.Duration changeStreamRetention;

@InternalApi
public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto) {
Expand All @@ -123,10 +125,10 @@ public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto)
columnFamilies.add(ColumnFamily.fromProto(entry.getKey(), entry.getValue()));
}

Duration changeStreamConfig = null;
java.time.Duration changeStreamConfig = null;
if (proto.hasChangeStreamConfig()) {
changeStreamConfig =
Duration.ofSeconds(
java.time.Duration.ofSeconds(
proto.getChangeStreamConfig().getRetentionPeriod().getSeconds(),
proto.getChangeStreamConfig().getRetentionPeriod().getNanos());
}
Expand All @@ -142,7 +144,7 @@ private Table(
TableName tableName,
Map<String, ReplicationState> replicationStatesByClusterId,
List<ColumnFamily> columnFamilies,
Duration changeStreamRetention) {
java.time.Duration changeStreamRetention) {
this.instanceId = tableName.getInstance();
this.id = tableName.getTable();
this.replicationStatesByClusterId = replicationStatesByClusterId;
Expand All @@ -168,7 +170,13 @@ public List<ColumnFamily> getColumnFamilies() {
return columnFamilies;
}

public Duration getChangeStreamRetention() {
/** This method is obsolete. Use {@link #getChangeStreamRetentionDuration()} instead. */
@ObsoleteApi("Use getChangeStreamRetention() instead.")
public org.threeten.bp.Duration getChangeStreamRetention() {
return toThreetenDuration(getChangeStreamRetentionDuration());
}

public java.time.Duration getChangeStreamRetentionDuration() {
return changeStreamRetention;
}

Expand Down
Loading
Loading