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

Method new

src/expr/src/row/collection.rs:70–89  ·  view source on GitHub ↗

Create a new [`RowCollection`] from a collection of [`Row`]s. Sorts data by `order_by`. Note that all row collections to be merged must be constructed with the same `order_by` to ensure a consistent sort order. Anything else is undefined behavior. TODO: Remember the `order_by` and assert that it is the same for all collections.

(mut rows: Vec<(Row, NonZeroUsize)>, order_by: &[ColumnOrder])

Source from the content-addressed store, hash-verified

68 /// to ensure a consistent sort order. Anything else is undefined behavior.
69 // TODO: Remember the `order_by` and assert that it is the same for all collections.
70 pub fn new(mut rows: Vec<(Row, NonZeroUsize)>, order_by: &[ColumnOrder]) -> Self {
71 let comparator = RowComparator::new(order_by);
72 // Sort data to maintain sortedness invariants.
73 rows.sort_by(|(row1, _diff1), (row2, _diff2)| {
74 comparator.compare_rows(row1, row2, || row1.cmp(row2))
75 });
76
77 // Pre-sizing our buffer should allow us to make just 1 allocation, and
78 // use the perfect amount of memory.
79 //
80 // Note(parkmycar): I didn't do any benchmarking to determine if this
81 // is faster, so feel free to change this if you'd like.
82 let encoded_size = rows.iter().map(|(row, _diff)| row.data_len()).sum();
83
84 let mut builder = Self::builder(encoded_size, rows.len());
85 for (row, diff) in rows {
86 builder.push(row.as_row_ref(), diff);
87 }
88 builder.build()
89 }
90
91 fn iter(&self) -> impl Iterator<Item = (&RowRef, NonZeroUsize)> {
92 self.rows.iter().zip_eq(self.diffs.iter().copied())

Callers

nothing calls this directly

Calls 10

compare_rowsMethod · 0.80
sumMethod · 0.80
data_lenMethod · 0.80
as_row_refMethod · 0.80
cmpMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected