Documentation
¶
Overview ¶
Package spantype formats Cloud Spanner google.spanner.v1.Type values with multiple verbosity levels for logs, errors, and debugging output. Dialect sppb.Type.TypeAnnotation values (for example PostgreSQL PG_NUMERIC) are controlled by TypeAnnotationMode inside FormatOption.
Index ¶
- Variables
- func EquivalentTypes(a, b *sppb.Type) bool
- func FormatProtoEnum(typ *sppb.Type, mode ProtoEnumMode) string
- func FormatStructFields(fields []*sppb.StructType_Field, opts FormatOption) string
- func FormatType(typ *sppb.Type, opts FormatOption) string
- func FormatTypeCode(code sppb.TypeCode, mode UnknownMode) string
- func FormatTypeMoreVerbose(typ *sppb.Type) string
- func FormatTypeNormal(typ *sppb.Type) string
- func FormatTypePostgreSQL(typ *sppb.Type) string
- func FormatTypeSimple(typ *sppb.Type) string
- func FormatTypeSimplest(typ *sppb.Type) string
- func FormatTypeVerbose(typ *sppb.Type) string
- type ArrayMode
- type FormatOption
- type ProtoEnumMode
- type StructMode
- type TypeAnnotationMode
- type UnknownMode
Constants ¶
This section is empty.
Variables ¶
var ( // FormatOptionSimplest is a FormatOption for FormatTypeSimplest. FormatOptionSimplest = FormatOption{ Struct: StructModeBase, Proto: ProtoEnumModeBase, Enum: ProtoEnumModeBase, Array: ArrayModeBase, Unknown: UnknownModeTypeCode, } // FormatOptionSimple is a FormatOption for FormatTypeSimple. FormatOptionSimple = FormatOption{ Struct: StructModeBase, Proto: ProtoEnumModeLeaf, Enum: ProtoEnumModeLeaf, Array: ArrayModeRecursive, Unknown: UnknownModeUnknown, } // FormatOptionNormal is a FormatOption for FormatTypeNormal. FormatOptionNormal = FormatOption{ Struct: StructModeRecursive, Proto: ProtoEnumModeLeaf, Enum: ProtoEnumModeLeaf, Array: ArrayModeRecursive, Unknown: UnknownModeVerbose, } // FormatOptionVerbose is a FormatOption for FormatTypeVerbose. FormatOptionVerbose = FormatOption{ Struct: StructModeRecursiveWithName, Proto: ProtoEnumModeFull, Enum: ProtoEnumModeFull, Array: ArrayModeRecursive, Unknown: UnknownModeVerbose, } // FormatOptionMoreVerbose is a FormatOption for FormatTypeMoreVerbose. FormatOptionMoreVerbose = FormatOption{ Struct: StructModeRecursiveWithName, Proto: ProtoEnumModeFullWithKind, Enum: ProtoEnumModeFullWithKind, Array: ArrayModeRecursive, Unknown: UnknownModeVerbose, } )
Functions ¶
func EquivalentTypes ¶ added in v0.3.13
EquivalentTypes reports whether a and b are Spanner-equivalent cloud.google.com/go/spanner/apiv1/spannerpb.Type metadata for identity retyping: a value of either type can carry the same wire payload when only Type metadata differs in ways that do not affect type identity.
EquivalentTypes is stricter than wire-encoding compatibility: sppb.Type.TypeAnnotation and sppb.Type.ProtoTypeFqn are part of type identity even when serialization is unchanged.
Rules follow [google.spanner.v1.Type] shape (https://github.com/googleapis/googleapis/blob/master/google/spanner/v1/type.proto) and GoogleSQL supertypes for composite types (https://docs.cloud.google.com/spanner/docs/reference/standard-sql/conversion_rules#supertypes):
- Scalars: same TypeCode, TypeAnnotation, and ProtoTypeFqn; container fields must be absent. Unknown protobuf fields are intentionally ignored.
- ARRAY: equivalent sppb.Type.ArrayElementType; sppb.Type.StructType must be absent.
- STRUCT: same number of fields with pairwise equivalent field types by position; field names are not compared. sppb.Type.ArrayElementType must be absent.
This is narrower than the Cast table in the same conversion-rules page: types that can CAST to one another (for example INT64 and FLOAT64) are not necessarily equivalent. Use EquivalentTypes only when semantics require an identity path (no value conversion), such as ARRAY/STRUCT layout checks or gcvctor.WithEquivalentType.
func FormatProtoEnum ¶ added in v0.2.0
func FormatProtoEnum(typ *sppb.Type, mode ProtoEnumMode) string
FormatProtoEnum formats `PROTO` or `ENUM` type using ProtoEnumMode. It panics when the input type is not `PROTO` or `ENUM`.
func FormatStructFields ¶
func FormatStructFields(fields []*sppb.StructType_Field, opts FormatOption) string
FormatStructFields formats Cloud Spanner struct fields or `metadata.rowType` using the given FormatOption.
func FormatType ¶
func FormatType(typ *sppb.Type, opts FormatOption) string
FormatType formats Cloud Spanner type using the given FormatOption. FormatOption.TypeAnnotation selects whether sppb.Type.TypeAnnotation is omitted, appended in parentheses after the base type, or used as the primary label (see TypeAnnotationMode).
func FormatTypeCode ¶ added in v0.2.0
func FormatTypeCode(code sppb.TypeCode, mode UnknownMode) string
FormatTypeCode formats sppb.TypeCode, but it formats unknown type code as `UNKNOWN(int32(code))`. e.g. `UNKNOWN(-1)`
func FormatTypeMoreVerbose ¶ added in v0.3.0
FormatTypeMoreVerbose formats Cloud Spanner type as more verbose format. e.g. `INT64`, `ARRAY<INT64>`, `PROTO<examples.ProtoType>`, `ENUM<examples.EnumType>`, `STRUCT<n INT64>`
func FormatTypeNormal ¶
FormatTypeNormal formats Cloud Spanner type as normal format. e.g. `INT64`, `ARRAY<INT64>`, `ProtoType`, `EnumType`, `STRUCT<INT64>`
func FormatTypePostgreSQL ¶ added in v0.3.12
FormatTypePostgreSQL renders a sppb.Type using PostgreSQL-dialect spellings from https://docs.cloud.google.com/spanner/docs/reference/postgresql/data-types (supported types: bool, bytea, date, float4, float8, bigint, interval, jsonb, numeric, timestamptz, text, uuid, oid, and `T[]` array declarations). sppb.TypeCode_JSON is rendered "jsonb" only when the type carries sppb.TypeAnnotationCode_PG_JSONB (otherwise "json", a label that preserves the wire distinction even though plain JSON is not a PostgreSQL data type), and sppb.TypeCode_INT64 with sppb.TypeAnnotationCode_PG_OID is rendered "oid". A nil type renders as the empty string.
sppb.TypeCode_PROTO and sppb.TypeCode_ENUM are not PostgreSQL-interface types: they render as "proto" and "enum" — not as "bytea" or "text" — so wire types are never mislabeled if they appear in metadata. sppb.TypeCode_STRUCT does not appear in PostgreSQL-dialect metadata in practice today; the provisional rendering uses GoogleSQL STRUCT<...> declaration syntax with field types spelled using the PostgreSQL names above, and may change once official guidance for composite types exists (no stability guarantee for the STRUCT branch).
This function originated as FormatPostgreSQLType in github.com/apstndb/spanpg, where its spellings are pinned against PostgreSQL-dialect Spanner databases by integration probes.
func FormatTypeSimple ¶
FormatTypeSimple formats Cloud Spanner type as simple format. e.g. `INT64`, `ARRAY<INT64>`, `ProtoType`, `EnumType`, `STRUCT`
func FormatTypeSimplest ¶
FormatTypeSimplest formats Cloud Spanner type as simplest format. e.g. `INT64`, `ARRAY`, `PROTO`, `ENUM`, `STRUCT`
func FormatTypeVerbose ¶
FormatTypeVerbose formats Cloud Spanner type as verbose format. e.g. `INT64`, `ARRAY<INT64>`, `examples.ProtoType`, `examples.EnumType`, `STRUCT<n INT64>`
Types ¶
type ArrayMode ¶
type ArrayMode int
ArrayMode controls how ARRAY types are rendered by selecting either base or recursive element rendering.
type FormatOption ¶
type FormatOption struct {
// Struct controls STRUCT formatting.
Struct StructMode
// Proto controls PROTO formatting.
Proto ProtoEnumMode
// Enum controls ENUM formatting.
Enum ProtoEnumMode
// Array controls ARRAY formatting.
Array ArrayMode
// Unknown controls formatting for unknown type codes.
Unknown UnknownMode
// TypeAnnotation controls how dialect TypeAnnotation is combined with the base type.
TypeAnnotation TypeAnnotationMode
}
FormatOption is an option for FormatType, and FormatStructFields.
Callers building their own values should use keyed struct literals (e.g. FormatOption{Struct: ..., Proto: ...}) so that new fields can be added in minor releases without breaking compilation. Positional literals are fragile.
type ProtoEnumMode ¶ added in v0.2.0
type ProtoEnumMode int
ProtoEnumMode controls how PROTO and ENUM types are rendered by selecting base, leaf, full-name, or explicit-kind output.
const ( // ProtoEnumModeBase formats `PROTO` and `ENUM` type as `PROTO` and `ENUM`. ProtoEnumModeBase ProtoEnumMode = iota // ProtoEnumModeLeaf formats `PROTO` and `ENUM` type without package name. e.g. `ProtoType`, `EnumType` ProtoEnumModeLeaf // ProtoEnumModeFull formats `PROTO` and `ENUM` type as full qualified name. e.g. `examples.ProtoType`, `examples.EnumType` ProtoEnumModeFull // ProtoEnumModeLeafWithKind formats `PROTO` and `ENUM` type without package name with kind. // e.g. `PROTO<ProtoType>`, `ENUM<EnumType>` ProtoEnumModeLeafWithKind // ProtoEnumModeFullWithKind formats `PROTO` and `ENUM` type as full qualified name with kind. // e.g. `PROTO<examples.ProtoType>`, `ENUM<examples.EnumType>`. // Note: It should be same format with `INFORMATION_SCHEMA.COLUMNS.SPANNER_TYPE`. ProtoEnumModeFullWithKind )
type StructMode ¶
type StructMode int
StructMode controls how STRUCT types are rendered by selecting one of StructModeBase, StructModeRecursive, or StructModeRecursiveWithName.
const ( // StructModeBase formats `STRUCT` type as `STRUCT`. StructModeBase StructMode = iota // StructModeRecursive formats `STRUCT` type with field types. e.g. `STRUCT<INT64, STRUCT<INT64>>` StructModeRecursive // StructModeRecursiveWithName formats `STRUCT` type with field types with field name. e.g. `STRUCT<n INT64, s STRUCT<n INT64>>` StructModeRecursiveWithName )
type TypeAnnotationMode ¶ added in v0.3.11
type TypeAnnotationMode int
TypeAnnotationMode controls how sppb.Type.TypeAnnotation is rendered for simple and container types (recursively for ARRAY and STRUCT fields).
const ( // TypeAnnotationModeSuffix is the default (zero value): append a parenthetical // annotation when set, e.g. `NUMERIC(PG_NUMERIC)`. TypeAnnotationModeSuffix TypeAnnotationMode = iota // TypeAnnotationModeOmit ignores TypeAnnotation and formats the base type only, e.g. `NUMERIC`. TypeAnnotationModeOmit // TypeAnnotationModePrimary uses the annotation as the displayed type label when non-UNSPECIFIED, // e.g. `PG_NUMERIC` instead of `NUMERIC` or `NUMERIC(PG_NUMERIC)`. TypeAnnotationModePrimary )
type UnknownMode ¶ added in v0.3.0
type UnknownMode int
UnknownMode controls how unknown type codes are rendered by selecting UNKNOWN, the raw numeric code, a verbose form, or panic behavior.
const ( // UnknownModeUnknown formats unknown type code as `UNKNOWN` UnknownModeUnknown UnknownMode = iota // UnknownModeTypeCode formats unknown type code as e.g. `-1` UnknownModeTypeCode // UnknownModeVerbose formats unknown type code as `UNKNOWN(int32(code))` as e.g. `UNKNOWN(-1)` UnknownModeVerbose // UnknownModePanic panics when type code is unknown. UnknownModePanic )
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
spantype
command
|
|
|
Package typector provides small constructor helpers for building Cloud Spanner google.spanner.v1.Type values and struct fields in tests and callers.
|
Package typector provides small constructor helpers for building Cloud Spanner google.spanner.v1.Type values and struct fields in tests and callers. |