Documentation
¶
Overview ¶
Package plan is the vectorized measure-query plan tree (G8).
Top-level dispatch (banyand/query/processor.go, G8d) routes every measure query here.
A VecPlan node knows its output BatchSchema, its children, and how to append itself to a *vectorized.PipelineBuilder during Build. Build is bottom-up: a node calls Build on its child first, then attaches its own operator. The root's Build returns a fully-composed PipelineBuilder that the executor (G8c) finalizes via builder.Build() to produce a *vectorized.Pipeline.
Index ¶
- func BuildMultiGroupBatchSchema(measureSchemas []*databasev1.Measure, req *measurev1.QueryRequest) (*vectorized.BatchSchema, error)
- func Dispatch(ctx context.Context, req *measurev1.QueryRequest, metadata *commonv1.Metadata, ...) (iter executor.MIterator, planStr string, err error)
- func Execute(ctx context.Context, plan VecPlan, cfg measure.VectorizedConfig) (executor.MIterator, error)
- func HandledCount() int64
- func PrintTree(root VecPlan) string
- func SupportsDistributedRows(req *measurev1.QueryRequest) bool
- func ValidateMultiGroupProjection(req *measurev1.QueryRequest, schemas []logical.Schema, ...) error
- type BatchResult
- func DispatchBatches(ctx context.Context, req *measurev1.QueryRequest, metadata *commonv1.Metadata, ...) (resultBatch *BatchResult, planStr string, err error)
- func DispatchSeriesBatches(ctx context.Context, req *measurev1.QueryRequest, metadata *commonv1.Metadata, ...) (*BatchResult, string, error)
- func ExecuteBatches(ctx context.Context, plan VecPlan, cfg measure.VectorizedConfig) (*BatchResult, error)
- func MergeStandaloneBatches(ctx context.Context, groups []*BatchResult, schema *vectorized.BatchSchema, ...) (*BatchResult, error)
- func NewBatchResult(ctx context.Context, source vectorized.PullOperator, ...) (*BatchResult, error)
- func (r *BatchResult) Close() error
- func (r *BatchResult) Init(ctx context.Context) error
- func (r *BatchResult) NativeIterator(ctx context.Context) (executor.MIterator, error)
- func (r *BatchResult) NativeIteratorFrom(ctx context.Context, source vectorized.PullOperator) (executor.MIterator, error)
- func (r *BatchResult) NextBatch(ctx context.Context) (*vectorized.RecordBatch, error)
- func (r *BatchResult) OutputSchema() *vectorized.BatchSchema
- func (r *BatchResult) QueryTrace() *commonv1.Trace
- func (r *BatchResult) SetTraceFinalizer(finalizer func() *commonv1.Trace)
- func (r *BatchResult) TraceIterator(ctx context.Context)
- type BuildContext
- type DistributedPlan
- type GroupBatches
- type GroupByAgg
- type Limit
- type MultiGroupMerge
- func (m *MultiGroupMerge) Collect(ctx context.Context, result *BatchResult, planStr string) (*GroupBatches, error)
- func (m *MultiGroupMerge) GroupRequest() *measurev1.QueryRequest
- func (m *MultiGroupMerge) GroupRequestFor(group string) *measurev1.QueryRequest
- func (m *MultiGroupMerge) Merge(ctx context.Context, groups []*GroupBatches) (executor.MIterator, error)
- func (m *MultiGroupMerge) MergeBatches(ctx context.Context, groups []*GroupBatches) (*BatchResult, error)
- func (m *MultiGroupMerge) ReducesAggregates() bool
- func (m *MultiGroupMerge) Tracker() *vectorized.MemoryTracker
- type MultiGroupOption
- type Scan
- type ScanParams
- type Top
- type VecPlan
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildMultiGroupBatchSchema ¶
func BuildMultiGroupBatchSchema(measureSchemas []*databasev1.Measure, req *measurev1.QueryRequest) (*vectorized.BatchSchema, error)
BuildMultiGroupBatchSchema unions the per-group BatchSchemas produced by BuildBatchSchema and returns a single merged schema whose column order is:
metadata (timestamp, version, sid, shardID), then tags in (TagFamilyIdx, TagIdx) walk order across all groups with duplicates skipped, then fields ordered by request projection (or schema-walk order when no projection is given).
Tag type-divergence (same name, different type across groups) falls back to ColumnTypeTagValue so the frame proto-bytes passthrough carries each cell without forced type conversion. Field type-divergence falls back to ColumnTypeFieldValue, mirroring the row path's FIELD_TYPE_UNSPECIFIED fallback (schema.go:165-176).
When len(measureSchemas) == 1 the result is identical to BuildBatchSchema applied to that single schema (single-group hot path is unchanged).
func Dispatch ¶
func Dispatch( ctx context.Context, req *measurev1.QueryRequest, metadata *commonv1.Metadata, measureSchema *databasev1.Measure, logicalSchema logical.Schema, ec executor.MeasureExecutionContext, cfg measure.VectorizedConfig, emitPartial bool, skipProjectionValidation bool, ) (iter executor.MIterator, planStr string, err error)
Dispatch is the G8d top-level entry into the vec measure subsystem.
Called from banyand/query/processor.go before the row-path Analyze runs. When the request is eligible for the vec subsystem, Dispatch:
- Analyzes the request into a VecPlan via plan.Analyze (G8b)
- Resolves the remaining criteria + entity table the storage layer needs: extractSeriesMatchers (non-index-mode) or the raw request criteria (index mode) plus a measureFieldResolver, which the series index evaluates via pkg/index/native/criteria.Filter -- no legacy-engine query is built (NIDX-03 §5)
- Calls ec.Query(ctx, opts) to obtain the MeasureQueryResult
- Wraps the result as a vec PullOperator (BatchSourceFromBatchResult fast path when available; BatchScan fallback otherwise) and installs it on the leaf Scan node
- Executes the plan via plan.Execute (G8c) to return an MIterator
Dispatch is contract-bound to either return an iterator or surface a hard error — there is no fall-through.
Eligibility gate (v1):
- request may carry GroupBy and/or Agg in any combination (group+agg, scalar reduce, raw GroupBy); plan.Analyze auto-extends the projection so the keys / agg field always resolve
- request may carry Top: the analyzer emits Scan → Top → Limit (or Scan → GroupByAgg → Top → Limit) and BatchTop reproduces the row path's top-N (G9a)
- a nil request.TimeRange is accepted: Dispatch normalises it to an epoch→epoch window for row-path parity (G9c), so callers do not need to pre-populate one
- hidden criteria tags (criteria tags absent from the projection) are projected for storage-side filtering, then stripped at egress by hiddenTagsMIterator so the wire format is byte-identical
- measureSchema and logicalSchema must be non-nil
func Execute ¶
func Execute(ctx context.Context, plan VecPlan, cfg measure.VectorizedConfig) (executor.MIterator, error)
Execute composes a vec plan tree into a runnable *vectorized.Pipeline and returns it as an executor.MIterator. The Scan node(s) in the plan must have Source already set — the executor (G8c) does not resolve storage on its own; G8d's top-level dispatch is responsible for building the scan source from a MeasureExecutionContext and stitching it in.
Lifecycle: a per-pipeline MemoryTracker is constructed from cfg.QueryMemoryMiB and threaded through the BuildContext so every memory-bookkeeping operator (BatchAggregation, future BatchGroupBy) charges against a single budget (G7a). Pipeline.Init is invoked before the iterator is returned so breaker stages (which lazily allocate their state on Init) are ready for the first Next.
On any error during Build, builder.Build, or Pipeline.Init, the function returns the error and closes any partially-constructed pipeline so source resources (BatchPool, underlying MeasureBatchResult) are released.
func HandledCount ¶
func HandledCount() int64
HandledCount returns the cumulative number of vec dispatch successes observed by this process.
func PrintTree ¶
PrintTree renders a plan tree as multi-line text. Leaves first column, each parent indented two spaces deeper than its child. Useful for debugging analyzer output.
func SupportsDistributedRows ¶
func SupportsDistributedRows(req *measurev1.QueryRequest) bool
SupportsDistributedRows reports whether a non-aggregation request can use the native vectorized distributed row merge. Phase 2 lifts the OrderBy.IndexRuleName != "" gate; Phase 4 lifts the Top-without-Agg gate; Phase 5 lifts the GroupBy-without-Agg gate (raw GroupBy: first-seen row per group) and the multi-group + Top carve-out (per-group Limit is now calibrated rather than MaxUint32, so amplification is bounded).
Rejected: Agg != nil — aggregation requests always go through executeAgg.
func ValidateMultiGroupProjection ¶
func ValidateMultiGroupProjection(req *measurev1.QueryRequest, schemas []logical.Schema, measures []*databasev1.Measure) error
ValidateMultiGroupProjection is the multi-measure counterpart of the single-group validation Dispatch runs inline. A projected tag/field is accepted if it resolves in ANY group's schema/measure — mirroring the row path's measure_analyzer.Analyze, which calls mergeSchema(ss) to union the per-group schemas before validating the projection. Without this, a multi-measure query that projects a tag/field added to one group but not another (the classic schema-evolution case the `multi_group_new_tag_field` integration test pins) would be rejected per-group inside Dispatch even though the row path accepts it. Returns the same byte-identical error message ("<tag>: tag is not defined" / "field <name> not found in schema") as the single-group path so test fixtures and operator-facing errors match across the two routes.
Types ¶
type BatchResult ¶ added in v0.12.0
BatchResult owns eager native output, its schema and retained buffers. NextBatch lends descriptors until the next pull or Close. Consumers retaining views must retain owners and copy descriptors before another adapter can recycle them. Close is idempotent. Native execution remains eager: this handle does not imply streaming fanout.
func DispatchBatches ¶ added in v0.12.0
func DispatchBatches(ctx context.Context, req *measurev1.QueryRequest, metadata *commonv1.Metadata, measureSchema *databasev1.Measure, logicalSchema logical.Schema, ec executor.MeasureExecutionContext, cfg measure.VectorizedConfig, emitPartial, skipProjectionValidation bool, patterns ...native.TermSetRequest, ) (resultBatch *BatchResult, planStr string, err error)
DispatchBatches executes the native scan and reduction path without materializing DataPoints.
func DispatchSeriesBatches ¶ added in v0.12.0
func DispatchSeriesBatches(ctx context.Context, req *measurev1.QueryRequest, metadata *commonv1.Metadata, measureSchema *databasev1.Measure, logicalSchema logical.Schema, ec executor.MeasureExecutionContext, cfg measure.VectorizedConfig, emitPartial, skipProjectionValidation bool, patterns ...native.TermSetRequest, ) (*BatchResult, string, error)
DispatchSeriesBatches executes a complete raw input for a QL plan that permits series ordering.
func ExecuteBatches ¶ added in v0.12.0
func ExecuteBatches(ctx context.Context, plan VecPlan, cfg measure.VectorizedConfig) (*BatchResult, error)
ExecuteBatches initializes a native plan and transfers its batch ownership to the caller.
func MergeStandaloneBatches ¶ added in v0.12.0
func MergeStandaloneBatches(ctx context.Context, groups []*BatchResult, schema *vectorized.BatchSchema, req *measurev1.QueryRequest, schemas []logical.Schema, cfg vmeasure.VectorizedConfig, ) (*BatchResult, error)
MergeStandaloneBatches transfers ownership of group results to a native batch merger.
func NewBatchResult ¶ added in v0.12.0
func NewBatchResult(ctx context.Context, source vectorized.PullOperator, schema *vectorized.BatchSchema, batchSize int) (*BatchResult, error)
NewBatchResult wraps an initialized local batch source and takes its Close ownership. The source retains responsibility for accounting buffers until disposal.
func (*BatchResult) Close ¶ added in v0.12.0
func (r *BatchResult) Close() error
Close releases all retained output owners and live memory reservations.
func (*BatchResult) Init ¶ added in v0.12.0
func (r *BatchResult) Init(ctx context.Context) error
Init implements PullOperator; execution has already initialized the result.
func (*BatchResult) NativeIterator ¶ added in v0.12.0
NativeIterator applies native pagination and hidden projection semantics. The iterator takes ownership of r and closes it on Close.
func (*BatchResult) NativeIteratorFrom ¶ added in v0.12.0
func (r *BatchResult) NativeIteratorFrom(ctx context.Context, source vectorized.PullOperator) (executor.MIterator, error)
NativeIteratorFrom serializes a batch consumer wrapping r, transferring Close ownership.
func (*BatchResult) NextBatch ¶ added in v0.12.0
func (r *BatchResult) NextBatch(ctx context.Context) (*vectorized.RecordBatch, error)
NextBatch lends the next native batch without protobuf serialization.
func (*BatchResult) OutputSchema ¶ added in v0.12.0
func (r *BatchResult) OutputSchema() *vectorized.BatchSchema
OutputSchema returns the explicit native output schema, including hidden inputs.
func (*BatchResult) QueryTrace ¶ added in v0.12.0
func (r *BatchResult) QueryTrace() *commonv1.Trace
QueryTrace returns the completed native execution trace after Close. Calling it before Close does not complete or snapshot an unfinished trace.
func (*BatchResult) SetTraceFinalizer ¶ added in v0.12.0
func (r *BatchResult) SetTraceFinalizer(finalizer func() *commonv1.Trace)
SetTraceFinalizer defers trace completion until batch consumption or Close has finished.
func (*BatchResult) TraceIterator ¶ added in v0.12.0
func (r *BatchResult) TraceIterator(ctx context.Context)
TraceIterator records final serialized consumption under the query processor's span. It must be configured before NativeIteratorFrom transfers consumption ownership.
type BuildContext ¶
type BuildContext struct {
Builder *vectorized.PipelineBuilder
Tracker *vectorized.MemoryTracker
Config measure.VectorizedConfig
}
BuildContext is the cross-cutting state threaded through every Build call. Builder accumulates operators; Tracker is the shared per-pipeline MemoryTracker (G7a) every memory-bookkeeping operator must use; Config supplies BatchSize and other runtime knobs.
type DistributedPlan ¶
type DistributedPlan struct {
// contains filtered or unexported fields
}
DistributedPlan is the vectorized liaison-side distributed measure plan. It consumes data-node raw frame bodies as []byte values from RawFrameCodec, decodes them into vectorized batches, and runs the liaison operators without routing through the row-compatible logical distributedPlan.
func AnalyzeDistributed ¶
func AnalyzeDistributed( req *measurev1.QueryRequest, measureSchemas []*databasev1.Measure, indexRules [][]*databasev1.IndexRule, cfg vmeasure.VectorizedConfig, patterns ...model.IndexedPattern, ) (*DistributedPlan, error)
AnalyzeDistributed builds the vectorized distributed liaison plan. measureSchemas is the per-group slice of Measure schemas (one entry per req.Groups element). indexRules is the corresponding per-group slice of index rule sets (ec.GetIndexRules() for each group). Both slices must be in request-group order. Single-group callers may pass a length-1 slice for each (the existing behavior is preserved byte-for-byte).
When indexRules is nil or empty and req.OrderBy.IndexRuleName is non-empty, the resolver surfaces an "index rule X not found" error byte-equivalent to the row path.
func (*DistributedPlan) Execute ¶
Execute broadcasts the internal query and executes the liaison-side vectorized plan. For single-group requests, one broadcast is issued for all groups (existing behavior). For multi-group requests, one broadcast is issued per group, each carrying a single-element Groups slice, so data nodes can answer with a schema that matches only their local group's columns.
func (*DistributedPlan) ExecuteBatches ¶ added in v0.12.0
func (p *DistributedPlan) ExecuteBatches(ctx context.Context) (result *BatchResult, err error)
ExecuteBatches executes the native plan without constructing intermediate DataPoints. It scans the data nodes as streams of chunks and reads them only as far as the output is pulled: the rows merge decodes one chunk at a time, and a time-bucketed aggregation reduces and emits a bucket once every node has passed it. The returned result owns the node streams and every batch, and must be closed, including after cancellation: closing it cancels the scans on the data nodes.
func (*DistributedPlan) RequiresSingleStage ¶ added in v0.12.0
func (p *DistributedPlan) RequiresSingleStage() bool
RequiresSingleStage reports whether p's Agg is a COUNT_DISTINCT that must resolve to exactly one lifecycle stage (design §7.4). Callers that resolve node selectors from stages (banyand/dquery) must check this after resolution and before dispatch — AnalyzeDistributed cannot check it itself, since it never resolves stages.
func (*DistributedPlan) String ¶
func (p *DistributedPlan) String() string
String returns a concise plan rendering for tracing.
type GroupBatches ¶ added in v0.12.0
type GroupBatches struct {
Schema *vectorized.BatchSchema
Hidden logical.HiddenTagSet
PlanString string
Batches []*vectorized.RecordBatch
// contains filtered or unexported fields
}
GroupBatches owns copies of one group's borrowed batch descriptors and columns. The native result stays open until Release to retain any borrowed cell payloads.
func (*GroupBatches) Release ¶ added in v0.12.0
func (g *GroupBatches) Release()
Release closes the native group and releases copied output and reservations.
type GroupByAgg ¶
type GroupByAgg struct {
Child VecPlan
GroupBy *model.MeasureGroupBy
Agg *model.MeasureAgg
Mode vmeasure.AggMode
// contains filtered or unexported fields
}
GroupByAgg is the vec aggregation/grouping node. It fuses GroupBy and a single Aggregation into one BatchAggregation operator (see G7d planner), and also covers the two single-sided shapes:
- GroupBy + Agg → BatchAggregation: key columns + one agg result column (schema-rewriting; timestamp dropped, per G7 decision D2).
- Agg without GroupBy → scalar reduce: BatchAggregation with no key columns, a single output row (first-seen tags + agg result).
- GroupBy without Agg → raw GroupBy: a first-seen-row-per-group BatchGroupBy, schema-preserving.
The concrete operator (and therefore the output schema) is chosen by vmeasure.BuildOperators from which of GroupBy/Agg is set. Mode selects AggModeAll (single-node final reduce) vs AggModeMap (G9f.2 distributed Map phase emitting typed-column partials). Mode is irrelevant for raw GroupBy (BatchGroupBy doesn't carry partial state).
func NewGroupByAgg ¶
func NewGroupByAgg(child VecPlan, groupBy *model.MeasureGroupBy, agg *model.MeasureAgg, mode vmeasure.AggMode) (*GroupByAgg, error)
NewGroupByAgg constructs a GroupByAgg node wrapping child. At least one of groupBy/agg must be set (BuildOperators routes on which); child must not be nil. mode selects AggModeAll for the single-node path or AggModeMap for the distributed Map phase (G9f.2); AggModeReduce is rejected here (the reduce plan is built liaison-side in G9f.3).
func (*GroupByAgg) Build ¶
func (g *GroupByAgg) Build(ctx context.Context, bc *BuildContext) error
Build recurses into child, then attaches the aggregation operator. A time-bucketed GroupBy wires BatchTimeBucket in via PipelineBuilder.Transform, since it is a PullOperator that pulls from upstream directly rather than a BreakerOperator driven by Break's Consume/Finalize contract (see BatchTimeBucket's doc for why that distinction is what makes its memory bound real). Every other shape attaches its BatchAggregation/BatchGroupBy via Break, as before. The pipeline-shared MemoryTracker from bc threads through either way.
func (*GroupByAgg) Children ¶
func (g *GroupByAgg) Children() []VecPlan
Children returns the single child.
func (*GroupByAgg) Schema ¶
func (g *GroupByAgg) Schema() *vectorized.BatchSchema
Schema returns the aggregation output schema. The schema is computed lazily on first call by running BuildOperators (or, for a time-bucketed GroupBy, BuildTimeBucketOperator with a nil upstream — see its doc) against the child schema; subsequent calls return the cached value.
func (*GroupByAgg) String ¶
func (g *GroupByAgg) String() string
String returns a single-line debug description.
type Limit ¶
Limit applies offset+limit windowing as a fusible operator on the pipeline. Schema-preserving: emits the same column layout as its child.
Limit <= 0 means "no limit"; the analyzer normalises QueryRequest.Limit of zero to the row-path default (100) before constructing this node.
func (*Limit) Build ¶
func (l *Limit) Build(ctx context.Context, bc *BuildContext) error
Build recurses into the child first, then attaches a BatchLimit as a fusible operator. If N is zero, no operator is attached — the caller's downstream nodes still see the source's full output.
func (*Limit) Schema ¶
func (l *Limit) Schema() *vectorized.BatchSchema
Schema returns the child's schema (Limit is schema-preserving).
type MultiGroupMerge ¶ added in v0.12.0
type MultiGroupMerge struct {
// contains filtered or unexported fields
}
MultiGroupMerge merges the per-group batch results of a local multi-group measure query. It derives the per-group request, so every group returns enough rows and the order-by column, runs the shared k-way row merger over the groups' batches, and exposes the merged batches before final row serialization.
A result that keeps the series-id, timestamp and version columns (plain rows, Top and raw GroupBy) is merged by sort key with version dedup. A time-bucketed aggregate keeps only the timestamp, so it is merged by time without dedup. Any other Agg output has no ordering column. Its groups are dispatched in partial mode without Top, offset or limit and reduced across groups with the liaison's reducer; Top, offset and limit are then applied once to the reduced rows. A caller that itself emits partials (a distributed data node) opts out with ConcatAggregates, and its per-group results are concatenated in group order, as each group's plan already applied its own limit. COUNT_DISTINCT is not additive across groups, so it is always concatenated.
Every batch the groups hand over, the reshaped copies and the merged output are charged to one memory tracker sized by the query memory budget.
func NewMultiGroupMerge ¶ added in v0.12.0
func NewMultiGroupMerge( ctx context.Context, req *measurev1.QueryRequest, schemas []logical.Schema, measureSchemas []*databasev1.Measure, cfg vmeasure.VectorizedConfig, opts ...MultiGroupOption, ) (*MultiGroupMerge, error)
NewMultiGroupMerge resolves how the groups of req are merged. schemas and measureSchemas are the per-group logical and measure schemas in request order.
func (*MultiGroupMerge) Collect ¶ added in v0.12.0
func (m *MultiGroupMerge) Collect(ctx context.Context, result *BatchResult, planStr string) (*GroupBatches, error)
Collect takes ownership of a native group result without materializing rows.
func (*MultiGroupMerge) GroupRequest ¶ added in v0.12.0
func (m *MultiGroupMerge) GroupRequest() *measurev1.QueryRequest
GroupRequest returns the shared request, which still names every group. A group is dispatched with GroupRequestFor, which narrows it to that group when the query's window can be pushed down.
func (*MultiGroupMerge) GroupRequestFor ¶ added in v0.12.0
func (m *MultiGroupMerge) GroupRequestFor(group string) *measurev1.QueryRequest
GroupRequestFor returns the request to dispatch for one group. A plain-row query names only that group, so the scan can push the group's window down to storage the way a data node does: the window is pushed only for a request over a single group, and a request that still named every group read every document of every group. A query that reduces aggregates or ranks a top-N keeps the shared request.
func (*MultiGroupMerge) Merge ¶ added in v0.12.0
func (m *MultiGroupMerge) Merge(ctx context.Context, groups []*GroupBatches) (executor.MIterator, error)
Merge returns a native iterator over merged batches, transferring Close ownership.
func (*MultiGroupMerge) MergeBatches ¶ added in v0.12.0
func (m *MultiGroupMerge) MergeBatches(ctx context.Context, groups []*GroupBatches) (*BatchResult, error)
MergeBatches takes ownership of groups and returns their merged native batches. Groups and reservations are released on failure or when the result is closed.
func (*MultiGroupMerge) ReducesAggregates ¶ added in v0.12.0
func (m *MultiGroupMerge) ReducesAggregates() bool
ReducesAggregates reports whether the groups must be dispatched in partial mode, because MergeBatches reduces their aggregation partials across groups.
func (*MultiGroupMerge) Tracker ¶ added in v0.12.0
func (m *MultiGroupMerge) Tracker() *vectorized.MemoryTracker
Tracker returns the shared query memory tracker used by collection and merging.
type MultiGroupOption ¶ added in v0.12.0
type MultiGroupOption func(*multiGroupOptions)
MultiGroupOption customizes NewMultiGroupMerge.
func ConcatAggregates ¶ added in v0.12.0
func ConcatAggregates() MultiGroupOption
ConcatAggregates keeps each group's aggregation result as is and concatenates them, for callers whose own result is itself a partial that is reduced elsewhere.
type Scan ¶
type Scan struct {
BatchSchema *vectorized.BatchSchema
Source vectorized.PullOperator
Params ScanParams
}
Scan is the leaf node of every vec plan. It carries the schema for downstream nodes to consult and the parameters the executor needs to build a source. Source is set by the executor immediately before Build is called; tests can populate it directly to drive Build with a fake source.
func NewScan ¶
func NewScan(schema *vectorized.BatchSchema, params ScanParams) *Scan
NewScan constructs a Scan node with an analyzed schema and params. Source is unset; the executor or test populates it before Build.
func (*Scan) Build ¶
func (s *Scan) Build(_ context.Context, bc *BuildContext) error
Build attaches Source as the pipeline source. The executor must set Source before invoking Build; an unset Source is treated as a programming error (the executor missed a step).
func (*Scan) Schema ¶
func (s *Scan) Schema() *vectorized.BatchSchema
Schema returns the BatchSchema of rows this node emits.
type ScanParams ¶
type ScanParams struct {
// PatternRequests intersect whole-value indexed patterns before row reads.
PatternRequests []native.TermSetRequest
Measure *databasev1.Measure
TimeRange *timestamp.TimeRange
// Criteria is the remaining (non-entity) filter the series index
// evaluates; Fields resolves its tag names to engine fields. See
// pkg/query/vectorized/measure/plan's entity-extraction helper, which
// replaces the row path's inverted.BuildQuery (NIDX-03 §5).
Criteria *modelv1.Criteria
Fields model.FieldResolver
Entities [][]*modelv1.TagValue
GroupBy *model.MeasureGroupBy
Agg *model.MeasureAgg
TagProjection []model.TagProjection
FieldProjection []string
}
ScanParams holds everything the executor needs to materialize a batch source from a Measure. The analyzer populates these from the proto QueryRequest at plan-build time; the executor (G8c) consults the MeasureExecutionContext and constructs the MeasureBatchResult right before calling Scan.Build.
type Top ¶
Top selects the top-N (or bottom-N when Asc) rows by FieldName. Wraps `measure.BatchTop`, a single global heap. This matches the row path's req.Top handler (pkg/query/logical/measure.topOp), which also inserts every data point into one TopQueue — req.Top is a whole-result top-N, not the per-timestamp TopNQuery RPC (out of scope, see .omc/g9-plan.md G9a).
Schema-preserving.
func (*Top) Build ¶
func (t *Top) Build(ctx context.Context, bc *BuildContext) error
Build recurses into the child, locates FieldName in the propagated schema, then attaches a BatchTop as a breaker. The FieldName must reference a field column in the current schema.
func (*Top) Schema ¶
func (t *Top) Schema() *vectorized.BatchSchema
Schema returns the child's schema (Top is schema-preserving).
type VecPlan ¶
type VecPlan interface {
Schema() *vectorized.BatchSchema
Children() []VecPlan
Build(ctx context.Context, bc *BuildContext) error
String() string
}
VecPlan is the vectorized measure-query plan node interface.
Schema returns the BatchSchema of rows this node emits — for fusible or schema-preserving breakers it matches the input schema; for schema-rewriting breakers (BatchAggregation) it is the operator's OutputSchema.
Children returns the immediate child plan nodes (zero for leaves).
Build appends this node's contribution to bc.Builder. The leaf (Scan) calls Builder.From; fusible nodes call Builder.Apply; breakers call Builder.Break. Build must call Build on its children before attaching itself so the source flows in tree order.
String returns a single-line debug description ("Scan(measure=foo)", "GroupByAgg(keys=svc, fn=sum, field=value)", etc.) so plan trees can be pretty-printed with PrintTree.
func Analyze ¶
func Analyze(req *measurev1.QueryRequest, measureSchema *databasev1.Measure, mode measure.AggMode, indexChecker logical.IndexChecker) (VecPlan, error)
Analyze translates a measurev1.QueryRequest + its Measure schema into a VecPlan tree. It is the vec counterpart of pkg/query/logical/measure (deprecated) but produces vec plan nodes — there is no leaf substitution into a row plan.
The returned tree is structural: it carries the static (proto-derived) query parameters in `Scan.Params` and the BatchSchema for downstream nodes to consult. Runtime fields that depend on the executor's MeasureExecutionContext — the resolved `index.Query` and the entity table — are NOT populated here; the executor (G8c) fills them in before invoking Build.
Errors are returned for:
- nil schema
- tag/field projection naming columns not in the schema
- GroupBy referencing a tag absent from the schema
- Agg referencing a field or tag absent from the schema, naming both or neither of field_name/tag_name, or naming a tag whose type or family qualification the target function does not support (design §6)
GroupBy and Agg may travel together (group + aggregate), or either alone: Agg without GroupBy is a scalar reduce (single output row); GroupBy without Agg is a raw GroupBy (first-seen row per group). Both mirror the row path (measure_plan_aggregation.go / measure_plan_groupby.go).
mode selects the BatchAggregation strategy when an agg operator is built: AggModeAll for single-node final reduce, AggModeMap for the distributed Map phase (G9f.2) that emits typed-column partials. AggModeReduce is rejected (the reduce plan is built liaison-side in G9f.3).
Source Files
¶
- analyzer.go
- batch_result.go
- dispatch.go
- distributed.go
- distributed_agg_stream.go
- distributed_rows.go
- distributed_rows_stream.go
- distributed_scan.go
- entity_extract.go
- executor.go
- groupby_agg.go
- hidden_tags.go
- limit.go
- multi_group_merge.go
- multi_group_schema.go
- orderby.go
- plan.go
- scan.go
- sort_key.go
- standalone_merge.go
- standalone_projection.go
- top.go
- tracing_summary.go