Skip to main content

canonical_boundary_stages

Function canonical_boundary_stages 

Source
pub fn canonical_boundary_stages(
    promql: Arc<str>,
    tree: &NativeTree,
    children: &[LogicalPlan],
    source_tags: &[Vec<String>],
    grid: &Arc<EvalGrid>,
    time_index: &str,
    tags: &[String],
    metric: &Option<Arc<str>>,
    format: FusedOutputFormat,
    root_kind: FieldKind,
    output_tags_of: OutputTags,
    field_names: FieldNames,
) -> Option<(LogicalPlan, Vec<String>)>
Expand description

Lowers a tree whose root is a canonical merge into a producer and a canonical router.

The tree says the statement answers one series per canonical label set; what it cannot say is where the pieces of one set are, because a rewrite created them after the scan split the rows. So the pieces have to meet before the answer is written, and there are only two honest ways to make them meet: read every partition in one execution, or route each label set to one owner. The first takes the caller’s parallelism away for the whole query; this is the second.

Two stages come out of it, and each has one job:

  • the producer runs the tree’s root merge on every scan partition. Its merge collects the pieces that partition holds - which is what makes a same-partition collision an error here, before anything is routed - and it exports one series per label set as a series frame. It is explicitly partition-local: the same node without that distinction would gather its inputs and answer everything in one execution.
  • the router is SeriesRepartitionExec’s canonical routing, which collects the pieces of one label set from every input partition. It is the conservative router - a label set is published only once every producer contributed it or ended - because a producer promises one series per set per partition, not that each set lives in one partition. A second piece of one set that holds a position another piece already holds is the same error, reported while that label set is assembled, and each output of the router then holds whole label sets: one series per set, complementary points joined.

None when the boundary cannot be built, so the caller keeps the plan it would have chosen. The stages of a canonical boundary over tree, and the columns its frames carry.

format says what the caller above reads: a statement root reads the boundary’s rows, and anything else reads the assembled frames as an ordinary evaluated input.