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

Function spark_array_repeat

datafusion/spark/src/function/array/repeat.rs:92–121  ·  view source on GitHub ↗

This is a Spark-specific wrapper around DataFusion's array_repeat that returns NULL if the count argument is NULL (Spark behavior), whereas DataFusion's array_repeat ignores NULLs.

(args: ScalarFunctionArgs)

Source from the content-addressed store, hash-verified

90/// This is a Spark-specific wrapper around DataFusion's array_repeat that returns NULL
91/// if the count argument is NULL (Spark behavior), whereas DataFusion's array_repeat ignores NULLs.
92fn spark_array_repeat(args: ScalarFunctionArgs) -> Result<ColumnarValue> {
93 let ScalarFunctionArgs {
94 args: arg_values,
95 arg_fields,
96 number_rows,
97 return_field,
98 config_options,
99 } = args;
100 let return_type = return_field.data_type().clone();
101
102 // A NULL element should be repeated into the array, not cause a NULL result.
103 let null_mask = compute_null_mask(&arg_values[1..]);
104
105 // If count is null then return NULL immediately
106 if matches!(null_mask, NullMaskResolution::ReturnNull) {
107 return Ok(ColumnarValue::Scalar(ScalarValue::try_from(return_type)?));
108 }
109
110 let array_repeat_func = ArrayRepeat::new();
111 let func_args = ScalarFunctionArgs {
112 args: arg_values,
113 arg_fields,
114 number_rows,
115 return_field,
116 config_options,
117 };
118 let result = array_repeat_func.invoke_with_args(func_args)?;
119
120 apply_null_mask(result, null_mask, &return_type)
121}

Callers 1

invoke_with_argsMethod · 0.85

Calls 6

compute_null_maskFunction · 0.85
newFunction · 0.85
apply_null_maskFunction · 0.85
cloneMethod · 0.45
data_typeMethod · 0.45
invoke_with_argsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…