tupleordering

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: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tupleordering is Java's TupleOrdering: tuples packed so that their byte order is a chosen direction and NULL placement, the encoding order functions store in index keys. The planner's ordered-bytes Values and the record layer's key evaluation share it.

Index

Constants

This section is empty.

Variables

View Source
var (
	AscNullsFirst  = Direction{Inverted: false, CounterflowNulls: false}
	AscNullsLast   = Direction{Inverted: false, CounterflowNulls: true}
	DescNullsFirst = Direction{Inverted: true, CounterflowNulls: true}
	DescNullsLast  = Direction{Inverted: true, CounterflowNulls: false}
)

The four directions of Java's TupleOrdering.Direction.

Functions

func ElementEndPos

func ElementEndPos(data []byte, pos int) (int, error)

ElementEndPos finds the end position (exclusive) of a single tuple element starting at data[pos]. Used by UnpackNullsLast to parse element boundaries.

func Invert

func Invert(input []byte) []byte

Invert applies byte-level inversion for DESC ordering. Each input byte is bit-flipped (XOR 0xFF), then the flipped bits are packed 7 bits per output byte (high bit always 0). A terminator byte with high bit set encodes the padding length.

This ensures that when comparing inverted byte sequences lexicographically:

  • Opposite ordering of original values (due to bit flip)
  • Shorter strings sort AFTER longer ones with the same prefix (due to 7-bit packing where terminators with high bit 1 sort after data bytes with high bit 0)

Matches Java's TupleOrdering.invert() exactly.

func Pack

func Pack(t tuple.Tuple, dir Direction) []byte

Pack encodes t in direction dir (TupleOrdering.pack). A tuple holding an incomplete versionstamp cannot be packed; the caller refuses it first.

func PackNullsLast

func PackNullsLast(t tuple.Tuple) []byte

PackNullsLast encodes a tuple element-by-element, replacing nil elements with a single 0xFE byte (which sorts after all standard tuple type codes). Matches Java's TupleOrdering.PackNullsLast().

func Uninvert

func Uninvert(inverted []byte) ([]byte, error)

Uninvert reverses Invert, recovering the original byte sequence. Matches Java's TupleOrdering.uninvert() exactly.

func Unpack

func Unpack(packed []byte, dir Direction) (tuple.Tuple, error)

Unpack decodes bytes packed in direction dir (TupleOrdering.unpack).

func UnpackNullsLast

func UnpackNullsLast(data []byte) (tuple.Tuple, error)

UnpackNullsLast decodes bytes that were encoded with PackNullsLast. 0xFE bytes are decoded as nil elements; other bytes use standard tuple decoding. Matches Java's TupleOrdering.UnpackNullsLast().

Types

type Direction

type Direction struct {
	// Inverted is DESC: the packed bytes are inverted.
	Inverted bool
	// CounterflowNulls places NULLs opposite to their natural position.
	CounterflowNulls bool
}

Direction is Java's TupleOrdering.Direction.

Jump to

Keyboard shortcuts

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