Go · Reads and Writes

Reads and Writes

import "github.com/unum-cloud/ustore" 1.0.0-rc.1 · 084197c4

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/ustore/go/reads-and-writes.md' | claude -p "How would this fit my code?"

Keys are []Key, viewed in place, and values are a Tape: bytes end to end around one more offset than values, as Apache Arrow lays them out. TapeOf packs strings or byte slices into a fresh tape, while U32Tape and U64Tape view bytes and offsets the caller already holds, without a copy. A read answers Values, which addresses the tape in the arena rather than copying out of it, reports a missing key as absent, and passes the whole batch back through Values.Tape, so a tape a read wrote is written again as it is. Since every result views the arena as Go slices, a verb into an arena whose Describe reports HostAccessRefused fails with StatusDevice before it runs, while managed memory and Apple’s shared memory read in place. A write carries values and nothing else, so an empty value is still a value, and BlobsRemove removes keys, or ranges given end keys.

ada, grace, kent := ustore.KeyFromUint64(1), ustore.KeyFromUint64(2), ustore.KeyFromUint64(3)
err := database.BlobsWrite(people, []ustore.Key{ada, grace}, ustore.TapeOf("Ada", "Grace"), nil)

values, err := database.BlobsRead(people, []ustore.Key{ada, grace, kent}, arena, nil)
name, ok := values.Get(0)    // "Ada", true
_, ok = values.Get(2)        // false
headers, err := database.BlobsRead(people, []ustore.Key{ada}, arena, &ustore.BlobsReadConfig{Limits: []uint64{2}})
err = database.BlobsRemove(people, []ustore.Key{grace}, nil)

API

Types

ArrowArrayArrowArray is the Arrow C data interface's array of one column, laid out as struct ArrowArray.
db.go:32 ↗
type ArrowArray C.struct_ArrowArray
BlobsReadConfigBlobsReadConfig carries the optional arguments of DatabaseOn.BlobsRead.
db.go:246 ↗
type BlobsReadConfig struct {
    Offsets []uint64
    Limits []uint64
}

Fields

Offsets[]uint64Offsets are the byte offsets into every value the read starts at, one per key, or whole values when empty.
Limits[]uint64Limits cap the bytes read of every value from its offset, one per key, or the rest when empty.
BlobsScanConfigBlobsScanConfig carries the optional arguments of DatabaseOn.BlobsScan.
db.go:302 ↗
type BlobsScanConfig struct {
    StartKeys []Key
    EndKeys []Key
    Direction ScanDirection
    Patterns Patterns
    Predicate Admitter
    Mode ScanMode
    Progress ProgressCallback
}

Fields

StartKeys[]KeyStartKeys are the inclusive starts of the scans, one per task, or the first key in Direction when empty.
EndKeys[]KeyEndKeys are the keys every scan stops before, one per task, or no bound when empty.
DirectionScanDirectionDirection is which way every scan goes from its start.
PatternsPatternsPatterns keep the keys whose values match, shared by every scan.
PredicateAdmitterPredicate admits or passes over the listed keys.
ModeScanModeMode is in what order the keys come.
ProgressProgressCallbackProgress reports the scans finished, and may cancel the call.
IngestRowsIngestRows is one batch of rows: keys and values for blobs, documents and pages, values as the strings and keys as what they map onto for strings, and sources, targets and optional edge identifiers for graphs.
db.go:2014 ↗
type IngestRows struct {
    Keys []Key
    Values Tape
    Sources []Key
    Targets []Key
    Edges []Key
}

Fields

Keys[]KeyKeys are the keys of blobs, documents and pages, or the keys strings map onto.
ValuesTapeValues are the values of blobs, JSON documents and XML pages, or the strings of a strings collection.
Sources[]KeySources are the sources of edges.
Targets[]KeyTargets are the targets of edges.
Edges[]KeyEdges are the identifiers of edges, or nothing for the default identifier of each.
RemoveConfigRemoveConfig carries the optional arguments of a removal by key or by range.
db.go:39 ↗
type RemoveConfig struct {
    EndKeys []Key
    Durability Durability
}

Fields

EndKeys[]KeyEndKeys turns every key into the inclusive start of a range ending before its end key, one per task, or removes the keys alone when empty.
DurabilityDurabilityDurability is how durable the removals are once the call finishes at the head.
StringsCursorConfigStringsCursorConfig carries the optional arguments of DatabaseOn.StringsCursorInit.
db.go:319 ↗
type StringsCursorConfig struct {
    Prefix string
    StartString string
    EndString string
    Direction ScanDirection
    Patterns Patterns
    Predicate Admitter
}

Fields

PrefixstringPrefix is what every string the walk returns starts with, or nothing to match every string.
StartStringstringStartString is where the walk starts, inclusive, or the first string of the prefix in Direction when empty.
EndStringstringEndString is the string the walk stops before, or no bound when empty.
DirectionScanDirectionDirection is which way the walk goes from its start.
PatternsPatternsPatterns keep the strings matching, compiled once.
PredicateAdmitterPredicate admits or passes over the keys of every page.
StringsLayoutStringsLayout is the layout a tape of strings exports as.
db.go:52 ↗
type StringsLayout int32

Values

StringsU32TapeStringsU32Tape is Arrow's binary layout, with 32-bit offsets.
StringsU64TapeStringsU64Tape is Arrow's large binary layout, with 64-bit offsets.
StringsMeasureConfigStringsMeasureConfig carries the optional arguments of DatabaseOn.StringsMeasure.
db.go:520 ↗
type StringsMeasureConfig struct {
    StartStrings Tape
    EndStrings Tape
    Direction ScanDirection
}

Fields

StartStringsTapeStartStrings are the inclusive starts of the ranges, one per task, or the first string in Direction when empty.
EndStringsTapeEndStrings are the strings every range stops before, one per task, or no bound when empty.
DirectionScanDirectionDirection is which way every range goes from its start.
StringsRemoveConfigStringsRemoveConfig carries the optional arguments of DatabaseOn.StringsRemove.
db.go:74 ↗
type StringsRemoveConfig struct {
    EndStrings Tape
    Durability Durability
}

Fields

EndStringsTapeEndStrings turns every string into the inclusive start of a range ending before its end string, one per task, or removes the strings alone when empty.
DurabilityDurabilityDurability is how durable the removals are once the call finishes at the head.
StringsScanConfigStringsScanConfig carries the optional arguments of DatabaseOn.StringsScan.
db.go:235 ↗
type StringsScanConfig struct {
    Prefixes Tape
    StartStrings Tape
    EndStrings Tape
    Direction ScanDirection
    Patterns Patterns
    Predicate Admitter
    Mode ScanMode
    Progress ProgressCallback
}

Fields

PrefixesTapePrefixes every scan matches, one per task, or every string when empty.
StartStringsTapeStartStrings are the inclusive starts of the scans, one per task, or the first string in Direction when empty.
EndStringsTapeEndStrings are the strings every scan stops before, one per task, or no bound when empty.
DirectionScanDirectionDirection is which way every scan goes from its start.
PatternsPatternsPatterns keep the strings matching, shared by every scan.
PredicateAdmitterPredicate admits or passes over the keys the listed strings map onto.
ModeScanModeMode is in what order the strings come.
ProgressProgressCallbackProgress reports the scans finished, and may cancel the call.
WriteConfigWriteConfig carries the optional arguments of a write that takes nothing else.
db.go:33 ↗
type WriteConfig struct {
    Durability Durability
}

Fields

DurabilityDurabilityDurability is how durable the writes are once the call finishes at the head.
TypeArrowDeviceArrayArrowDeviceArray is an ArrowArray beside the device its buffers live on, laid out as struct ArrowDeviceArray.2
arrow.go:36 ↗
type ArrowDeviceArray C.struct_ArrowDeviceArray
ArrayArray reports the column itself, which the converters read as they read a host array.
arrow.go:47 ↗
func (array *ArrowDeviceArray) Array() *ArrowArray
ReleaseRelease hands the array back to its producer, once; a released array is safe to release again.
arrow.go:42 ↗
func (array *ArrowDeviceArray) Release()
TypeArrowSchemaArrowSchema is the Arrow C data interface's schema of one column, laid out as struct ArrowSchema, so any Arrow library reads it through its address.1
arrow.go:29 ↗
type ArrowSchema C.struct_ArrowSchema
ReleaseRelease hands the schema back to its producer, once; a released schema is safe to release again.
arrow.go:39 ↗
func (schema *ArrowSchema) Release()
EnumDurabilityDurability is how durable a write at the head is once the call finishes; a transaction's commit decides its own.2
db.go:221 ↗
type Durability int32

Values

DurabilityBufferedDurabilityBuffered is visible on return and durable at the next flush.
DurabilityFlushedDurabilityFlushed is durable on return.
DurabilityFromNameDurabilityFromName reads a durability back from the spelling Durability.String renders.
db.go:236 ↗
func DurabilityFromName(name string) (Durability, error)
StringString renders the durability as the library spells it.
db.go:231 ↗
func (durability Durability) String() string
EnumIngestOrderIngestOrder is in what order an ingest's rows arrive.2
db.go:416 ↗
type IngestOrder int32

Values

IngestSortedIngestSorted takes keys strictly ascending across every append.
IngestUnsortedIngestUnsorted takes keys in any order, the last row of a key winning.
IngestOrderFromNameIngestOrderFromName reads an ingest order back from the spelling IngestOrder.String renders.
db.go:431 ↗
func IngestOrderFromName(name string) (IngestOrder, error)
StringString renders the order as the library spells it.
db.go:426 ↗
func (order IngestOrder) String() string
StructListingListing is what a batch of string scans or samples wrote into its arena, strings scan after scan, readable until the arena serves another call.4
strings.go:197 ↗
type Listing struct {
    // contains filtered or unexported fields
}
CountCount reports how many strings scan task found.
strings.go:209 ↗
func (listing Listing) Count(task uint) uint
GetGet views string index of scan task in the arena; index must be below Listing.Count.
strings.go:216 ↗
func (listing Listing) Get(task, index uint) []byte
LenLen reports how many scans or samples the call ran.
strings.go:206 ↗
func (listing Listing) Len() uint
ScoresScores views the BM25 score of every string scan task found, and nothing unless the patterns carried weights.
strings.go:224 ↗
func (listing Listing) Scores(task uint) []float32
StructMappedMapped is the key every string a read looked up maps onto, in the order of the strings, readable until the arena serves another call.2
strings.go:130 ↗
type Mapped struct {
    // contains filtered or unexported fields
}
GetGet reports the key string index maps onto, and false for a missing string.
strings.go:141 ↗
func (mapped Mapped) Get(index uint) (Key, bool)
LenLen reports how many strings the call looked up.
strings.go:138 ↗
func (mapped Mapped) Len() uint
StructStringsStrings is a ragged batch a call wrote into its arena as a tape, readable until the arena serves another call.3
types.go:565 ↗
type Strings struct {
    // contains filtered or unexported fields
}
GetGet views string index in the arena; index must be below Strings.Len.
types.go:585 ↗
func (strings Strings) Get(index uint) []byte
LenLen reports how many strings the call wrote.
types.go:571 ↗
func (strings Strings) Len() uint
TapeTape passes the strings back as an input, so a tape one call wrote is written again as it is, valid while the arena holds it.
types.go:605 ↗
func (strings Strings) Tape() Tape
StructStringsPageStringsPage is one pull of a strings walk, written into its arena and readable until the arena serves another call.3
strings.go:396 ↗
type StringsPage struct {
    // contains filtered or unexported fields
}
LenLen reports how many strings the pull handed out; fewer than wanted exhausts the walk for good.
strings.go:404 ↗
func (page StringsPage) Len() uint
StringsStrings views the strings of the page in the arena.
strings.go:407 ↗
func (page StringsPage) Strings() Strings
ValuesValues views the key every string maps onto, and is empty after a StringsCursor.NextStrings pull.
strings.go:415 ↗
func (page StringsPage) Values() []Key
StructTapeTape passes a ragged batch of byte strings as Apache Arrow lays one out: the bytes end to end, and one more offset than strings around them, string i spanning offsets[i] up to offsets[i+1].5
types.go:495 ↗
type Tape struct {
    // contains filtered or unexported fields
}

A Tape views and never owns, and the binding pins both slices until each call it crosses is final. The zero Tape is the empty batch, which a verb reads as its input's default.

StringsViewFromArrowStringsViewFromArrow views the byte strings of a binary, utf8, large binary or large utf8 column in place as a Tape, viewing the column's buffers.
types.go:82 ↗
func StringsViewFromArrow(
    schema *ArrowSchema,
    array *ArrowArray,
) (Tape, error)
TapeOfTapeOf packs strings end to end into a fresh Tape, one entry apiece, with 32-bit offsets while the bytes fit in 4 GiB and 64-bit beyond.
types.go:524 ↗
func TapeOf[Text ~string | ~[]byte](texts ...Text) Tape
U32TapeU32Tape views bytes end to end around len(offsets) - 1 strings, in Arrow's binary layout.
types.go:505 ↗
func U32Tape(data []byte, offsets []uint32) Tape

Panics when the offsets overrun the bytes, which names a caller's arithmetic mistake rather than a condition the library could report.

U64TapeU64Tape views bytes end to end around len(offsets) - 1 strings, in Arrow's large binary layout.
types.go:515 ↗
func U64Tape(data []byte, offsets []uint64) Tape

Panics when the offsets overrun the bytes.

LenLen reports how many strings the tape spans.
types.go:547 ↗
func (tape Tape) Len() uint
StructValuesValues is a batch of values a read wrote into its arena, in the order of its keys, readable until the arena serves another call.3
blobs.go:49 ↗
type Values struct {
    // contains filtered or unexported fields
}
GetGet views value index in the arena, and false for a missing key.
blobs.go:60 ↗
func (values Values) Get(index uint) ([]byte, bool)
LenLen reports how many values the call read.
blobs.go:57 ↗
func (values Values) Len() uint
TapeTape passes every value back as an input, a missing key as an empty value, so a read's tape is written again as it is.
blobs.go:71 ↗
func (read Values) Tape() Tape

Functions

KeysViewToArrowKeysViewToArrow exports keys a call wrote into arena as one fixed_size_binary(16) column tagged arrow.uuid, in place; until both outputs are released, the arena's next call and Close answer StatusContended, so release them after reading.
ustore.go:95 ↗
func KeysViewToArrow(
    keys []Key,
    arena *Arena,
    schema *ArrowSchema,
    array *ArrowDeviceArray,
) error
StringsViewToArrowStringsViewToArrow exports strings a call wrote into arena as one binary or large binary column, in place when the tape already has layout; until both outputs are released, the arena's next call and Close answer StatusContended.
ustore.go:107 ↗
func StringsViewToArrow(
    strings Strings,
    layout StringsLayout,
    arena *Arena,
    schema *ArrowSchema,
    array *ArrowDeviceArray,
) error