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 likeselect arrayMap(x -> 2 * x, []);failed because function inside lambda cannot work with typeNothing, now such queries return empty array with typeArray(Nothing). Also add support for arrays of nullable types in functions like arrayFilter/arrayFill. Previously, queries likeselect 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).
Why it matters
This feature solves issues where functions failed when processing empty arrays or arrays with nullable elements due to inability to handle theNothing 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 likeselect arrayMap(x -> 2 * x, []); or select arrayFilter(x -> x % 2, [1, NULL]); will now work without modification, returning valid results with proper typed arrays.