-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Spanner should have helpful aliases for param types #3364
Comments
@jonparrott Aliasing the "scalar" types is easy (PR #3670). What do you envision for array / struct? |
@tseaver would param_types = {
tags: list,
metadata: dict
} |
Oh nevermind, ignore my last comment, I'm being thick. What does it look like today to if you need to specify an array / struct? |
@jonparrott For arrays, you have to pass the type of the elements: array_type = type_pb2.Type(
code=type_pb2.ARRAY, array_element_type=type_pb2.Type(code=type_pb2.INT64)) For structs, you have to construct / pass a struct_type_pb = type_pb2.StructType(fields=[
type_pb2.StructType.Field(name='name', type=type_pb2.Type(code=type_pb2.STRING)),
type_pb2.StructType.Field(name='age', type=type_pb2.Type(code=type_pb2.INT64)),
])
my_struct_type = type_pb2.Type(code=type_pb2.STRUCT, struct_type=struct_type_pb) |
@tseaver that's pretty rough. Is it possible to make it into something like: from google.cloud.spanner import types
array_type = types.Array(types.INT64) struct_type = types.Struct(
types.StructField('name', types.STRING),
types.StructField('age', types.INT64)),
) |
@jonparrott Assuming you meant to have the open square bracket after |
Actually I didn't, I meant for types.Struct to just use *args. But yeah, let's do it. :) |
@jonparrott Should we name those factories |
Sure, if that's all they're used for. |
Conceptually they describe types of returned cell values, too, but we don't expose that. |
Having to do:
Is rather awkward, it would be much more friendly to have:
or similar
The text was updated successfully, but these errors were encountered: