Query Solvers
The query engine resolves channel selections and evaluates events and
aggregations against silver-layer data. It does this through a solver:
the component that knows how your silver tables are physically laid out
and how to read them. Impulse ships a single solver — DefaultSolver —
that adapts to the silver tables you have.
One solver, three required tables
DefaultSolver runs on just three silver tables:
container_metrics— one row per container (recording).channel_metrics— one row per(container_id, channel_id)channel.channels— the time-series sample data (RLE or raw).
Everything else is optional. In particular, the tag tables
(container_tags, channel_tags) are not required — supply them only
when you want EAV-style tag filtering/selection. The channel_mapping
and unit_conversion tables are likewise optional add-ons that unlock
channel aliasing and unit conversion when present.
How DefaultSolver adapts
The solver chooses its behaviour per query from the tables you configure:
- Channel selection. With a
channel_tagstable configured, channels are selected from its narrow EAV(key, value)rows (pivoted on the fly). Without one, channels are selected directly from columns onchannel_metrics— so an attribute such aschannel_namelives as a column onchannel_metrics. The presence ofsource.channel_tags_tableselects the mode. - Container filtering. With a
container_tagstable configured, containers are filtered from its narrow EAV rows. Without one, container attributes are read as columns oncontainer_metrics(the wide-only model). - Channel aliasing. When a
channel_mappingtable is configured, logical channel names (channel_with_alias(...)) resolve to physical channels, with optional per-alias unit conversion when aunit_conversiontable is also configured.
Tag tables, when present, are always read in the narrow EAV layout
(key, value) and pivoted on the fly.
Channel aliasing requires channel-identifying columns on channel_metrics
When you use aliasing (channel_with_alias(...) backed by a
channel_mapping table), DefaultSolver resolves each logical alias to a
physical channel by joining channel_mapping to channel_metrics. That
join needs columns on channel_metrics that identify a channel within a
container — by default channel_name and data_key (the
channel_metrics side of the alias-resolution join keys).
So when aliasing is in use, channel_metrics must carry those
identifying columns. This holds regardless of whether a channel_tags
table is configured: even if direct channel selection runs against the EAV
channel_tags table, alias resolution always joins channel_mapping
against channel_metrics.
You can change which columns are used via channel_mapping.join_keys (for
example, a single-column join when data_key is not part of the channel
identity in your layout) — see
Alias-resolution join keys.
Container-level metadata in expressions
Expressions can pull container-level metadata into their evaluation. When a selected
expression — or a UDF wrapped inside an aggregation, event, or calculated channel — declares
container tags or metrics via container_tags= / container_metrics= (see
Defining Expressions),
DefaultSolver gathers the union across all selections, reads just those values from the silver
layer — metrics from container_metrics columns, tags from the EAV container_tags table
(pivoted) — and broadcast-joins them onto each container's evaluation frame so the UDF receives them.
The values are constant per container, and the same wiring applies to
solve_calculated_channels.
Requesting a nonexistent container_metrics column, or any container_tags without a
container_tags_table configured, raises a ValueError.
During the planning build that precedes solve-time (an empty run the engine uses to infer result
types; see Evaluation), these declared
keys are present but their values are None. UDFs that read container metadata must be null-safe
for that call.
Table requirements
| Silver table | Required? | Notes |
|---|---|---|
container_metrics | yes | One row per container. |
channel_metrics | yes | One row per channel. Carries channel-selection columns in the wide model, and the channel-identifying columns (channel_name, data_key) required for aliasing. |
channels | yes | Time-series sample data (RLE or raw). |
container_tags | optional | Narrow EAV. Omit for the wide-only container model. |
channel_tags | optional | Narrow EAV. Omit when channel-selection attributes live on channel_metrics. |
channel_mapping | optional | Channel aliases. Requires channel-identifying columns on channel_metrics (see above). |
unit_conversion | optional | Per-alias unit conversion (used together with channel_mapping). |
See the Silver Layer Schema for the columns each table is expected to carry.
Configuring the solver
Solver tuning lives under the query_engine section of your report config:
query_engine.solver— the solver to use. Defaults to"DefaultSolver". The values"DeltaSolver"and"KeyValueStoreSolver"are deprecated aliases retained for backward compatibility; both resolve toDefaultSolver.query_engine.data_typeandraw_encoder— declare whetherchannelsholds pre-encoded[tstart, tend)intervals ("RLE", the default) or raw point samples ("RAW"). For raw data,raw_encoderselects how samples are converted to intervals at query time:"RLE"(default) run-length encodes equal-valued runs into single intervals;"INTERVAL"only derivestendand drops exact duplicates. In both modestendis derived from the next sample's timestamp (the last sample falls back to its own timestamp) — see How Impulse interprets intervals for validity semantics and the definition of a duplicate point.- Solver column mappings and filters
— adapt the solver to a silver layer whose physical column names
diverge from Impulse's internal names, scope reads by
project_id, or apply per-table equality filters. query_engine.enable_pushdown— compute supported expressions natively in Spark before the pandas UDF (see Spark pushdown). Off by default.
If query_engine is omitted from your config entirely, the engine runs
with DefaultSolver and data_type = "RLE".
Calculated channels
The standard solve() produces a wide result — one row per container, one column per selection.
DefaultSolver.solve_calculated_channels is a parallel entry point that produces a narrow,
silver-shaped result instead: it explodes each selection's SampleSeries into one row per sample
interval, emitting container_id, channel_id, tstart, tend, value plus a single self-describing
identity map column.
Every selection must be a CalculatedChannel (identity keys are arbitrary and
need not match across selections), and each wrapped expression must evaluate to a SampleSeries. The stage reuses the same
metadata filter pipeline as solve() to resolve the input channels, then runs a grouped-map UDF per
container. Only DefaultSolver implements it — the base QuerySolver raises NotImplementedError.
The channel_id column of channels must be an integer or long column to hold the calculated
channels' ids.
from impulse_query_engine.analyze.query.channels.calculated_channel import CalculatedChannel
from impulse_query_engine.analyze.query.solvers.default_solver import DefaultSolver
cc = CalculatedChannel(
db.query.channel(channel_name="Vehicle Speed Sensor") * 3.6,
{"channel_name": "speed_kmh", "data_key": "CALC"},
)
df = db.query.select(cc).solve_calculated_channels(spark, solver=DefaultSolver(spark))
# df: [container_id, channel_id, tstart, tend, value, identity]
The reporting layer builds on this stage to persist derived channels to the gold layer — see Channels.
Spark pushdown (opt-in)
Every selection of a solve is evaluated in one pandas UDF per container, and by default the raw rows of every channel the selections reference are shipped into it. With pushdown enabled, a rule-based optimizer finds expression subtrees that Spark can compute natively, computes them before the UDF, and ships their (smaller) result instead of the raw rows.
Pushdown Rules lists the subtrees Spark computes today (resample and
comparisons with a number), their limits and the planned rules. The subtree can sit anywhere in
an expression, inside a CalculatedChannel, an aggregation, or an event condition; only the
pushed-down part runs in Spark.
solver = DefaultSolver(spark, enable_pushdown=True)
In a report config, set query_engine.enable_pushdown to true.
All selections of a solve share the raw data of their channels, so a channel is pushed down only
if every use of it in the solve is a pushed-down subtree. If the same channel is also used in
any other way, e.g. rpm.resample(1e6) next to rpm.max(), its raw rows are still needed: they are
shipped as before and the resample runs in pandas. Results are the same either way.
Solves without the pandas UDF
When every selection of a solve() call (in a report: of a solve batch) is a pushed-down
expression as a whole and Spark can produce its result, the result is computed entirely in
Spark and no pandas UDF runs. Spark produces the results of comparisons (lists of intervals);
this is the case for lightweight outlier detection, e.g.
rpm = q.channel(channel_name="eng_rpm")
q.select((rpm > 5000).alias("rpm_high"), (rpm < 300).alias("rpm_low")).solve(spark, solver=solver)
or a report whose events are all such comparisons. A selection that is a series, e.g. a bare
rpm.resample(1e6), is pushed down too, but solve() returns series as serialized
SampleSeries objects, which only the UDF produces; use a calculated channel (below) to get
resampled rows without the UDF.
If any selection of the call needs the UDF, e.g. (rpm > 5000).debounce(1e6), speed.max() or
rpm.resample(1e6), all of them are evaluated in the UDF as usual; their pushed-down parts still
run in Spark. Either way the result is identical, including one row per container whose channels
have data, with an empty list of intervals where a comparison never holds.
Calculated channels without the pandas UDF
When every calculated channel of a solve_calculated_channels call (in a report: of a solve
batch) is a pushed-down expression as a whole, e.g.
CalculatedChannel(veh_spd.resample(1e6), {...}), its rows are produced entirely in Spark and no
pandas UDF runs. If any calculated channel of the call needs the pandas evaluation, e.g.
veh_spd.resample(1e6) * 3.6, all of them are evaluated in the UDF as usual; their pushed-down
parts still run in Spark. Either way the rows are identical.
API reference
Auto-generated symbol-level docs:
DefaultSolverQuerySolver— abstract base class defining the six-stage solver pipeline.SolverConfig— per-table column mappings, filters, and project scoping.QueryOptimizerandPushdownRule— the Spark pushdown optimizer and the interface for its rules;pipelineandSeriesContext— how rules run in Spark and what they can use;ConditionPushdownRule— comparisons with a number.