I would like to convert an integer value, representing a bitmask, to an array holding corresponding values. For example, the value 3 should be converted to [1, 2] (I am happy with any conversion, as long as it's an array and it's unique and easy to query). As much as possible I'd like to avoid using a custom UDF.
I am able to use the following (example is for the constant input of 7):
select filter(array(1 * bit_get(7, 0), 2 * bit_get(7, 1), 3 * bit_get(7, 2)), x -> x > 0);
However, this is rather cumbersome and hard to maintain when the number of bits grow.
Is there a better way to achieve this goal, without use of UDFs?