conv

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package conv holds JSON-friendly value conversions shared by the warehouse sources (sqlsource, bigquery, athena), so every engine renders numbers, decimals, bytes and timestamps the same way (SPEC §5.5).

Index

Constants

View Source
const ValueOverhead = 16

ValueOverhead is the fixed cost Size adds for every value (including each row, array and object): roughly what holding a converted value in an interface, slice or map costs in memory beyond its JSON text.

Variables

This section is empty.

Functions

func Bytes

func Bytes(b []byte) string

Bytes renders binary data as standard base64.

func Date

func Date(t time.Time) string

Date renders the calendar date of t as YYYY-MM-DD (t's own location).

func Decimal

func Decimal(s string) any

Decimal parses a decimal string (as returned by an engine for DECIMAL / NUMERIC columns) and renders it with Rat. Unparseable input (e.g. "NaN") is returned unchanged.

func Float

func Float(f float64) any

Float renders a float64 for JSON: finite values stay numbers; NaN and ±Inf (which encoding/json rejects) become the strings "NaN", "Infinity" and "-Infinity".

func Float32

func Float32(f float32) any

Float32 renders a float32 using its shortest decimal representation (so float32(0.1) becomes 0.1, not 0.10000000149011612).

func Rat

func Rat(r *big.Rat, exact string) any

Rat renders an exact decimal value: a float64 when the float's shortest decimal representation equals r exactly (no precision is lost), otherwise the exact decimal string. exact is the engine's textual rendering of r; when empty, r.FloatString with a scale large enough for r is used.

func RatString

func RatString(r *big.Rat) string

RatString renders r as a plain decimal string without exponent and without superfluous trailing zeros. Non-terminating fractions are cut at 38 digits.

func Size

func Size(v any) int

Size estimates the bytes a converted value occupies: the length of its encoding/json encoding plus ValueOverhead per value. It is exact for the values the converters produce (nil, bool, string, int64, float64, []any, map[string]any); anything else is measured by encoding it.

func StringSize

func StringSize(s string) int

StringSize returns the length of s encoded as a JSON string by encoding/json (quotes, escapes, HTML-safe escaping of <, > and &, and an escaped replacement character for each invalid UTF-8 byte).

func Timestamp

func Timestamp(t time.Time) string

Timestamp renders an instant as RFC 3339 with nanoseconds, in UTC.

func UniqueNames

func UniqueNames(names []string) []string

UniqueNames returns names with duplicates (and empty names) disambiguated so they can be used as keys of a row map: the first occurrence keeps its name, later ones get a "_2", "_3", … suffix (skipping suffixes already taken). Empty names become "column_<n>" (1-based position).

Types

type Budget

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

Budget tracks the estimated size (see Size) of the rows added to a result against a cap.

func NewBudget

func NewBudget(limit int) *Budget

NewBudget returns a Budget of limit bytes.

func (*Budget) Add

func (b *Budget) Add(row map[string]any) bool

Add reports whether row fits in what is left of the budget and, if it does, counts it (plus the comma separating rows).

func (*Budget) Remaining

func (b *Budget) Remaining() int

Remaining returns the bytes left.

func (*Budget) Used

func (b *Budget) Used() int

Used returns the bytes counted so far.

Jump to

Keyboard shortcuts

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