MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / permutation_for_arrangement

Function permutation_for_arrangement

src/expr/src/linear.rs:1516–1544  ·  view source on GitHub ↗

Derive supporting logic to support transforming rows to (key, val) pairs, and back again. We are given as input a list of mappings from columns to key indices, a key length, and an input arity. (The produced key should be the application of the key expressions.) To produce the `val` output, we will identify those input columns not found in the key expressions, and name all other columns. To reco

(
        key: &[impl Columns],
        unthinned_arity: usize,
    )

Source from the content-addressed store, hash-verified

1514 /// `compute_types::plan::AvailableCollections`; see the
1515 /// documentation there for more details.
1516 pub fn permutation_for_arrangement(
1517 key: &[impl Columns],
1518 unthinned_arity: usize,
1519 ) -> (Vec<usize>, Vec<usize>) {
1520 let columns_in_key: BTreeMap<_, _> = key
1521 .iter()
1522 .enumerate()
1523 .filter_map(|(i, key_col)| key_col.as_column().map(|c| (c, i)))
1524 .collect();
1525
1526 let mut input_cursor = key.len();
1527 let permutation = (0..unthinned_arity)
1528 .map(|c| {
1529 if let Some(c) = columns_in_key.get(&c) {
1530 // Column is in key (and thus gone from the value
1531 // of the thinned representation)
1532 *c
1533 } else {
1534 // Column remains in value of the thinned representation
1535 input_cursor += 1;
1536 input_cursor - 1
1537 }
1538 })
1539 .collect();
1540 let thinning = (0..unthinned_arity)
1541 .filter(|c| !columns_in_key.contains_key(c))
1542 .collect();
1543 (permutation, thinning)
1544 }
1545
1546 /// Given the permutations (see [`permutation_for_arrangement`] and
1547 /// (`dataflow::plan::AvailableCollections`) corresponding to two

Callers 12

keysMethod · 0.85
lowerMethod · 0.85
create_fromMethod · 0.85
create_fromMethod · 0.85
create_fromMethod · 0.85
column_names_for_idMethod · 0.85
newMethod · 0.85
import_indexMethod · 0.85
newMethod · 0.85
export_sinkMethod · 0.85

Calls 9

enumerateMethod · 0.80
as_columnMethod · 0.80
contains_keyMethod · 0.80
collectMethod · 0.45
iterMethod · 0.45
mapMethod · 0.45
lenMethod · 0.45
getMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected