Documentation
¶
Overview ¶
Package tabular writes gobspect.Value nodes as CSV or TSV rows.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CellString ¶
CellString converts a single Value to a flat string suitable for a CSV cell. BytesValue is rendered as lowercase hex. Complex nested types are squashed to descriptive placeholders. Use Printer.WriteValue for format-aware rendering of bytes (respecting the configured [BytesFormat] and max-bytes limit).
Types ¶
type HeterogeneousMode ¶
type HeterogeneousMode int
HeterogeneousMode controls what the Printer does when a row with a different struct type arrives after the first row has locked the schema.
const ( // HeterogeneousFirstWins silently drops rows whose type differs from the // first row's type. HeterogeneousFirstWins HeterogeneousMode = iota // HeterogeneousReject returns an error when a row with a different type // arrives after the schema has been locked. HeterogeneousReject // HeterogeneousUnion grows the header when new columns appear. Rows already // printed cannot be backfilled; they receive empty cells for new columns. HeterogeneousUnion // HeterogeneousPartition emits a blank line followed by a new header row // whenever the struct type changes, then continues with the new type's schema. HeterogeneousPartition )
func ParseHeterogeneousMode ¶
func ParseHeterogeneousMode(s string) (HeterogeneousMode, bool)
ParseHeterogeneousMode converts a string to a HeterogeneousMode constant. Accepts "first", "reject", "union", or "partition" (case-insensitive). An empty string maps to HeterogeneousFirstWins. Returns (HeterogeneousFirstWins, false) for unrecognised values.
type Option ¶
type Option func(*Printer)
Option is a functional option for NewPrinter.
func WithBytesFormat ¶
func WithBytesFormat(f gobspect.BytesFormat) Option
WithBytesFormat sets the rendering format for BytesValue cells.
func WithDelimiter ¶
WithDelimiter sets the CSV/TSV column delimiter.
func WithHeterogeneousMode ¶
func WithHeterogeneousMode(m HeterogeneousMode) Option
WithHeterogeneousMode sets the heterogeneous-type handling mode.
func WithMaxBytes ¶
WithMaxBytes sets the byte-slice truncation limit (0 = no limit).
func WithNoHeaders ¶
WithNoHeaders suppresses the header row when b is true.
func WithStream ¶
WithStream sets the gobspect.Stream used for canonical type-definition lookups. When nil, column order falls back to the struct's own Fields slice.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer writes gobspect.Value nodes as CSV or TSV rows.
Column order is determined by the canonical type definition for the first struct received, looked up via stream.TypeByID. For projection structs (TypeName == query.ProjectionTypeName), the struct's own fields define the column order, and heterogeneous source types are accepted without error.
When structs of a locked type arrive with fewer fields than the header (gob sparse encoding omits zero-value fields), the missing columns are emitted as empty strings so every row has the same column count as the header.
The behavior when structs of a different type arrive is controlled by HeterogeneousMode.
func NewPrinter ¶
NewPrinter creates a Printer that writes to out. Defaults: comma delimiter, headers on, HeterogeneousFirstWins, BytesHex, no truncation.