Skip to main content

publish_legacy_schema

Function publish_legacy_schema 

Source
fn publish_legacy_schema(
    native: LogicalPlan,
    legacy: &LogicalPlan,
) -> Option<LogicalPlan>
Expand description

The native plan, wrapped in the projection that publishes legacy’s columns over it.

A hybrid CTE registers the plan as a table the outer SQL query reads, so the columns this plan publishes are the CTE’s columns: their names, their order, their types, their nullability and the metadata they carry are what the statement’s SQL sees, and a column list the CTE declares is applied to them by position. The two routes do not agree on that schema - the fused node takes its names from the compiled tree and publishes the time index first, while the existing planner names each value column after the expression it planned and publishes the labels first - so a CTE answered natively would make one statement mean different things depending on which route planned it. This wraps the native plan in the projection that publishes the existing planner’s answer for the same statement instead.

One column follows the answer rather than the existing planner: a native rows answer declares the per-row metric name, which the existing planner never publishes, and that column is part of what the statement answers. It is appended after the existing planner’s columns, so those keep their names, order, types and metadata, while a column list the CTE declares needs one more name - and a statement whose answer declares no name column (a scalar-typed answer) publishes none here. A CTE answered by the existing planner publishes exactly the columns it always has.

The projection is made of expressions - an alias per column, and a cast where the two routes carry the same values in different Arrow types - because that is what survives analysis: the analyzer rebuilds a projection’s schema from its expressions, so anything the projection declared but its expressions did not carry would be gone by the time the CTE’s columns are read.

The mapping is the identity on every column both plans publish alike - the time index and the label columns, which carry the same metadata on both routes now - and is a cast for a column whose identity is unambiguous: one native column of the same type once both are unencoded, no per-column metadata to lose and the same nullability. None says the two plans admit no such mapping - a differently named time index, an ambiguous set of columns left over, or a column a cast cannot reproduce faithfully - and the caller then keeps the existing plan rather than publish a column it cannot fill faithfully.