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)
| 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. |
| 92 | fn 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 | } |
no test coverage detected
searching dependent graphs…