Skip to main content

impulse_query_engine.analyze.query.optimizer.context

What a pushdown rule sees of the samples it computes on.

A rule never handles DataFrames. The pipeline (:mod:.pipeline) evaluates the rule's hooks with a :class:SeriesContext, whose properties are Spark columns describing the current sample of one of the rule's series: its times and value, its neighbours, the run (e.g. continuous block) it belongs to, and facts about the whole series. Columns returned by a hook become part of the shared pass over the channel data.

ELEMENT_TYPE​

Element type of the arrays returned by :meth:PushdownRule.emit.

BLOCK​

Name of the built-in run of continuous samples.

nan_to_null​

def nan_to_null(col: Column) -> Column

col with NaN as null, as numpy.nanmin / nanmax skip it and Arrow encodes it.

converted​

def converted(value: Column, factor: Column, applies: Column) -> Column

value times the unit-conversion factor where applies, as the UDF's cache converts.

Like TimeSeriesCache.to_sample_series: a null or NaN factor leaves the value as it is.

element​

def element(tstart: Column | None = None,
tend: Column | None = None,
value: Column | None = None) -> Column

One emitted row; tstart / tend left out keep the row's own times.

run_col​

def run_col(run: str, name: str) -> str

Name of the pipeline column name of the run run.

Sample​

class Sample()

One sample as columns: tstart and tend as double, and its value as double.

RunBreak​

A run definition: whether the sample cur starts a new run after prev. It

is called with prev columns that are null before the series' first sample; a null result counts as a break.

Run​

class Run()

Where the current sample sits in its run, a maximal stretch without a break.

Arguments:

  • starts (Column): The sample starts its run.
  • id (Column): Number of the run within the series, from 1.
  • start (Column): tstart of the run's first sample.
  • next_starts (Column): The next sample starts a new run; null for the series' last sample.
  • is_last (Column): The run is the last of its series.

block_break​

def block_break(prev: Sample, cur: Sample) -> Column

Continuous blocks: a sample continues its block when it starts where the previous ended.

SeriesContext​

class SeriesContext()

Columns a rule's hooks build on, for the current sample of one of its series.

Every series is one channel's samples of one variant, ordered by (tstart, tend, value); all variants of a channel have the same samples. Rules running in series order (ordered) see neighbours, runs and series facts; per-sample rules see only the sample.

Arguments:

  • rule (PushdownRule): The rule the hooks belong to.
  • variants (Mapping[int, Pushdown]): The rule's variants in this solve.
  • key (Sequence[str]): Columns identifying a series.
  • order (Sequence[str]): The channel-data tstart, tend and value columns: the series order.
  • ordered (bool): Whether the pipeline runs the rule in series order.
  • runs (Mapping[str, str]): The rule's run names to pipeline run names.
  • kept (bool): Whether the hook runs on the kept samples (kept_columns, emit).
  • has_factor (bool): Whether the rows carry the channel's conversion factor (:data:FACTOR_COL).

kept_stage​

def kept_stage() -> SeriesContext

This context, for the hooks that run on the kept samples.

active​

def active() -> Column

The sample belongs to one of the rule's variants.

name​

def name(column: str) -> str

Pipeline name of the rule's column column.

col​

def col(column: str) -> Column

The rule's column column, defined by an earlier hook entry.

param​

def param(name: str) -> Column

The pushdown parameter name of the sample's variant.

per_variant​

def per_variant(column: Callable[[Pushdown], Column]) -> Column

column(pushdown) for the sample's variant: a CASE over the rule's variants.

tstart​

def tstart() -> Column

The sample's tstart as double.

tend​

def tend() -> Column

The sample's tend as double.

value​

def value() -> Column

The sample's value as double.

converted_value​

def converted_value() -> Column

The sample's value as the UDF's cache loads it for the variant's selector.

Multiplied by the channel's conversion factor for variants whose rule

sample​

def sample() -> Sample

The current sample.

prev​

def prev() -> Sample

The previous sample of the series; null columns for its first sample.

next​

def next() -> Sample

The next sample of the series; null columns for its last sample.

n​

def n() -> Column

Number of samples in the series.

last​

def last() -> Sample

The series' last sample.

first_in_chunk​

def first_in_chunk() -> Column

The sample is the first of its chunk.

in_chunk​

def in_chunk() -> WindowSpec

Window over the sample's chunk in series order, for local neighbour access.

Chunks are consecutive slices of a channel, the same for all its series; use :attr:prev, :attr:next and runs for anything that must see across chunk boundaries.

block​

def block() -> Run

The continuous block the sample belongs to (gaps end blocks).

run​

def run(name: str) -> Run

The sample's run of the rule's run definition name (see :meth:PushdownRule.runs).

block_end​

def block_end() -> Column

nanmax of the tend values of the sample's block (kept samples only).

RowsContext​

class RowsContext()

Columns a rule's finishing hooks build on, for one derived row of one of its series.

The finishing pass (:func:~.pipeline.finish_rows) sees all derived rows of a series (one channel's rows of one variant in a container), ordered like the UDF's cache orders them: by tstart, then tend, NaN and null last.

Arguments:

  • rule (PushdownRule): The rule the hooks belong to.
  • variants (Mapping[int, Pushdown]): The rule's variants in this solve.
  • series (WindowSpec): Window over the row's series in order.

active​

def active() -> Column

The row belongs to one of the rule's variants.

name​

def name(column: str) -> str

Pipeline name of the rule's finishing column column.

col​

def col(column: str) -> Column

The rule's finishing column column, defined by an earlier hook entry.

per_variant​

def per_variant(column: Callable[[Pushdown], Column]) -> Column

column(pushdown) for the row's variant: a CASE over the rule's variants.

tstart​

def tstart() -> Column

The row's tstart as double.

tend​

def tend() -> Column

The row's tend as double.

value​

def value() -> Column

The row's value as double.

prev​

def prev() -> Sample

The previous row of the series; null columns for its first row.

next​

def next() -> Sample

The next row of the series; null columns for its last row.

is_first​

def is_first() -> Column

The row is the first of its series.

is_last​

def is_last() -> Column

The row is the last of its series.

running​

def running() -> WindowSpec

Window from the series' first row up to the current row.

series​

def series() -> WindowSpec

Window over the row's series in order, for lag / lead.