jqresult

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(filter string) (*gojq.Code, error)

Compile parses filter and returns executable jq code.

func DefaultFilter

func DefaultFilter(InputMode) string

DefaultFilter returns the filter used when the user passes an empty --filter.

func Execute

func Execute(code *gojq.Code, mode InputMode, rowIter *spanner.RowIterator, rs *sppb.ResultSet, redactRows bool, opts ...LazyOption) (gojq.Iter, func(), error)

Execute runs jq. For eager mode, rs must be set and rowIter is ignored. For lazy mode, rowIter must be unread; cleanup releases the iterator state. Lazy mode is intended for read-only queries; read-write callers should materialize first and use eager mode. opts apply only to lazy mode (for example WithOmitQueryPlan).

func MetadataMapFromMetadata

func MetadataMapFromMetadata(metadata *sppb.ResultSetMetadata) (map[string]any, error)

MetadataMapFromMetadata returns the metadata object for jq input.

func NormalizeForEncode

func NormalizeForEncode(v any) (any, error)

NormalizeForEncode walks v and expands gojq.Iter and gojq.JQValue so encoding/json or yaml can encode the result. jq-compatible containers ([]any, map[string]any) are recursed; other concrete values are left as leaves.

func Print

func Print(enc Encoder, iter gojq.Iter) error

Print writes all values from a jq iterator. Top-level gojq.Iter values are expanded to one Encode per element (JSONL-friendly). Other values are normalized (including nested Iter) then encoded once.

func ProtoToMap

func ProtoToMap(m proto.Message) (map[string]any, error)

ProtoToMap marshals a protobuf message with protojson and decodes to map[string]any.

func ResultSetMap

func ResultSetMap(rs *sppb.ResultSet) (map[string]any, error)

ResultSetMap materializes a full ResultSet as a jq input map (eager mode).

func RowToJSON

func RowToJSON(r *spanner.Row) (any, error)

RowToJSON encodes one row the same way as protojson on a single-row ResultSet (array-shaped row).

func StatsMapFromResult

func StatsMapFromResult(result spaniter.RowIteratorResult) (map[string]any, error)

StatsMapFromResult returns the stats object for jq input from captured iterator state.

Types

type Encoder

type Encoder interface {
	Encode(v any) error
}

Encoder writes one jq emission (JSON or YAML document).

type InputMode

type InputMode string

InputMode selects how Spanner query results are passed to gojq.

const (
	InputEager InputMode = "eager"
	InputLazy  InputMode = "lazy"
)

func ParseInputMode

func ParseInputMode(s string) (InputMode, error)

func (InputMode) ValidateFormat

func (m InputMode) ValidateFormat(format string) error

ValidateFormat returns an error when mode is incompatible with the output format.

type Lazy

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

Lazy is a JQValue root for a Spanner query result. Accessing stats drains rows; rows streams via gojq.Iter.

func NewLazy

func NewLazy(rowIter *spanner.RowIterator, redact bool, opts ...LazyOption) *Lazy

NewLazy builds a lazy jq input. rowIter must not have been read yet; Lazy takes ownership and Stop()s it.

func (*Lazy) Drain

func (l *Lazy) Drain() error

Drain consumes any remaining rows so final stats are available. If .stats was already read, this is a no-op. Newly consumed rows are discarded and not retained on Lazy.

func (*Lazy) JQValueEach

func (l *Lazy) JQValueEach() any

func (*Lazy) JQValueHas

func (l *Lazy) JQValueHas(key any) any

func (*Lazy) JQValueIndex

func (l *Lazy) JQValueIndex(int) any

func (*Lazy) JQValueKey

func (l *Lazy) JQValueKey(name string) any

func (*Lazy) JQValueKeys

func (l *Lazy) JQValueKeys() any

func (*Lazy) JQValueLength

func (l *Lazy) JQValueLength() any

func (*Lazy) JQValueSlice

func (l *Lazy) JQValueSlice(int, int) any

func (*Lazy) JQValueSliceLen

func (l *Lazy) JQValueSliceLen() any

func (*Lazy) JQValueToGoJQ

func (l *Lazy) JQValueToGoJQ() any

func (*Lazy) JQValueToNumber

func (l *Lazy) JQValueToNumber() any

func (*Lazy) JQValueToString

func (l *Lazy) JQValueToString() any

func (*Lazy) JQValueType

func (l *Lazy) JQValueType() string

func (*Lazy) Result

func (l *Lazy) Result() spaniter.RowIteratorResult

Result returns iterator metadata and stats captured while rows were consumed. Call Drain first when jq may have stopped before the last PartialResultSet.

func (*Lazy) Stop

func (l *Lazy) Stop()

Stop releases the row iterator without draining unconsumed rows.

type LazyOption

type LazyOption func(*Lazy)

LazyOption configures NewLazy.

func WithOmitQueryPlan

func WithOmitQueryPlan() LazyOption

WithOmitQueryPlan omits queryPlan from the .stats object presented to jq. The underlying iterator stats still include the plan for Drain/Result.

type RowIter

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

RowIter streams query rows as jq-compatible values ([]any per row, matching protojson ResultSet rows).

func NewRowIter

func NewRowIter(rowIter *spanner.RowIterator, redact bool, rowToJSON func(*spanner.Row) (any, error)) *RowIter

func (*RowIter) Result

func (r *RowIter) Result() spaniter.RowIteratorResult

Result returns lifecycle data captured by spaniter while rows are consumed.

func (*RowIter) Stop

func (r *RowIter) Stop()

Jump to

Keyboard shortcuts

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