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
- func Bytes(b []byte) string
- func Date(t time.Time) string
- func Decimal(s string) any
- func Float(f float64) any
- func Float32(f float32) any
- func Rat(r *big.Rat, exact string) any
- func RatString(r *big.Rat) string
- func Size(v any) int
- func StringSize(s string) int
- func Timestamp(t time.Time) string
- func UniqueNames(names []string) []string
- type Budget
Constants ¶
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 Decimal ¶
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 ¶
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 ¶
Float32 renders a float32 using its shortest decimal representation (so float32(0.1) becomes 0.1, not 0.10000000149011612).
func Rat ¶
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 ¶
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 ¶
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 ¶
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 UniqueNames ¶
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.