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

Function first_value_no_list

src/expr/src/relation/func.rs:915–953  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

913/// Like `first_value`, but doesn't perform the final wrapping in a list, returning an Iterator
914/// instead.
915fn first_value_no_list<'a: 'b, 'b, I>(
916 datums: I,
917 callers_temp_storage: &'b RowArena,
918 order_by: &[ColumnOrder],
919 window_frame: &WindowFrame,
920) -> impl Iterator<Item = Datum<'b>>
921where
922 I: IntoIterator<Item = Datum<'a>>,
923{
924 // Sort the datums according to the ORDER BY expressions and return the (OriginalRow, InputValue) record
925 let datums = order_aggregate_datums(datums, order_by);
926
927 // Decode the input (OriginalRow, InputValue) into separate datums
928 let (orig_rows, args): (Vec<_>, Vec<_>) = datums
929 .into_iter()
930 .map(|d| {
931 let mut iter = d.unwrap_list().iter();
932 let original_row = iter.next().unwrap();
933 let arg = iter.next().unwrap();
934
935 (original_row, arg)
936 })
937 .unzip();
938
939 let results = first_value_inner(args, window_frame);
940
941 callers_temp_storage.reserve(results.len());
942 results
943 .into_iter()
944 .zip_eq(orig_rows)
945 .map(|(result_value, original_row)| {
946 callers_temp_storage.make_datum(|packer| {
947 packer.push_list_with(|packer| {
948 packer.push(result_value);
949 packer.push(original_row);
950 });
951 })
952 })
953}
954
955fn first_value_inner<'a>(datums: Vec<Datum<'a>>, window_frame: &WindowFrame) -> Vec<Datum<'a>> {
956 let length = datums.len();

Callers 2

first_valueFunction · 0.85
eval_with_unnest_listMethod · 0.85

Calls 13

order_aggregate_datumsFunction · 0.85
first_value_innerFunction · 0.85
unwrap_listMethod · 0.80
unwrapMethod · 0.80
make_datumMethod · 0.80
push_list_withMethod · 0.80
mapMethod · 0.45
into_iterMethod · 0.45
iterMethod · 0.45
nextMethod · 0.45
reserveMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected