Skip to content

Commit

Permalink
feat: add FLOAT32 enum to TypeCode (#1081)
Browse files Browse the repository at this point in the history
* feat(spanner): add proto descriptors for proto and enum types in create/update/get database ddl requests

PiperOrigin-RevId: 601013501

Source-Link: googleapis/googleapis@81b24a5

Source-Link: googleapis/googleapis-gen@46f0446
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDZmMDQ0NjAzNzkwNmYwZDkwNTM2NTgzNWYwMmE2NTIyNDFmM2RlMyJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* feat: add FLOAT32 enum to TypeCode

PiperOrigin-RevId: 601176446

Source-Link: googleapis/googleapis@584ecd4

Source-Link: googleapis/googleapis-gen@0bdb815
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMGJkYjgxNTc3OWQwZmQ3ODI0YmFmZmYwYzkxMDQ2YTdkY2E1Y2Q1ZiJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
3 people committed Jan 28, 2024
1 parent f3b23b2 commit 5b94dac
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
Expand Up @@ -355,6 +355,26 @@ class CreateDatabaseRequest(proto.Message):
database_dialect (google.cloud.spanner_admin_database_v1.types.DatabaseDialect):
Optional. The dialect of the Cloud Spanner
Database.
proto_descriptors (bytes):
Optional. Proto descriptors used by CREATE/ALTER PROTO
BUNDLE statements in 'extra_statements' above. Contains a
protobuf-serialized
`google.protobuf.FileDescriptorSet <https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto>`__.
To generate it,
`install <https://grpc.io/docs/protoc-installation/>`__ and
run ``protoc`` with --include_imports and
--descriptor_set_out. For example, to generate for
moon/shot/app.proto, run
::
$protoc --proto_path=/app_path --proto_path=/lib_path \
--include_imports \
--descriptor_set_out=descriptors.data \
moon/shot/app.proto
For more details, see protobuffer `self
description <https://developers.google.com/protocol-buffers/docs/techniques#self-description>`__.
"""

parent: str = proto.Field(
Expand All @@ -379,6 +399,10 @@ class CreateDatabaseRequest(proto.Message):
number=5,
enum=common.DatabaseDialect,
)
proto_descriptors: bytes = proto.Field(
proto.BYTES,
number=6,
)


class CreateDatabaseMetadata(proto.Message):
Expand Down Expand Up @@ -521,6 +545,25 @@ class UpdateDatabaseDdlRequest(proto.Message):
underscore. If the named operation already exists,
[UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl]
returns ``ALREADY_EXISTS``.
proto_descriptors (bytes):
Optional. Proto descriptors used by CREATE/ALTER PROTO
BUNDLE statements. Contains a protobuf-serialized
`google.protobuf.FileDescriptorSet <https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto>`__.
To generate it,
`install <https://grpc.io/docs/protoc-installation/>`__ and
run ``protoc`` with --include_imports and
--descriptor_set_out. For example, to generate for
moon/shot/app.proto, run
::
$protoc --proto_path=/app_path --proto_path=/lib_path \
--include_imports \
--descriptor_set_out=descriptors.data \
moon/shot/app.proto
For more details, see protobuffer `self
description <https://developers.google.com/protocol-buffers/docs/techniques#self-description>`__.
"""

database: str = proto.Field(
Expand All @@ -535,6 +578,10 @@ class UpdateDatabaseDdlRequest(proto.Message):
proto.STRING,
number=3,
)
proto_descriptors: bytes = proto.Field(
proto.BYTES,
number=4,
)


class DdlStatementActionInfo(proto.Message):
Expand Down Expand Up @@ -682,12 +729,22 @@ class GetDatabaseDdlResponse(proto.Message):
A list of formatted DDL statements defining
the schema of the database specified in the
request.
proto_descriptors (bytes):
Proto descriptors stored in the database. Contains a
protobuf-serialized
`google.protobuf.FileDescriptorSet <https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto>`__.
For more details, see protobuffer `self
description <https://developers.google.com/protocol-buffers/docs/techniques#self-description>`__.
"""

statements: MutableSequence[str] = proto.RepeatedField(
proto.STRING,
number=1,
)
proto_descriptors: bytes = proto.Field(
proto.BYTES,
number=2,
)


class ListDatabaseOperationsRequest(proto.Message):
Expand Down
4 changes: 4 additions & 0 deletions google/cloud/spanner_v1/types/type.py
Expand Up @@ -50,6 +50,9 @@ class TypeCode(proto.Enum):
FLOAT64 (3):
Encoded as ``number``, or the strings ``"NaN"``,
``"Infinity"``, or ``"-Infinity"``.
FLOAT32 (15):
Encoded as ``number``, or the strings ``"NaN"``,
``"Infinity"``, or ``"-Infinity"``.
TIMESTAMP (4):
Encoded as ``string`` in RFC 3339 timestamp format. The time
zone must be present, and must be ``"Z"``.
Expand Down Expand Up @@ -104,6 +107,7 @@ class TypeCode(proto.Enum):
BOOL = 1
INT64 = 2
FLOAT64 = 3
FLOAT32 = 15
TIMESTAMP = 4
DATE = 5
STRING = 6
Expand Down
4 changes: 2 additions & 2 deletions scripts/fixup_spanner_admin_database_v1_keywords.py
Expand Up @@ -41,7 +41,7 @@ class spanner_admin_databaseCallTransformer(cst.CSTTransformer):
METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
'copy_backup': ('parent', 'backup_id', 'source_backup', 'expire_time', 'encryption_config', ),
'create_backup': ('parent', 'backup_id', 'backup', 'encryption_config', ),
'create_database': ('parent', 'create_statement', 'extra_statements', 'encryption_config', 'database_dialect', ),
'create_database': ('parent', 'create_statement', 'extra_statements', 'encryption_config', 'database_dialect', 'proto_descriptors', ),
'delete_backup': ('name', ),
'drop_database': ('database', ),
'get_backup': ('name', ),
Expand All @@ -58,7 +58,7 @@ class spanner_admin_databaseCallTransformer(cst.CSTTransformer):
'test_iam_permissions': ('resource', 'permissions', ),
'update_backup': ('backup', 'update_mask', ),
'update_database': ('database', 'update_mask', ),
'update_database_ddl': ('database', 'statements', 'operation_id', ),
'update_database_ddl': ('database', 'statements', 'operation_id', 'proto_descriptors', ),
}

def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:
Expand Down
Expand Up @@ -2377,6 +2377,7 @@ def test_get_database_ddl(request_type, transport: str = "grpc"):
# Designate an appropriate return value for the call.
call.return_value = spanner_database_admin.GetDatabaseDdlResponse(
statements=["statements_value"],
proto_descriptors=b"proto_descriptors_blob",
)
response = client.get_database_ddl(request)

Expand All @@ -2388,6 +2389,7 @@ def test_get_database_ddl(request_type, transport: str = "grpc"):
# Establish that the response is the type that we expect.
assert isinstance(response, spanner_database_admin.GetDatabaseDdlResponse)
assert response.statements == ["statements_value"]
assert response.proto_descriptors == b"proto_descriptors_blob"


def test_get_database_ddl_empty_call():
Expand Down Expand Up @@ -2426,6 +2428,7 @@ async def test_get_database_ddl_async(
call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
spanner_database_admin.GetDatabaseDdlResponse(
statements=["statements_value"],
proto_descriptors=b"proto_descriptors_blob",
)
)
response = await client.get_database_ddl(request)
Expand All @@ -2438,6 +2441,7 @@ async def test_get_database_ddl_async(
# Establish that the response is the type that we expect.
assert isinstance(response, spanner_database_admin.GetDatabaseDdlResponse)
assert response.statements == ["statements_value"]
assert response.proto_descriptors == b"proto_descriptors_blob"


@pytest.mark.asyncio
Expand Down Expand Up @@ -8444,6 +8448,7 @@ def test_get_database_ddl_rest(request_type):
# Designate an appropriate value for the returned response.
return_value = spanner_database_admin.GetDatabaseDdlResponse(
statements=["statements_value"],
proto_descriptors=b"proto_descriptors_blob",
)

# Wrap the value into a proper Response obj
Expand All @@ -8460,6 +8465,7 @@ def test_get_database_ddl_rest(request_type):
# Establish that the response is the type that we expect.
assert isinstance(response, spanner_database_admin.GetDatabaseDdlResponse)
assert response.statements == ["statements_value"]
assert response.proto_descriptors == b"proto_descriptors_blob"


def test_get_database_ddl_rest_required_fields(
Expand Down

0 comments on commit 5b94dac

Please sign in to comment.