Skip to content

Commit

Permalink
Chore: Address comments
Browse files Browse the repository at this point in the history
Change-Id: I8886e907ebb797a67b36240417c2e609b6f5857a
  • Loading branch information
Lixia Chen committed Mar 27, 2024
1 parent 4cc5ba6 commit 9592a9e
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 228 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package com.google.cloud.bigtable.data.v2.internal;

import com.google.api.core.InternalApi;
import com.google.cloud.bigtable.data.v2.models.AuthorizedViewId;
import com.google.cloud.bigtable.data.v2.models.TableId;
import com.google.cloud.bigtable.data.v2.models.TargetId;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -84,4 +87,31 @@ public static String extractAuthorizedViewIdFromAuthorizedViewName(
}
return matcher.group(4);
}

public static TargetId extractTargetId(
@Nonnull String tableName, @Nonnull String authorizedViewName) {
if (tableName.isEmpty() && authorizedViewName.isEmpty()) {
throw new IllegalArgumentException(
"Either table name or authorized view name must be specified. Table name: "
+ tableName
+ ", authorized view name: "
+ authorizedViewName);
}
if (!tableName.isEmpty() && !authorizedViewName.isEmpty()) {
throw new IllegalArgumentException(
"Table name and authorized view name cannot be specified at the same time. Table name: "
+ tableName
+ ", authorized view name: "
+ authorizedViewName);
}

if (!tableName.isEmpty()) {
String tableId = extractTableIdFromTableName(tableName);
return TableId.of(tableId);
} else {
String tableId = extractTableIdFromAuthorizedViewName(authorizedViewName);
String authorizedViewId = extractAuthorizedViewIdFromAuthorizedViewName(authorizedViewName);
return AuthorizedViewId.of(tableId, authorizedViewId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ public final class BulkMutation implements Serializable, Cloneable {

private long mutationCountSum = 0;

/**
* @deprecated Please use {@link BulkMutation#create(TargetId)} instead. Create a TargetId for a
* table with {@link TableId#of(String)}.
*/
/** @deprecated Please use {@link BulkMutation#create(TargetId)} instead. */
@Deprecated
public static BulkMutation create(String tableId) {
return new BulkMutation(TableId.of(tableId));
}

/** Creates a new instance of the bulk mutation builder for the given target with targetId. */
/**
* Creates a new instance of the bulk mutation builder for the given target with targetId.
*
* @see AuthorizedViewId
* @see TableId
*/
public static BulkMutation create(TargetId targetId) {
return new BulkMutation(targetId);
}
Expand Down Expand Up @@ -153,24 +155,8 @@ public static BulkMutation fromProto(@Nonnull MutateRowsRequest request) {
String tableName = request.getTableName();
String authorizedViewName = request.getAuthorizedViewName();

Preconditions.checkArgument(
!tableName.isEmpty() || !authorizedViewName.isEmpty(),
"Either table name or authorized view name must be specified");
Preconditions.checkArgument(
tableName.isEmpty() || authorizedViewName.isEmpty(),
"Table name and authorized view name cannot be specified at the same time");

BulkMutation bulkMutation;
if (!tableName.isEmpty()) {
bulkMutation =
BulkMutation.create(TableId.of(NameUtil.extractTableIdFromTableName(tableName)));
} else {
bulkMutation =
BulkMutation.create(
AuthorizedViewId.of(
NameUtil.extractTableIdFromAuthorizedViewName(authorizedViewName),
NameUtil.extractAuthorizedViewIdFromAuthorizedViewName(authorizedViewName)));
}
BulkMutation bulkMutation =
BulkMutation.create(NameUtil.extractTargetId(tableName, authorizedViewName));
bulkMutation.builder = request.toBuilder();

return bulkMutation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,36 @@ private ConditionalRowMutation(TargetId targetId, ByteString rowKey) {
builder.setRowKey(rowKey);
}

/**
* @deprecated Please use {@link ConditionalRowMutation#create(TargetId, String)} instead. Create
* a TargetId for a table with {@link TableId#of(String)}.
*/
/** @deprecated Please use {@link ConditionalRowMutation#create(TargetId, String)} instead. */
@Deprecated
public static ConditionalRowMutation create(String tableId, String rowKey) {
return create(tableId, ByteString.copyFromUtf8(rowKey));
}

/** Creates a new instance of the mutation builder for the given target with targetId. */
/**
* Creates a new instance of the mutation builder for the given target with targetId.
*
* @see AuthorizedViewId
* @see TableId
*/
public static ConditionalRowMutation create(TargetId targetId, String rowKey) {
return create(targetId, ByteString.copyFromUtf8(rowKey));
}

/**
* @deprecated Please use {@link ConditionalRowMutation#create(TargetId, ByteString)} instead.
* Create a TargetId for a table with {@link TableId#of(String)}.
*/
/** @deprecated Please use {@link ConditionalRowMutation#create(TargetId, ByteString)} instead. */
@Deprecated
public static ConditionalRowMutation create(String tableId, ByteString rowKey) {
Validations.validateTableId(tableId);

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

/** Creates a new instance of the mutation builder for the given target with targetId. */
/**
* Creates a new instance of the mutation builder for the given target with targetId.
*
* @see AuthorizedViewId
* @see TableId
*/
public static ConditionalRowMutation create(TargetId targetId, ByteString rowKey) {
return new ConditionalRowMutation(targetId, rowKey);
}
Expand Down Expand Up @@ -173,25 +177,9 @@ public static ConditionalRowMutation fromProto(@Nonnull CheckAndMutateRowRequest
String tableName = request.getTableName();
String authorizedViewName = request.getAuthorizedViewName();

Preconditions.checkArgument(
!tableName.isEmpty() || !authorizedViewName.isEmpty(),
"Either table name or authorized view name must be specified");
Preconditions.checkArgument(
tableName.isEmpty() || authorizedViewName.isEmpty(),
"Table name and authorized view name cannot be specified at the same time");

ConditionalRowMutation rowMutation;
if (!tableName.isEmpty()) {
String tableId = NameUtil.extractTableIdFromTableName(tableName);
rowMutation = ConditionalRowMutation.create(TableId.of(tableId), request.getRowKey());
} else {
String tableId = NameUtil.extractTableIdFromAuthorizedViewName(authorizedViewName);
String authorizedViewId =
NameUtil.extractAuthorizedViewIdFromAuthorizedViewName(authorizedViewName);
rowMutation =
ConditionalRowMutation.create(
AuthorizedViewId.of(tableId, authorizedViewId), request.getRowKey());
}
ConditionalRowMutation rowMutation =
ConditionalRowMutation.create(
NameUtil.extractTargetId(tableName, authorizedViewName), request.getRowKey());
rowMutation.builder = request.toBuilder();

return rowMutation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public final class Query implements Serializable {
private final TargetId targetId;
private transient ReadRowsRequest.Builder builder = ReadRowsRequest.newBuilder();

/**
* @deprecated Please use {@link Query#create(TargetId)} instead. Create a TargetId for a table
* with {@link TableId#of(String)}.
*/
/** @deprecated Please use {@link Query#create(TargetId)} instead. */
@Deprecated
public static Query create(String tableId) {
return new Query(TableId.of(tableId));
Expand All @@ -63,6 +60,9 @@ public static Query create(String tableId) {
* Constructs a new Query object for the given target with targetId. The target id will be
* combined with the instance name specified in the {@link
* com.google.cloud.bigtable.data.v2.BigtableDataSettings}.
*
* @see AuthorizedViewId
* @see TableId
*/
public static Query create(TargetId targetId) {
return new Query(targetId);
Expand Down Expand Up @@ -336,23 +336,7 @@ public static Query fromProto(@Nonnull ReadRowsRequest request) {
String tableName = request.getTableName();
String authorizedViewName = request.getAuthorizedViewName();

Preconditions.checkArgument(
!tableName.isEmpty() || !authorizedViewName.isEmpty(),
"Either table name or authorized view name must be specified");
Preconditions.checkArgument(
tableName.isEmpty() || authorizedViewName.isEmpty(),
"Table name and authorized view name cannot be specified at the same time");

Query query;
if (!tableName.isEmpty()) {
query = new Query(TableId.of(NameUtil.extractTableIdFromTableName(tableName)));
} else {
query =
new Query(
AuthorizedViewId.of(
NameUtil.extractTableIdFromAuthorizedViewName(authorizedViewName),
NameUtil.extractAuthorizedViewIdFromAuthorizedViewName(authorizedViewName)));
}
Query query = new Query(NameUtil.extractTargetId(tableName, authorizedViewName));
query.builder = request.toBuilder();

return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,35 @@ private ReadModifyWriteRow(TargetId targetId, ByteString key) {
builder.setRowKey(key);
}

/**
* @deprecated Please use {@link ReadModifyWriteRow#create(TargetId, String)} instead. Create a
* TargetId for a table with {@link TableId#of(String)}.
*/
/** @deprecated Please use {@link ReadModifyWriteRow#create(TargetId, String)} instead. */
@Deprecated
public static ReadModifyWriteRow create(String tableId, String key) {
Preconditions.checkNotNull(key, "key can't be null.");
return new ReadModifyWriteRow(TableId.of(tableId), ByteString.copyFromUtf8(key));
}

/** Creates a new instance of the ReadModifyWriteRow for the given target with targetId. */
/**
* Creates a new instance of the ReadModifyWriteRow for the given target with targetId.
*
* @see AuthorizedViewId
* @see TableId
*/
public static ReadModifyWriteRow create(TargetId targetId, String key) {
return new ReadModifyWriteRow(targetId, ByteString.copyFromUtf8(key));
}

/**
* @deprecated Please use {@link ReadModifyWriteRow#create(TargetId, ByteString)} instead. Create
* a TargetId for a table with {@link TableId#of(String)}.
*/
/** @deprecated Please use {@link ReadModifyWriteRow#create(TargetId, ByteString)} instead. */
@Deprecated
public static ReadModifyWriteRow create(String tableId, ByteString key) {
return new ReadModifyWriteRow(TableId.of(tableId), key);
}

/** Creates a new instance of the ReadModifyWriteRow for the given target with targetId. */
/**
* Creates a new instance of the ReadModifyWriteRow for the given target with targetId.
*
* @see AuthorizedViewId
* @see TableId
*/
public static ReadModifyWriteRow create(TargetId targetId, ByteString key) {
return new ReadModifyWriteRow(targetId, key);
}
Expand Down Expand Up @@ -170,25 +174,9 @@ public static ReadModifyWriteRow fromProto(@Nonnull ReadModifyWriteRowRequest re
String tableName = request.getTableName();
String authorizedViewName = request.getAuthorizedViewName();

Preconditions.checkArgument(
!tableName.isEmpty() || !authorizedViewName.isEmpty(),
"Either table name or authorized view name must be specified");
Preconditions.checkArgument(
tableName.isEmpty() || authorizedViewName.isEmpty(),
"Table name and authorized view name cannot be specified at the same time");

ReadModifyWriteRow row;
if (!tableName.isEmpty()) {
String tableId = NameUtil.extractTableIdFromTableName(tableName);
row = ReadModifyWriteRow.create(TableId.of(tableId), request.getRowKey());
} else {
String tableId = NameUtil.extractTableIdFromAuthorizedViewName(authorizedViewName);
String authorizedViewId =
NameUtil.extractAuthorizedViewIdFromAuthorizedViewName(authorizedViewName);
row =
ReadModifyWriteRow.create(
AuthorizedViewId.of(tableId, authorizedViewId), request.getRowKey());
}
ReadModifyWriteRow row =
ReadModifyWriteRow.create(
NameUtil.extractTargetId(tableName, authorizedViewName), request.getRowKey());
row.builder = request.toBuilder();

return row;
Expand Down

0 comments on commit 9592a9e

Please sign in to comment.