v.22.6Improvement

Add Default Implementation for Nothing in Functions to Handle Nullable Types and Empty Arrays

Add default implementation for Nothing in functions. Now most of the functions will return column with type Nothing in case one of it's arguments is Nothing. It also solves problem with functions like arrayMap/arrayFilter and similar when they have empty array as an argument. Previously queries like select arrayMap(x -> 2 * x, []); failed because function inside lambda cannot work with type Nothing, now such queries return empty array with type Array(Nothing). Also add support for arrays of nullable types in functions like arrayFilter/arrayFill. Previously, queries like select arrayFilter(x -> x % 2, [1, NULL]) failed, now they work (if the result of lambda is NULL, then this value won't be included in the result). Closes #37000. #37048 (Kruglov Pavel).
Functions in ClickHouse now have a default implementation for the Nothing type, allowing them to return columns with type Nothing when any argument is Nothing. This improves behavior of functions like arrayMap, arrayFilter, and arrayFill when dealing with empty arrays or arrays containing nullable types.

Why it matters

This feature solves issues where functions failed when processing empty arrays or arrays with nullable elements due to inability to handle the Nothing type. It ensures that such functions gracefully return appropriately typed empty arrays (e.g., Array(Nothing)) or filter out NULL values in lambdas, thereby improving query stability and usability.

How to use it

Users get this feature automatically after upgrading to the version including this change. Queries like select arrayMap(x -> 2 * x, []); or select arrayFilter(x -> x % 2, [1, NULL]); will now work without modification, returning valid results with proper typed arrays.