Struct expr::JoinInputMapper [−][src]
pub struct JoinInputMapper {
arities: Vec<usize>,
input_relation: Vec<usize>,
prior_arities: Vec<usize>,
}
Expand description
Any column in a join expression exists in two contexts:
- It has a position relative to the result of the join (global)
- It has a position relative to the specific input it came from (local) This utility focuses on taking expressions that are in terms of the local input and re-expressing them in global terms and vice versa.
Methods in this class that take an argument equivalences
are only
guaranteed to return a correct answer if equivalence classes are in
canonical form.
(See crate::relation::canonicalize::canonicalize_equivalences
.)
Fields
arities: Vec<usize>
The number of columns per input. All other fields in this struct are derived using the information in this field.
input_relation: Vec<usize>
Looks up which input each column belongs to. Derived from arities
.
Stored as a field to avoid recomputation.
prior_arities: Vec<usize>
The sum of the arities of the previous inputs in the join. Derived from
arities
. Stored as a field to avoid recomputation.
Implementations
Creates a new JoinInputMapper
and calculates the mapping of global context
columns to local context columns.
Creates a new JoinInputMapper
and calculates the mapping of global context
columns to local context columns. Using this method saves is more
efficient if input types have been pre-calculated
Creates a new JoinInputMapper
and calculates the mapping of global context
columns to local context columns. Using this method saves is more
efficient if input arities have been pre-calculated
reports sum of the number of columns of each input
reports total numbers of inputs in the join
Using the keys that came from each local input, figures out which keys remain unique in the larger join Currently, we only figure out a small subset of the keys that can remain unique.
returns the arity for a particular input
All column numbers in order for a particular input in the local context
All column numbers in order for a particular input in the global context
Takes an expression from the global context and creates a new version
where column references have been remapped to the local context.
Assumes that all columns in expr
are from the same input.
Takes an expression from the local context of the index
th input and
creates a new version where column references have been remapped to the
global context.
Remap column numbers from the global to the local context.
Returns a 2-tuple (<new column number>, <index of input>)
Remap a column number from a local context to the global context.
Takes a HashSet of columns in the global context and splits it into
a Vec
containing self.total_inputs()
HashSets, each containing
the localized columns that belong to the particular input.
Find the sorted, dedupped set of inputs an expression references
Returns the index of the only input referenced in the given expression.
pub fn find_bound_expr(
&self,
expr: &MirScalarExpr,
bound_inputs: &[usize],
equivalences: &[Vec<MirScalarExpr>]
) -> Option<MirScalarExpr>
pub fn find_bound_expr(
&self,
expr: &MirScalarExpr,
bound_inputs: &[usize],
equivalences: &[Vec<MirScalarExpr>]
) -> Option<MirScalarExpr>
Takes an expression in the global context and looks in equivalences
for an equivalent expression (also expressed in the global context) that
belongs to one or more of the inputs in bound_inputs
Examples
use repr::{Datum, ColumnType, RelationType, ScalarType};
use expr::{JoinInputMapper, MirRelationExpr, MirScalarExpr};
// A two-column schema common to each of the three inputs
let schema = RelationType::new(vec![
ScalarType::Int32.nullable(false),
ScalarType::Int32.nullable(false),
]);
// the specific data are not important here.
let data = vec![Datum::Int32(0), Datum::Int32(1)];
let input0 = MirRelationExpr::constant(vec![data.clone()], schema.clone());
let input1 = MirRelationExpr::constant(vec![data.clone()], schema.clone());
let input2 = MirRelationExpr::constant(vec![data.clone()], schema.clone());
// [input0(#0) = input2(#1)], [input0(#1) = input1(#0) = input2(#0)]
let equivalences = vec![
vec![MirScalarExpr::Column(0), MirScalarExpr::Column(5)],
vec![MirScalarExpr::Column(1), MirScalarExpr::Column(2), MirScalarExpr::Column(4)],
];
let input_mapper = JoinInputMapper::new(&[input0, input1, input2]);
assert_eq!(
Some(MirScalarExpr::Column(4)),
input_mapper.find_bound_expr(&MirScalarExpr::Column(2), &[2], &equivalences)
);
assert_eq!(
None,
input_mapper.find_bound_expr(&MirScalarExpr::Column(0), &[1], &equivalences)
);
pub fn try_map_to_input_with_bound_expr(
&self,
expr: MirScalarExpr,
index: usize,
equivalences: &[Vec<MirScalarExpr>]
) -> Option<MirScalarExpr>
pub fn try_map_to_input_with_bound_expr(
&self,
expr: MirScalarExpr,
index: usize,
equivalences: &[Vec<MirScalarExpr>]
) -> Option<MirScalarExpr>
Try to rewrite an expression from the global context so that all the
columns point to the index
input by replacing subexpressions with their
bound equivalents in the index
th input if necessary.
The return value, if not None, is in the context of the index
th input
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for JoinInputMapper
impl Send for JoinInputMapper
impl Sync for JoinInputMapper
impl Unpin for JoinInputMapper
impl UnwindSafe for JoinInputMapper
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more