model

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 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 model defines the structures and interfaces for query options and results.

Index

Constants

View Source
const MaxIndexedPatternIdentityBytes = 255

MaxIndexedPatternIdentityBytes bounds each source tag and family name.

View Source
const MaxIndexedPatterns = native.MaxSQLPatterns

MaxIndexedPatterns bounds the number of pattern conjuncts in one source scan.

View Source
const SmallBatchRows = 256

SmallBatchRows is the row count below which a storage batch is copied into a larger owned batch instead of being passed along as it is: per-batch overhead (a RecordBatch, an owner set, one operator call) would otherwise dominate a batch of a few rows. Storage coalesces its small series windows to this threshold, and the scan source applies it to whatever storage hands over.

Variables

This section is empty.

Functions

func ResolveIndexedPatterns added in v0.12.0

func ResolveIndexedPatterns(measure *databasev1.Measure, rules []*databasev1.IndexRule, patterns []IndexedPattern) ([]native.TermSetRequest, error)

ResolveIndexedPatterns validates live schemas and bindings and requires an unambiguous whole-value index rule on coordinator and workers.

func ValidateIndexedPatterns added in v0.12.0

func ValidateIndexedPatterns(measure *databasev1.Measure, rules []*databasev1.IndexRule, patterns []IndexedPattern) error

ValidateIndexedPatterns checks current schema/index eligibility without opening storage.

Types

type Field

type Field struct {
	Name   string
	Values []*modelv1.FieldValue
}

Field is a field name and its values.

type FieldResolver added in v0.12.0

type FieldResolver interface {
	// Field returns the engine field (and, for MATCH, the analyzer) a
	// Criteria condition's tag name resolves to, or ok false when the tag is
	// not indexed for this caller.
	Field(tagName string) (field string, analyzer string, ok bool)
}

FieldResolver mirrors pkg/index/native/criteria.FieldResolver's single method without importing that package: pkg/index/native/criteria depends on pkg/query/logical, which this package's tag_filter_adapter.go already imports, so importing criteria here would cycle back. Any criteria.FieldResolver value satisfies this interface structurally (same method, same signature), so callers pass one through directly.

type IndexedPattern added in v0.12.0

type IndexedPattern struct {
	TagFamily  string
	TagName    string
	Pattern    string
	Escape     string
	IgnoreCase bool
}

IndexedPattern is a bound source-WHERE LIKE or ILIKE predicate. Escape is explicit: backslash is the language default and an empty string disables it.

func (IndexedPattern) Validate added in v0.12.0

func (p IndexedPattern) Validate() error

Validate checks the wire-independent pattern shape without opening storage.

type MeasureAgg added in v0.11.0

type MeasureAgg struct {
	FieldName string
	TagName   string
	TagFamily string
	Func      modelv1.AggregationFunction
	HideTag   bool
	// TargetIndexResolved is true when TagName resolves from the series
	// index (an entity tag or an IndexRule-indexed tag), so its value is
	// guaranteed constant and non-null across every row of one series
	// (design §7.7, stage 8a run-folding). Always false for a field target.
	TargetIndexResolved bool
}

MeasureAgg describes a single aggregation for a measure query. v1 supports one aggregation per query — matches the singular QueryRequest.agg proto field. Exactly one of FieldName / TagName is set: FieldName must reference a field in MeasureQueryOptions.FieldProjection; TagName + TagFamily reference a tag instead (design §5.1, §7.1). HideTag is set when the analyzer injected TagName into the tag projection because the caller didn't request it — the injected copy is then stripped from the output (design §5.2).

type MeasureBatch added in v0.11.0

type MeasureBatch struct {
	// Schema describes the column layout. Tags[i] / Fields[i] entries are
	// indexed via Schema.TagIndex / Schema.FieldIndex.
	Schema *vectorized.BatchSchema

	// Per-row metadata columns. Length equals the row count.
	Timestamps []int64
	Versions   []int64
	ShardIDs   []common.ShardID
	SeriesIDs  []common.SeriesID

	// Typed tag and field columns. Tags[i] corresponds to the i-th
	// RoleTag entry in Schema.Columns (in declaration order); same for
	// Fields. Each column reports the same Len() as len(Timestamps).
	Tags   []vectorized.Column
	Fields []vectorized.Column

	// SeriesBoundaries records exclusive end-of-series row indices for
	// multi-series batches. nil or empty when the batch contains a single
	// series.
	SeriesBoundaries []int

	// Selection, when non-nil, lists the row indices of the batch's columns in
	// the order the rows are to be emitted; rows not listed are not part of the
	// batch's result. nil means every row in storage order. A descending scan
	// emits one block as [n-1, ..., 0] over unreversed columns instead of copying
	// them backwards. RowCount still reports the column length: use ActiveRows for
	// the number of rows the consumer sees. Consumers must treat it as read-only.
	Selection []uint16

	// Owners pins the storage memory that string, bytes and string-array cells
	// in Tags borrow without copying. Release drops the references. A consumer
	// that keeps a borrowed cell past Release must copy it first or pin the same
	// owners (vectorized.Owners.PinAll) before releasing the batch.
	Owners vectorized.Owners

	// SeriesKnown is set by a producer that knows exactly which series each row
	// belongs to: SeriesBoundaries is then exact, and empty means the batch is a
	// single series. Without it SeriesBoundaries says nothing.
	SeriesKnown bool

	// TimeOrder is the direction of time within each series run (a whole batch, for
	// a single series), in the order the batch's rows are read: TimeOrderAsc,
	// TimeOrderDesc, or TimeOrderUnknown when the producer does not promise one.
	TimeOrder vectorized.TimeOrder
	// contains filtered or unexported fields
}

MeasureBatch is a single columnar batch flowing out of the storage layer.

Row count is the length of Timestamps. Versions, ShardIDs and SeriesIDs have the same length. Tags and Fields are parallel column slices whose indices correspond to Schema.Columns entries with RoleTag / RoleField respectively (the column at Tags[i] aligns with the i-th tag slot in Schema, in declaration order; same for Fields[i]).

SeriesBoundaries records the exclusive end-of-series row indices within the batch. For example, a batch holding 100 rows of series A followed by 200 rows of series B reports SeriesBoundaries = [100, 300]. Empty (nil or zero-length) means "single series" — every row in the batch belongs to the same series. A batch whose rows interleave series (a time-ordered merge) lists the end of every maximal run of one series, so a series can appear in several runs; SeriesIDs says which series a run is.

func AcquireBorrowingMeasureBatch added in v0.12.0

func AcquireBorrowingMeasureBatch(schema *vectorized.BatchSchema, capacity int) *MeasureBatch

AcquireBorrowingMeasureBatch is AcquireMeasureBatch for a batch whose Timestamps and Versions will be set with BorrowMetadata: it does not size those two slices, only ShardIDs, SeriesIDs and the columns.

func AcquireConstEntityMeasureBatch added in v0.12.0

func AcquireConstEntityMeasureBatch(schema *vectorized.BatchSchema, capacity int) *MeasureBatch

AcquireConstEntityMeasureBatch is AcquireBorrowingMeasureBatch for a batch whose entity tag columns are about to be replaced by constants (see ConstFrom): their placeholder columns are acquired empty instead of sized to capacity rows, so a pool miss does not allocate a column's worth of memory that is released unused.

func AcquireMeasureBatch added in v0.11.0

func AcquireMeasureBatch(schema *vectorized.BatchSchema, capacity int) *MeasureBatch

AcquireMeasureBatch returns a recycled *MeasureBatch wired to schema with Tag / Field column slots pre-acquired from the per-type column pool. The parallel metadata slices are truncated to length 0 and grown to capacity if needed; oversized cached column and metadata buffers are dropped before attachment; normal batch-size reuse is preserved. Callers must call Release exactly once when done with the batch.

func (*MeasureBatch) ActiveRows added in v0.12.0

func (b *MeasureBatch) ActiveRows() int

ActiveRows returns the number of rows a consumer sees: len(Selection) when a selection is set, RowCount otherwise.

func (*MeasureBatch) BorrowMetadata added in v0.12.0

func (b *MeasureBatch) BorrowMetadata(timestamps, versions []int64)

BorrowMetadata makes Timestamps and Versions zero-copy views of timestamps and versions, which must have equal length and stay valid and unmodified until Release; the caller pins whatever owns them. The slices are capacity-limited, so an append reallocates instead of writing into the owner's memory. Release drops the views and keeps the batch's own pooled buffers.

func (*MeasureBatch) ConstFrom added in v0.12.0

func (b *MeasureBatch) ConstFrom(src vectorized.Column, row, n int) (*vectorized.ConstColumn, bool)

ConstFrom returns a constant column of n rows holding the value of row of src (see vectorized.AcquireConstFrom), in storage the batch owns when it has room. The caller puts it in Tags, which Release gives back; it reports false, having built nothing, when src cannot be constant.

func (*MeasureBatch) MetadataBorrowed added in v0.12.0

func (b *MeasureBatch) MetadataBorrowed() bool

MetadataBorrowed reports whether Timestamps and Versions are borrowed views.

func (*MeasureBatch) Release added in v0.11.0

func (b *MeasureBatch) Release()

Release returns the batch's Tag / Field columns to the per-type pool and the batch itself to the MeasureBatch pool, and drops its owner references, after which no borrowed cell may be read. Parallel metadata slices keep their backing arrays (truncated to length 0) so the next Acquire can reuse them. Calling Release on a nil receiver is a no-op; calling Release twice on the same batch is a use-after-free and not supported.

func (*MeasureBatch) RowCount added in v0.11.0

func (b *MeasureBatch) RowCount() int

RowCount returns the number of rows in the batch. It reads len(Timestamps); callers must keep the parallel column lengths in sync.

type MeasureBatchResult added in v0.11.0

type MeasureBatchResult interface {
	// PullBatch returns the next batch from the underlying scan. It returns
	// (nil, nil) on EOF; (nil, err) on storage error. Once an error is
	// returned, subsequent calls must continue to return that same error
	// (sticky-error contract — matches MeasureQueryResult.Pull's
	// MeasureResult.Error semantics).
	PullBatch(ctx context.Context) (*MeasureBatch, error)

	// Release frees any resources held by the result. Idempotent.
	Release()
}

MeasureBatchResult is the columnar counterpart to MeasureQueryResult. Implementations return a *MeasureBatch carrying parallel typed slices instead of the row-shaped *modelv1.TagValue / *modelv1.FieldValue cells.

The contract is independent of MeasureQueryResult: a single underlying query may satisfy both interfaces (dual-emit) or only one. Callers that want the columnar path call PullBatch; callers that still want the row path call MeasureQueryResult.Pull. Release is shared semantics — the caller invokes it exactly once after iteration is complete; calling Release twice (e.g. once via each interface) is safe but unnecessary.

type MeasureGroupBy added in v0.11.0

type MeasureGroupBy struct {
	TimeBucket *MeasureTimeBucket
	TagFamily  string
	TagNames   []string
	// AllTagsIndexResolved is true when every tag in TagNames resolves from
	// the series index — an entity tag or a tag carrying an IndexRule —
	// rather than the part's tag columns, computed once at analyze time
	// from static schema facts (design §7.7, stage 8a run-folding). Left
	// false (the zero value) when TagNames is empty; consumers treat an
	// empty key list as vacuously safe on their own, so this field is only
	// consulted when TagNames is non-empty.
	AllTagsIndexResolved bool
}

MeasureGroupBy describes a GroupBy clause for a measure query. v1 supports a single tag family; each entry in TagNames is a key column. An empty TagNames slice means the query carries no tag GroupBy clause — the query may still bucket by time alone (TimeBucket set, TagNames empty).

TimeBucket carries the request's resolved time_bucket clause (design §5.3); a nil TimeBucket means no bucketing.

type MeasureQueryOptions

type MeasureQueryOptions struct {
	// PatternRequests intersect whole-value indexed patterns before row reads.
	PatternRequests []native.TermSetRequest
	// Criteria is the filter the series index evaluates after series
	// matchers/IndexModeSubject narrow the universe (NIDX-03 §5/§6.2); it
	// never builds an engine query itself. A nil Criteria matches every
	// candidate the universe already selected.
	Criteria *modelv1.Criteria
	// Fields resolves a Criteria condition's tag name to its engine field.
	// Required whenever Criteria is non-nil.
	Fields          FieldResolver
	TimeRange       *timestamp.TimeRange
	Order           *index.OrderBy
	GroupBy         *MeasureGroupBy
	Agg             *MeasureAgg
	Name            string
	Entities        [][]*modelv1.TagValue
	TagProjection   []TagProjection
	FieldProjection []string
	Sort            modelv1.Sort
	// Limit, when positive, is how many rows the query can use from the scan: its offset plus limit. A normal-mode scan
	// reads it only for an order by an index rule, as a count of data points.
	// The plan sets it only when nothing between the scan and the limit can drop or reorder rows.
	Limit         int
	Number        int32
	TopNFieldType databasev1.FieldType
}

MeasureQueryOptions is the options of a measure query.

type MeasureQueryResult

type MeasureQueryResult interface {
	Pull() *MeasureResult
	Release()
}

MeasureQueryResult is the result of a measure query.

type MeasureResult

type MeasureResult struct {
	Error       error
	Timestamps  []int64
	Versions    []int64
	ShardIDs    []common.ShardID
	TagFamilies []TagFamily
	Fields      []Field
	SID         common.SeriesID
}

MeasureResult is the result of a query.

type MeasureTimeBucket added in v0.12.0

type MeasureTimeBucket struct {
	Width           string
	WidthNanos      int64
	UseIndexModeMap bool
}

MeasureTimeBucket describes a resolved GroupBy.time_bucket clause (design §5.3). Width is the raw requested/resolved duration string, kept for diagnostics; WidthNanos is its parsed value in nanoseconds and is what execution actually uses — always > 0 once translateGroupBy has resolved it (a zero or negative width is rejected at analyze time, never carried this far). UseIndexModeMap is set when measureSchema.GetIndexMode() is true: an index-mode measure's scan has no ascending-timestamp guarantee, so execution must take the non-streaming map path (design §7.2) instead of the streaming operator, decided once here rather than guessed at runtime.

type StreamQueryOptions

type StreamQueryOptions struct {
	Name           string
	TimeRange      *timestamp.TimeRange
	Entities       [][]*modelv1.TagValue
	InvertedFilter index.Filter
	SkippingFilter index.Filter
	Order          *index.OrderBy
	TagProjection  []TagProjection
	MaxElementSize int
}

StreamQueryOptions is the options of a stream query.

func (*StreamQueryOptions) CopyFrom added in v0.8.0

func (s *StreamQueryOptions) CopyFrom(other *StreamQueryOptions)

CopyFrom copies the StreamQueryOptions from other to s.

func (*StreamQueryOptions) Reset added in v0.8.0

func (s *StreamQueryOptions) Reset()

Reset resets the StreamQueryOptions.

type Tag

type Tag struct {
	Name   string
	Values []*modelv1.TagValue
}

Tag is a tag name and its values.

type TagFamily

type TagFamily struct {
	Name string
	Tags []Tag
}

TagFamily is a tag family name and its tags.

type TagFilterMatcher added in v0.9.0

type TagFilterMatcher interface {
	// Match returns true if the given tags match the filter criteria.
	// tags is a slice of tags for a single element/row.
	Match(tags []*modelv1.Tag) (bool, error)
	// GetDecoder returns the decoder function for tag values.
	GetDecoder() TagValueDecoder
}

TagFilterMatcher is a simple interface for matching tags without schema dependency. This avoids cycle imports between logical and sidx packages.

type TagProjection

type TagProjection struct {
	Family string
	Names  []string
}

TagProjection is the projection of a tag family and its tags.

type TagValueDecoder added in v0.9.0

type TagValueDecoder func(valueType pbv1.ValueType, value []byte, valueArr [][]byte) *modelv1.TagValue

TagValueDecoder decodes a byte slice to a TagValue based on the value type.

type TagValueDecoderProvider added in v0.9.0

type TagValueDecoderProvider interface {
	GetTagValueDecoder() TagValueDecoder
}

TagValueDecoderProvider provides a decoder for tag values.

type TraceQueryOptions added in v0.9.0

type TraceQueryOptions struct {
	SkippingFilter index.Filter
	TagFilter      TagFilterMatcher
	TimeRange      *timestamp.TimeRange
	Order          *index.OrderBy
	TagProjection  *TagProjection
	Name           string
	Entities       [][]*modelv1.TagValue
	TraceIDs       []string
	MaxTraceSize   int
	MinVal         int64
	MaxVal         int64
}

TraceQueryOptions is the options of a trace query.

func (*TraceQueryOptions) CopyFrom added in v0.9.0

func (t *TraceQueryOptions) CopyFrom(other *TraceQueryOptions)

CopyFrom copies the TraceQueryOptions from other to t.

func (*TraceQueryOptions) Reset added in v0.9.0

func (t *TraceQueryOptions) Reset()

Reset resets the TraceQueryOptions.

type TraceQueryResult added in v0.9.0

type TraceQueryResult interface {
	Pull() *TraceResult
	Release()
}

TraceQueryResult is the result of a trace query.

type TraceResult added in v0.9.0

type TraceResult struct {
	Error      error
	TID        string
	Spans      [][]byte
	SpanIDs    []string
	Tags       []Tag
	Key        int64
	GroupIndex int
}

TraceResult is the result of a query.

Jump to

Keyboard shortcuts

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