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: add write_mode property to BigQuery Storage Write API v1 #360

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions google/cloud/bigquery_storage_v1/types/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ class WriteStream(proto.Message):
generate data that's compatible with this schema to send in
initial ``AppendRowsRequest``. The table schema could go out
of date during the life time of the stream.
write_mode (google.cloud.bigquery_storage_v1.types.WriteStream.WriteMode):
Immutable. Mode of the stream.
tseaver marked this conversation as resolved.
Show resolved Hide resolved
"""

class Type(proto.Enum):
Expand All @@ -203,11 +205,17 @@ class Type(proto.Enum):
PENDING = 2
BUFFERED = 3

class WriteMode(proto.Enum):
r"""Mode enum of the stream."""
WRITE_MODE_UNSPECIFIED = 0
INSERT = 1

name = proto.Field(proto.STRING, number=1,)
type_ = proto.Field(proto.ENUM, number=2, enum=Type,)
create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,)
commit_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,)
table_schema = proto.Field(proto.MESSAGE, number=5, message=gcbs_table.TableSchema,)
write_mode = proto.Field(proto.ENUM, number=7, enum=WriteMode,)


__all__ = tuple(sorted(__protobuf__.manifest))
20 changes: 16 additions & 4 deletions tests/unit/gapic/bigquery_storage_v1/test_big_query_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ def test_create_write_stream(
) as call:
# Designate an appropriate return value for the call.
call.return_value = stream.WriteStream(
name="name_value", type_=stream.WriteStream.Type.COMMITTED,
name="name_value",
type_=stream.WriteStream.Type.COMMITTED,
write_mode=stream.WriteStream.WriteMode.INSERT,
)
response = client.create_write_stream(request)

Expand All @@ -517,6 +519,7 @@ def test_create_write_stream(
assert isinstance(response, stream.WriteStream)
assert response.name == "name_value"
assert response.type_ == stream.WriteStream.Type.COMMITTED
assert response.write_mode == stream.WriteStream.WriteMode.INSERT


def test_create_write_stream_from_dict():
Expand Down Expand Up @@ -559,7 +562,9 @@ async def test_create_write_stream_async(
# Designate an appropriate return value for the call.
call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
stream.WriteStream(
name="name_value", type_=stream.WriteStream.Type.COMMITTED,
name="name_value",
type_=stream.WriteStream.Type.COMMITTED,
write_mode=stream.WriteStream.WriteMode.INSERT,
)
)
response = await client.create_write_stream(request)
Expand All @@ -573,6 +578,7 @@ async def test_create_write_stream_async(
assert isinstance(response, stream.WriteStream)
assert response.name == "name_value"
assert response.type_ == stream.WriteStream.Type.COMMITTED
assert response.write_mode == stream.WriteStream.WriteMode.INSERT


@pytest.mark.asyncio
Expand Down Expand Up @@ -805,7 +811,9 @@ def test_get_write_stream(
with mock.patch.object(type(client.transport.get_write_stream), "__call__") as call:
# Designate an appropriate return value for the call.
call.return_value = stream.WriteStream(
name="name_value", type_=stream.WriteStream.Type.COMMITTED,
name="name_value",
type_=stream.WriteStream.Type.COMMITTED,
write_mode=stream.WriteStream.WriteMode.INSERT,
)
response = client.get_write_stream(request)

Expand All @@ -818,6 +826,7 @@ def test_get_write_stream(
assert isinstance(response, stream.WriteStream)
assert response.name == "name_value"
assert response.type_ == stream.WriteStream.Type.COMMITTED
assert response.write_mode == stream.WriteStream.WriteMode.INSERT


def test_get_write_stream_from_dict():
Expand Down Expand Up @@ -856,7 +865,9 @@ async def test_get_write_stream_async(
# Designate an appropriate return value for the call.
call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
stream.WriteStream(
name="name_value", type_=stream.WriteStream.Type.COMMITTED,
name="name_value",
type_=stream.WriteStream.Type.COMMITTED,
write_mode=stream.WriteStream.WriteMode.INSERT,
)
)
response = await client.get_write_stream(request)
Expand All @@ -870,6 +881,7 @@ async def test_get_write_stream_async(
assert isinstance(response, stream.WriteStream)
assert response.name == "name_value"
assert response.type_ == stream.WriteStream.Type.COMMITTED
assert response.write_mode == stream.WriteStream.WriteMode.INSERT


@pytest.mark.asyncio
Expand Down