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

Function rank_no_list

src/expr/src/relation/func.rs:509–557  ·  view source on GitHub ↗

Like `rank`, but doesn't perform the final wrapping in a list, returning an Iterator instead.

(
    datums: I,
    callers_temp_storage: &'b RowArena,
    order_by: &[ColumnOrder],
)

Source from the content-addressed store, hash-verified

507/// Like `rank`, but doesn't perform the final wrapping in a list, returning an Iterator
508/// instead.
509fn rank_no_list<'a: 'b, 'b, I>(
510 datums: I,
511 callers_temp_storage: &'b RowArena,
512 order_by: &[ColumnOrder],
513) -> impl Iterator<Item = Datum<'b>>
514where
515 I: IntoIterator<Item = Datum<'a>>,
516{
517 // Keep the row used for ordering around, as it is used to determine the rank
518 let datums = order_aggregate_datums_with_rank(datums, order_by);
519
520 let mut datums = datums
521 .into_iter()
522 .map(|(d0, order_row)| {
523 d0.unwrap_list()
524 .iter()
525 .map(move |d1| (d1, order_row.clone()))
526 })
527 .flatten();
528
529 callers_temp_storage.reserve(datums.size_hint().0);
530 datums
531 .next()
532 .map_or(vec![], |(first_datum, first_order_row)| {
533 // Folding with (last order_by row, last assigned rank,
534 // row number, output vec)
535 datums.fold(
536 (first_order_row, 1, 1, vec![(first_datum, 1)]),
537 |mut acc, (next_datum, next_order_row)| {
538 let (ref mut acc_row, ref mut acc_rank, ref mut acc_row_num, ref mut output) = acc;
539 *acc_row_num += 1;
540 // Identity is based on the order_by expression
541 if *acc_row != next_order_row {
542 *acc_rank = *acc_row_num;
543 *acc_row = next_order_row;
544 }
545
546 (*output).push((next_datum, *acc_rank));
547 acc
548 })
549 }.3).into_iter().map(|(d, i)| {
550 callers_temp_storage.make_datum(|packer| {
551 packer.push_list_with(|packer| {
552 packer.push(Datum::Int64(i));
553 packer.push(d);
554 });
555 })
556 })
557}
558
559/// The expected input is in the format of `[((OriginalRow, [EncodedArgs]), OrderByExprs...)]`
560/// The output is in the format of `[result_value, original_row]`.

Callers 2

rankFunction · 0.85
eval_with_unnest_listMethod · 0.85

Calls 14

unwrap_listMethod · 0.80
foldMethod · 0.80
make_datumMethod · 0.80
push_list_withMethod · 0.80
flattenMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
reserveMethod · 0.45
size_hintMethod · 0.45

Tested by

no test coverage detected