Skip to content

Commit 60365af

Browse files
author
Lixia Chen
committed
Chore: Address comments
Change-Id: I8886e907ebb797a67b36240417c2e609b6f5857a
1 parent 41a623e commit 60365af

File tree

10 files changed

+223
-228
lines changed

10 files changed

+223
-228
lines changed

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java

Lines changed: 88 additions & 69 deletions
Large diffs are not rendered by default.

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/NameUtil.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
package com.google.cloud.bigtable.data.v2.internal;
1717

1818
import com.google.api.core.InternalApi;
19+
import com.google.cloud.bigtable.data.v2.models.AuthorizedViewId;
20+
import com.google.cloud.bigtable.data.v2.models.TableId;
21+
import com.google.cloud.bigtable.data.v2.models.TargetId;
1922
import java.util.regex.Matcher;
2023
import java.util.regex.Pattern;
2124
import javax.annotation.Nonnull;
@@ -84,4 +87,31 @@ public static String extractAuthorizedViewIdFromAuthorizedViewName(
8487
}
8588
return matcher.group(4);
8689
}
90+
91+
public static TargetId extractTargetId(
92+
@Nonnull String tableName, @Nonnull String authorizedViewName) {
93+
if (tableName.isEmpty() && authorizedViewName.isEmpty()) {
94+
throw new IllegalArgumentException(
95+
"Either table name or authorized view name must be specified. Table name: "
96+
+ tableName
97+
+ ", authorized view name: "
98+
+ authorizedViewName);
99+
}
100+
if (!tableName.isEmpty() && !authorizedViewName.isEmpty()) {
101+
throw new IllegalArgumentException(
102+
"Table name and authorized view name cannot be specified at the same time. Table name: "
103+
+ tableName
104+
+ ", authorized view name: "
105+
+ authorizedViewName);
106+
}
107+
108+
if (!tableName.isEmpty()) {
109+
String tableId = extractTableIdFromTableName(tableName);
110+
return TableId.of(tableId);
111+
} else {
112+
String tableId = extractTableIdFromAuthorizedViewName(authorizedViewName);
113+
String authorizedViewId = extractAuthorizedViewIdFromAuthorizedViewName(authorizedViewName);
114+
return AuthorizedViewId.of(tableId, authorizedViewId);
115+
}
116+
}
87117
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/BulkMutation.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ public final class BulkMutation implements Serializable, Cloneable {
4343

4444
private long mutationCountSum = 0;
4545

46-
/**
47-
* @deprecated Please use {@link BulkMutation#create(TargetId)} instead. Create a TargetId for a
48-
* table with {@link TableId#of(String)}.
49-
*/
46+
/** @deprecated Please use {@link BulkMutation#create(TargetId)} instead. */
5047
@Deprecated
5148
public static BulkMutation create(String tableId) {
5249
return new BulkMutation(TableId.of(tableId));
5350
}
5451

55-
/** Creates a new instance of the bulk mutation builder for the given target with targetId. */
52+
/**
53+
* Creates a new instance of the bulk mutation builder for the given target with targetId.
54+
*
55+
* @see AuthorizedViewId
56+
* @see TableId
57+
*/
5658
public static BulkMutation create(TargetId targetId) {
5759
return new BulkMutation(targetId);
5860
}
@@ -153,24 +155,8 @@ public static BulkMutation fromProto(@Nonnull MutateRowsRequest request) {
153155
String tableName = request.getTableName();
154156
String authorizedViewName = request.getAuthorizedViewName();
155157

156-
Preconditions.checkArgument(
157-
!tableName.isEmpty() || !authorizedViewName.isEmpty(),
158-
"Either table name or authorized view name must be specified");
159-
Preconditions.checkArgument(
160-
tableName.isEmpty() || authorizedViewName.isEmpty(),
161-
"Table name and authorized view name cannot be specified at the same time");
162-
163-
BulkMutation bulkMutation;
164-
if (!tableName.isEmpty()) {
165-
bulkMutation =
166-
BulkMutation.create(TableId.of(NameUtil.extractTableIdFromTableName(tableName)));
167-
} else {
168-
bulkMutation =
169-
BulkMutation.create(
170-
AuthorizedViewId.of(
171-
NameUtil.extractTableIdFromAuthorizedViewName(authorizedViewName),
172-
NameUtil.extractAuthorizedViewIdFromAuthorizedViewName(authorizedViewName)));
173-
}
158+
BulkMutation bulkMutation =
159+
BulkMutation.create(NameUtil.extractTargetId(tableName, authorizedViewName));
174160
bulkMutation.builder = request.toBuilder();
175161

176162
return bulkMutation;

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ConditionalRowMutation.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,36 @@ private ConditionalRowMutation(TargetId targetId, ByteString rowKey) {
4444
builder.setRowKey(rowKey);
4545
}
4646

47-
/**
48-
* @deprecated Please use {@link ConditionalRowMutation#create(TargetId, String)} instead. Create
49-
* a TargetId for a table with {@link TableId#of(String)}.
50-
*/
47+
/** @deprecated Please use {@link ConditionalRowMutation#create(TargetId, String)} instead. */
5148
@Deprecated
5249
public static ConditionalRowMutation create(String tableId, String rowKey) {
5350
return create(tableId, ByteString.copyFromUtf8(rowKey));
5451
}
5552

56-
/** Creates a new instance of the mutation builder for the given target with targetId. */
53+
/**
54+
* Creates a new instance of the mutation builder for the given target with targetId.
55+
*
56+
* @see AuthorizedViewId
57+
* @see TableId
58+
*/
5759
public static ConditionalRowMutation create(TargetId targetId, String rowKey) {
5860
return create(targetId, ByteString.copyFromUtf8(rowKey));
5961
}
6062

61-
/**
62-
* @deprecated Please use {@link ConditionalRowMutation#create(TargetId, ByteString)} instead.
63-
* Create a TargetId for a table with {@link TableId#of(String)}.
64-
*/
63+
/** @deprecated Please use {@link ConditionalRowMutation#create(TargetId, ByteString)} instead. */
6564
@Deprecated
6665
public static ConditionalRowMutation create(String tableId, ByteString rowKey) {
6766
Validations.validateTableId(tableId);
6867

6968
return new ConditionalRowMutation(TableId.of(tableId), rowKey);
7069
}
7170

72-
/** Creates a new instance of the mutation builder for the given target with targetId. */
71+
/**
72+
* Creates a new instance of the mutation builder for the given target with targetId.
73+
*
74+
* @see AuthorizedViewId
75+
* @see TableId
76+
*/
7377
public static ConditionalRowMutation create(TargetId targetId, ByteString rowKey) {
7478
return new ConditionalRowMutation(targetId, rowKey);
7579
}
@@ -173,25 +177,9 @@ public static ConditionalRowMutation fromProto(@Nonnull CheckAndMutateRowRequest
173177
String tableName = request.getTableName();
174178
String authorizedViewName = request.getAuthorizedViewName();
175179

176-
Preconditions.checkArgument(
177-
!tableName.isEmpty() || !authorizedViewName.isEmpty(),
178-
"Either table name or authorized view name must be specified");
179-
Preconditions.checkArgument(
180-
tableName.isEmpty() || authorizedViewName.isEmpty(),
181-
"Table name and authorized view name cannot be specified at the same time");
182-
183-
ConditionalRowMutation rowMutation;
184-
if (!tableName.isEmpty()) {
185-
String tableId = NameUtil.extractTableIdFromTableName(tableName);
186-
rowMutation = ConditionalRowMutation.create(TableId.of(tableId), request.getRowKey());
187-
} else {
188-
String tableId = NameUtil.extractTableIdFromAuthorizedViewName(authorizedViewName);
189-
String authorizedViewId =
190-
NameUtil.extractAuthorizedViewIdFromAuthorizedViewName(authorizedViewName);
191-
rowMutation =
192-
ConditionalRowMutation.create(
193-
AuthorizedViewId.of(tableId, authorizedViewId), request.getRowKey());
194-
}
180+
ConditionalRowMutation rowMutation =
181+
ConditionalRowMutation.create(
182+
NameUtil.extractTargetId(tableName, authorizedViewName), request.getRowKey());
195183
rowMutation.builder = request.toBuilder();
196184

197185
return rowMutation;

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Query.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ public final class Query implements Serializable {
5050
private final TargetId targetId;
5151
private transient ReadRowsRequest.Builder builder = ReadRowsRequest.newBuilder();
5252

53-
/**
54-
* @deprecated Please use {@link Query#create(TargetId)} instead. Create a TargetId for a table
55-
* with {@link TableId#of(String)}.
56-
*/
53+
/** @deprecated Please use {@link Query#create(TargetId)} instead. */
5754
@Deprecated
5855
public static Query create(String tableId) {
5956
return new Query(TableId.of(tableId));
@@ -63,6 +60,9 @@ public static Query create(String tableId) {
6360
* Constructs a new Query object for the given target with targetId. The target id will be
6461
* combined with the instance name specified in the {@link
6562
* com.google.cloud.bigtable.data.v2.BigtableDataSettings}.
63+
*
64+
* @see AuthorizedViewId
65+
* @see TableId
6666
*/
6767
public static Query create(TargetId targetId) {
6868
return new Query(targetId);
@@ -336,23 +336,7 @@ public static Query fromProto(@Nonnull ReadRowsRequest request) {
336336
String tableName = request.getTableName();
337337
String authorizedViewName = request.getAuthorizedViewName();
338338

339-
Preconditions.checkArgument(
340-
!tableName.isEmpty() || !authorizedViewName.isEmpty(),
341-
"Either table name or authorized view name must be specified");
342-
Preconditions.checkArgument(
343-
tableName.isEmpty() || authorizedViewName.isEmpty(),
344-
"Table name and authorized view name cannot be specified at the same time");
345-
346-
Query query;
347-
if (!tableName.isEmpty()) {
348-
query = new Query(TableId.of(NameUtil.extractTableIdFromTableName(tableName)));
349-
} else {
350-
query =
351-
new Query(
352-
AuthorizedViewId.of(
353-
NameUtil.extractTableIdFromAuthorizedViewName(authorizedViewName),
354-
NameUtil.extractAuthorizedViewIdFromAuthorizedViewName(authorizedViewName)));
355-
}
339+
Query query = new Query(NameUtil.extractTargetId(tableName, authorizedViewName));
356340
query.builder = request.toBuilder();
357341

358342
return query;

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRow.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,35 @@ private ReadModifyWriteRow(TargetId targetId, ByteString key) {
4545
builder.setRowKey(key);
4646
}
4747

48-
/**
49-
* @deprecated Please use {@link ReadModifyWriteRow#create(TargetId, String)} instead. Create a
50-
* TargetId for a table with {@link TableId#of(String)}.
51-
*/
48+
/** @deprecated Please use {@link ReadModifyWriteRow#create(TargetId, String)} instead. */
5249
@Deprecated
5350
public static ReadModifyWriteRow create(String tableId, String key) {
5451
Preconditions.checkNotNull(key, "key can't be null.");
5552
return new ReadModifyWriteRow(TableId.of(tableId), ByteString.copyFromUtf8(key));
5653
}
5754

58-
/** Creates a new instance of the ReadModifyWriteRow for the given target with targetId. */
55+
/**
56+
* Creates a new instance of the ReadModifyWriteRow for the given target with targetId.
57+
*
58+
* @see AuthorizedViewId
59+
* @see TableId
60+
*/
5961
public static ReadModifyWriteRow create(TargetId targetId, String key) {
6062
return new ReadModifyWriteRow(targetId, ByteString.copyFromUtf8(key));
6163
}
6264

63-
/**
64-
* @deprecated Please use {@link ReadModifyWriteRow#create(TargetId, ByteString)} instead. Create
65-
* a TargetId for a table with {@link TableId#of(String)}.
66-
*/
65+
/** @deprecated Please use {@link ReadModifyWriteRow#create(TargetId, ByteString)} instead. */
6766
@Deprecated
6867
public static ReadModifyWriteRow create(String tableId, ByteString key) {
6968
return new ReadModifyWriteRow(TableId.of(tableId), key);
7069
}
7170

72-
/** Creates a new instance of the ReadModifyWriteRow for the given target with targetId. */
71+
/**
72+
* Creates a new instance of the ReadModifyWriteRow for the given target with targetId.
73+
*
74+
* @see AuthorizedViewId
75+
* @see TableId
76+
*/
7377
public static ReadModifyWriteRow create(TargetId targetId, ByteString key) {
7478
return new ReadModifyWriteRow(targetId, key);
7579
}
@@ -170,25 +174,9 @@ public static ReadModifyWriteRow fromProto(@Nonnull ReadModifyWriteRowRequest re
170174
String tableName = request.getTableName();
171175
String authorizedViewName = request.getAuthorizedViewName();
172176

173-
Preconditions.checkArgument(
174-
!tableName.isEmpty() || !authorizedViewName.isEmpty(),
175-
"Either table name or authorized view name must be specified");
176-
Preconditions.checkArgument(
177-
tableName.isEmpty() || authorizedViewName.isEmpty(),
178-
"Table name and authorized view name cannot be specified at the same time");
179-
180-
ReadModifyWriteRow row;
181-
if (!tableName.isEmpty()) {
182-
String tableId = NameUtil.extractTableIdFromTableName(tableName);
183-
row = ReadModifyWriteRow.create(TableId.of(tableId), request.getRowKey());
184-
} else {
185-
String tableId = NameUtil.extractTableIdFromAuthorizedViewName(authorizedViewName);
186-
String authorizedViewId =
187-
NameUtil.extractAuthorizedViewIdFromAuthorizedViewName(authorizedViewName);
188-
row =
189-
ReadModifyWriteRow.create(
190-
AuthorizedViewId.of(tableId, authorizedViewId), request.getRowKey());
191-
}
177+
ReadModifyWriteRow row =
178+
ReadModifyWriteRow.create(
179+
NameUtil.extractTargetId(tableName, authorizedViewName), request.getRowKey());
192180
row.builder = request.toBuilder();
193181

194182
return row;

0 commit comments

Comments
 (0)