Skip to content

gcvctor: StringBasedValueOf(typ, string) — string-payload constructor for arbitrary Types (parallel to BytesBasedValueOf) #232

Description

@apstndb

Problem

gcvctor has an asymmetry between bytes-backed and string-backed wire payloads:

This leaves no constructor for string-payload values whose Type is not a bare code — most concretely PG-dialect annotated scalars. spanner.PGNumeric carries a raw wire string (not *big.Rat), so spanenc has to hand-assemble the GCV literal today:

// spanenc encode.go — the only hand-built GCV in the package
return gcv{
        Type:  typector.PGNumeric(),
        Value: structpb.NewStringValue(v.Numeric),
}

Suggested fix

Add the parallel constructor:

// StringBasedValueOf constructs a GenericColumnValue with an arbitrary
// string-compatible Type and the wire string stored as-is (no validation),
// like BytesBasedValueOf for base64 payloads.
func StringBasedValueOf(typ *sppb.Type, v string) spanner.GenericColumnValue

with the same no-validation caveats as StringBasedValueFromCode (caller supplies the canonical wire form). StringBasedValueFromCode then reads as the simple-code convenience over it.

This also unblocks the spanner.PGNumeric counterpart discussed in #207 (its FromNullable needs a raw-string path, not PGNumericValue(*big.Rat)).

Related

Feedback from building spanenc's encodeValue mirror on gcvctor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:highShould be addressed soon; correctness or release blocker

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions