MCPcopy Create free account
hub / github.com/apache/datafusion / evaluate

Method evaluate

datafusion/functions-window/src/rank.rs:276–312  ·  view source on GitHub ↗
(
        &mut self,
        values: &[ArrayRef],
        range: &Range<usize>,
    )

Source from the content-addressed store, hash-verified

274 }
275
276 fn evaluate(
277 &mut self,
278 values: &[ArrayRef],
279 range: &Range<usize>,
280 ) -> Result<ScalarValue> {
281 let row_idx = range.start;
282 // There is no argument, values are order by column values (where rank is calculated)
283 let range_columns = values;
284 let last_rank_data = get_row_at_idx(range_columns, row_idx)?;
285 let new_rank_encountered =
286 if let Some(state_last_rank_data) = &self.state.last_rank_data {
287 // if rank data changes, new rank is encountered
288 state_last_rank_data != &last_rank_data
289 } else {
290 // First rank seen
291 true
292 };
293 if new_rank_encountered {
294 self.state.last_rank_data = Some(last_rank_data);
295 self.state.last_rank_boundary += self.state.current_group_count;
296 self.state.current_group_count = 1;
297 self.state.n_rank += 1;
298 } else {
299 // data is still in the same rank
300 self.state.current_group_count += 1;
301 }
302
303 match self.rank_type {
304 RankType::Basic => Ok(ScalarValue::UInt64(Some(
305 self.state.last_rank_boundary as u64 + 1,
306 ))),
307 RankType::Dense => Ok(ScalarValue::UInt64(Some(self.state.n_rank as u64))),
308 RankType::Percent => {
309 exec_err!("Can not execute PERCENT_RANK in a streaming fashion")
310 }
311 }
312 }
313
314 fn evaluate_all_with_rank(
315 &self,

Callers 7

invoke_with_argsMethod · 0.45
run_any_matchFunction · 0.45
run_any_match_divFunction · 0.45
invoke_with_argsMethod · 0.45
eval_hof_on_i32_listFunction · 0.45
invoke_with_argsMethod · 0.45

Calls 1

get_row_at_idxFunction · 0.85

Tested by

no test coverage detected