rowstruct

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package rowstruct materializes a STRUCT column value for SQL clients: the Go analogue of Java's RowStruct family, where a struct column read off a record surfaces as a RelationalStruct rather than as the raw protobuf message.

Java's chain is RowStruct.getObject → getStruct → `new ImmutableRowStruct(new MessageTuple((Message) obj), metaData.getStructMetaData(col))` (RowStruct.java:184-197, :281-302), with MessageTuple reading the message POSITIONALLY over its descriptor's fields (MessageTuple.java:53-78) and RelationalStructMetaData backed by the struct's DataType (RelationalStructMetaData.java:40-135). This package is the same three pieces: MessageStruct (the struct), its positional accessor over the descriptor, and StructMetaData over an api.StructType.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataTypeOf

func DataTypeOf(typ values.Type) (api.DataType, error)

DataTypeOf is the public DataType of a planned type: Java's DataTypeUtils.toRelationalType, which a result set's metadata reports (RelationalStructMetaData over the plan's result type). A struct keeps its declared type name and its fields, an array its element type. A type with no public form (a vector, an unresolved type) is an error.

func NonArrayCorrelationError

func NonArrayCorrelationError(typ values.Type) error

NonArrayCorrelationError is Java's INVALID_COLUMN_REFERENCE for a correlated FROM item whose column is typ, not an array, with typ rendered as Java's DataType.toString renders it (`long ∪ ∅`). A type with no public rendering falls back to its own spelling.

Types

type ArrayBuilder

type ArrayBuilder struct {
	// contains filtered or unexported fields
}

ArrayBuilder builds an api.Array element by element: Java's EmbeddedRelationalArray.newBuilder() (EmbeddedRelationalArray.java:50-140). Every element has the type of the first.

func NewArrayBuilder

func NewArrayBuilder() *ArrayBuilder

NewArrayBuilder returns an empty builder.

func (*ArrayBuilder) AddBytes

func (b *ArrayBuilder) AddBytes(v []byte) *ArrayBuilder

AddBytes adds a BYTES element.

func (*ArrayBuilder) AddLong

func (b *ArrayBuilder) AddLong(v int64) *ArrayBuilder

AddLong adds a BIGINT element.

func (*ArrayBuilder) AddString

func (b *ArrayBuilder) AddString(v string) *ArrayBuilder

AddString adds a STRING element.

func (*ArrayBuilder) AddStruct

func (b *ArrayBuilder) AddStruct(v api.Struct) *ArrayBuilder

AddStruct adds a STRUCT element.

func (*ArrayBuilder) AddUUID

func (b *ArrayBuilder) AddUUID(v uuid.UUID) *ArrayBuilder

AddUUID adds a UUID element.

func (*ArrayBuilder) Build

func (b *ArrayBuilder) Build() api.Array

Build returns the array. An empty array's elements are NULL-typed, as Java's are.

type MessageStruct

type MessageStruct struct {
	// contains filtered or unexported fields
}

MessageStruct is an api.Struct over a proto message — Java's ImmutableRowStruct wrapping a MessageTuple.

Attributes are read POSITIONALLY off the descriptor, which is Java's contract (MessageTuple.getObject's `descriptor.getFields().get(position)`) and the only sound one: two same-named fields cannot occur in a descriptor, but position is what the metadata's ordinals mean.

func New

New builds the struct view of a proto message. The metadata is derived from the message's own descriptor, so a struct read back through it reports the DECLARED struct type name (Java: RelationalStructMetaData .getTypeName, :62-65).

func (*MessageStruct) Attribute

func (s *MessageStruct) Attribute(oneBasedIndex int) (any, error)

Attribute returns the attribute at oneBasedIndex (JDBC convention).

func (*MessageStruct) AttributeByName

func (s *MessageStruct) AttributeByName(name string) (any, error)

AttributeByName looks the attribute up by name, case-insensitively — Java resolves a struct attribute name the same way (RelationalStruct.getOneBasedPosition:156-164, equalsIgnoreCase).

func (*MessageStruct) AttributeCount

func (s *MessageStruct) AttributeCount() int

AttributeCount returns the number of attributes.

func (*MessageStruct) Attributes

func (s *MessageStruct) Attributes() []any

Attributes returns every attribute in declared order. An attribute that cannot be materialized surfaces as nil rather than an error, because the interface has no error channel here; every caller that needs the failure uses Attribute.

func (*MessageStruct) MetaData

func (s *MessageStruct) MetaData() api.StructMetaData

MetaData returns the struct's metadata.

type OrdinalStruct

type OrdinalStruct struct {
	// contains filtered or unexported fields
}

OrdinalStruct is the SQL-client view of a record-valued ordinal row. The executor keeps nested records as positional rows so further FieldValues can address them by baked ordinal; the public boundary exposes the same value as api.Struct, just as MessageStruct does for a protobuf-backed record.

func NewOrdinal

func NewOrdinal(row TypedOrdinalRow) (*OrdinalStruct, error)

NewOrdinal validates and wraps one exact positional record. It deliberately has no width/name recovery: a malformed row is an executor bug, not a struct whose missing attributes should quietly read as NULL.

func (*OrdinalStruct) Attribute

func (s *OrdinalStruct) Attribute(oneBasedIndex int) (any, error)

Attribute reads the one-based attribute and recursively materializes nested ordinal/protobuf records and arrays into their public representations.

func (*OrdinalStruct) AttributeByName

func (s *OrdinalStruct) AttributeByName(name string) (any, error)

AttributeByName resolves a unique field case-insensitively. Duplicate exact record labels remain ambiguous; ordinal access is always available.

func (*OrdinalStruct) AttributeCount

func (s *OrdinalStruct) AttributeCount() int

AttributeCount returns the number of positional record fields.

func (*OrdinalStruct) Attributes

func (s *OrdinalStruct) Attributes() []any

Attributes returns all attributes in declared order. As with MessageStruct, the interface has no error channel, so an individually malformed attribute is represented as nil; callers needing the error use Attribute.

func (*OrdinalStruct) MetaData

func (s *OrdinalStruct) MetaData() api.StructMetaData

MetaData returns metadata derived from the exact planner RecordType.

type StructBuilder

type StructBuilder struct {
	// contains filtered or unexported fields
}

StructBuilder builds an api.Struct attribute by attribute, the value a direct-access insert takes: Java's EmbeddedRelationalStruct.newBuilder() (EmbeddedRelationalStruct.java:42-121). Attribute names are kept as given; a direct-access insert matches them against the table's column names.

func NewStructBuilder

func NewStructBuilder() *StructBuilder

NewStructBuilder returns an empty builder.

func (*StructBuilder) AddArray

func (b *StructBuilder) AddArray(name string, v api.Array) *StructBuilder

AddArray adds an ARRAY attribute.

func (*StructBuilder) AddBoolean

func (b *StructBuilder) AddBoolean(name string, v bool) *StructBuilder

AddBoolean adds a BOOLEAN attribute.

func (*StructBuilder) AddBytes

func (b *StructBuilder) AddBytes(name string, v []byte) *StructBuilder

AddBytes adds a BYTES attribute.

func (*StructBuilder) AddDouble

func (b *StructBuilder) AddDouble(name string, v float64) *StructBuilder

AddDouble adds a DOUBLE attribute.

func (*StructBuilder) AddFloat

func (b *StructBuilder) AddFloat(name string, v float32) *StructBuilder

AddFloat adds a FLOAT attribute.

func (*StructBuilder) AddInt

func (b *StructBuilder) AddInt(name string, v int32) *StructBuilder

AddInt adds an INTEGER attribute.

func (*StructBuilder) AddLong

func (b *StructBuilder) AddLong(name string, v int64) *StructBuilder

AddLong adds a BIGINT attribute.

func (*StructBuilder) AddString

func (b *StructBuilder) AddString(name, v string) *StructBuilder

AddString adds a STRING attribute.

func (*StructBuilder) AddStruct

func (b *StructBuilder) AddStruct(name string, v api.Struct) *StructBuilder

AddStruct adds a STRUCT attribute.

func (*StructBuilder) AddUUID

func (b *StructBuilder) AddUUID(name string, v uuid.UUID) *StructBuilder

AddUUID adds a UUID attribute.

func (*StructBuilder) Build

func (b *StructBuilder) Build() api.Struct

Build returns the struct. Its type is anonymous, as Java's is (ANONYMOUS_STRUCT_<uuid>).

type StructMetaData

type StructMetaData struct {
	// contains filtered or unexported fields
}

StructMetaData is api.StructMetaData backed by an api.StructType — Java's RelationalStructMetaData (RelationalStructMetaData.java:40-135).

func NewStructMetaData

func NewStructMetaData(t *api.StructType) *StructMetaData

NewStructMetaData wraps a struct type as struct metadata.

func (*StructMetaData) AttributeCount

func (m *StructMetaData) AttributeCount() int

AttributeCount returns the number of attributes.

func (*StructMetaData) AttributeDataType

func (m *StructMetaData) AttributeDataType(oneBasedIndex int) (api.DataType, error)

AttributeDataType returns the attribute's full DataType.

func (*StructMetaData) AttributeName

func (m *StructMetaData) AttributeName(oneBasedIndex int) (string, error)

AttributeName returns the attribute's declared name.

func (*StructMetaData) AttributeNullable

func (m *StructMetaData) AttributeNullable(oneBasedIndex int) (int, error)

AttributeNullable reports whether the attribute admits NULL.

func (*StructMetaData) AttributeType

func (m *StructMetaData) AttributeType(oneBasedIndex int) (int, error)

AttributeType returns the attribute's JDBC type code.

func (*StructMetaData) AttributeTypeName

func (m *StructMetaData) AttributeTypeName(oneBasedIndex int) (string, error)

AttributeTypeName returns the attribute type's display name.

func (*StructMetaData) TypeName

func (m *StructMetaData) TypeName() string

TypeName returns the declared struct type name.

type TypedOrdinalRow

type TypedOrdinalRow interface {
	values.OrdinalRow
	OrdinalRecordType() *values.RecordType
	OrdinalRowKind() values.OrdinalCarrierKind
}

TypedOrdinalRow is the exact, positional representation accepted by NewOrdinal. executor.PositionalRow implements it without making rowstruct depend on the executor package (which is a higher layer).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL