project_ordering

Function project_ordering 

Source
pub fn project_ordering(
    ordering: &LexOrdering,
    schema: &SchemaRef,
) -> Option<LexOrdering>
Expand description

Projects a single LexOrdering onto the given schema.

This function attempts to rewrite every PhysicalSortExpr in the provided LexOrdering so that any Column expressions point at the correct field indices in schema.

Key details:

  • Columns are matched by name, not by index. The index of each matched column is looked up with Schema::column_with_name and a new Column with the correct index is substituted.
  • If an expression references a column name that does not exist in schema, projection of the current ordering stops and only the already rewritten prefix is kept. This models the fact that a lexicographical ordering remains valid for any leading prefix whose expressions are present in the projected schema.
  • If no expressions can be projected (i.e. the first one is missing), the function returns None.

Return value:

  • Some(LexOrdering) if at least one sort expression could be projected. The returned ordering may be a strict prefix of the input ordering.
  • None if no part of the ordering can be projected onto schema.

Example

Suppose we have an input ordering [col("a@0"), col("b@1")] but the projected schema only contains b and not a. The result will be Some([col("a@0")]). In other words, the column reference is reindexed to match the projected schema. If neither a nor b is present, the result will be None.