Prevent relation builder from generating NULL for array of ranges

It's updated version of pull-request #9179 and partial fix of issue #9171. Additionally I've added test coverage of the array handler.