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

Added Query#fromProto to convert protobuf ReadRowsRequest #4291

Merged
merged 6 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -260,6 +260,25 @@ public ReadRowsRequest toProto(RequestContext requestContext) {
.build();
}

/**
* Wraps the protobuf {@link ReadRowsRequest}. This method is considered an internal implementation detail
* and not meant to be used by applications.
rahulKQL marked this conversation as resolved.
Show resolved Hide resolved
*/
@InternalApi
public static Query fromProto(ReadRowsRequest request) {

This comment was marked as spam.

Preconditions.checkArgument(request != null, "ReadRowsRequest must not be null");

TableName tableName = TableName.parse(request.getTableName());

This comment was marked as spam.

String tableId = "";
if (tableName != null) {
tableId = tableName.getTable();
}

This comment was marked as spam.


Query query = new Query(tableId);
query.builder = ReadRowsRequest.newBuilder(request);

This comment was marked as spam.

return query;
}

private static ByteString wrapKey(String key) {
if (key == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,48 @@ private static ReadRowsRequest.Builder expectedProtoBuilder() {
.setTableName(TABLE_NAME.toString())
.setAppProfileId(APP_PROFILE_ID);
}

@Test
public void testFromProto() {
ReadRowsRequest request = ReadRowsRequest.newBuilder()
.setTableName(TABLE_NAME.toString())

This comment was marked as spam.

.setAppProfileId(APP_PROFILE_ID)
.setFilter(
RowFilter.newBuilder()
.setRowKeyRegexFilter(ByteString.copyFromUtf8(".*")))
.setRows(RowSet.newBuilder()
.addRowKeys(ByteString.copyFromUtf8("row-key"))
.addRowRanges(
RowRange.newBuilder()
.setStartKeyClosed(ByteString.copyFromUtf8("j"))
.setEndKeyClosed(ByteString.copyFromUtf8("z"))))
.build();
Query query = Query.fromProto(request);

assertThat(query.toProto(requestContext))
.isEqualTo(request);
}

@Test
public void testFromProtoWithEmptyTableId() {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

TableName EMPTY_TABLE_NAME = TableName.of("", "", "");
ReadRowsRequest request = ReadRowsRequest.newBuilder()
.setTableName(EMPTY_TABLE_NAME.toString())
.setFilter(
RowFilter.newBuilder()
.setRowKeyRegexFilter(
ByteString.copyFromUtf8(".*")))
.setRows(
RowSet.newBuilder()
.addRowKeys(ByteString.copyFromUtf8("row-key"))
.addRowRanges(
RowRange.newBuilder()
.setStartKeyClosed(ByteString.copyFromUtf8("j"))
.setEndKeyClosed(ByteString.copyFromUtf8("z"))))
.build();

RequestContext reqContext = RequestContext.create(InstanceName.of("", ""), "");
assertThat(Query.fromProto(request).toProto(reqContext))
.isEqualTo(request);
}
}