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

Function get_random_function

datafusion/core/tests/fuzz_cases/window_fuzz.rs:329–459  ·  view source on GitHub ↗
(
    schema: &SchemaRef,
    rng: &mut StdRng,
    is_linear: bool,
)

Source from the content-addressed store, hash-verified

327}
328
329fn get_random_function(
330 schema: &SchemaRef,
331 rng: &mut StdRng,
332 is_linear: bool,
333) -> (WindowFunctionDefinition, Vec<Arc<dyn PhysicalExpr>>, String) {
334 let arg = if is_linear {
335 // In linear test for the test version with WindowAggExec we use insert SortExecs to the plan to be able to generate
336 // same result with BoundedWindowAggExec which doesn't use any SortExec. To make result
337 // non-dependent on table order. We should use column a in the window function
338 // (Given that we do not use ROWS for the window frame. ROWS also introduces dependency to the table order.).
339 col("a", schema).unwrap()
340 } else {
341 col("x", schema).unwrap()
342 };
343 let mut window_fn_map = HashMap::new();
344 // HashMap values consists of tuple first element is WindowFunction, second is additional argument
345 // window function requires if any. For most of the window functions additional argument is empty
346 window_fn_map.insert(
347 "sum",
348 (
349 WindowFunctionDefinition::AggregateUDF(sum_udaf()),
350 vec![arg.clone()],
351 ),
352 );
353 window_fn_map.insert(
354 "count",
355 (
356 WindowFunctionDefinition::AggregateUDF(count_udaf()),
357 vec![arg.clone()],
358 ),
359 );
360 window_fn_map.insert(
361 "min",
362 (
363 WindowFunctionDefinition::AggregateUDF(min_udaf()),
364 vec![arg.clone()],
365 ),
366 );
367 window_fn_map.insert(
368 "max",
369 (
370 WindowFunctionDefinition::AggregateUDF(max_udaf()),
371 vec![arg.clone()],
372 ),
373 );
374 if !is_linear {
375 // row_number, rank, lead, lag doesn't use its window frame to calculate result. Their results are calculated
376 // according to table scan order. This adds the dependency to table order. Hence do not use these functions in
377 // Partition by linear test.
378 window_fn_map.insert(
379 "row_number",
380 (
381 WindowFunctionDefinition::WindowUDF(row_number_udwf()),
382 vec![],
383 ),
384 );
385 window_fn_map.insert(
386 "rank",

Callers 1

run_window_testFunction · 0.85

Calls 15

newFunction · 0.85
AggregateUDFClass · 0.85
WindowUDFClass · 0.85
fields_with_udfFunction · 0.85
colFunction · 0.50
castFunction · 0.50
insertMethod · 0.45
lenMethod · 0.45
valuesMethod · 0.45
cloneMethod · 0.45
is_emptyMethod · 0.45
return_fieldMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…