
**Describe the unexpected behaviour**

Current implementation of arrayCompact does not behave as other higher-order functions: it accepts lambda function as its first argument, but then it compacts array returned by lambda, not original array (see below for example).

**How to reproduce**
* Which ClickHouse server version to use

Any modern

* Queries to run that lead to unexpected result

select arrayCompact(x -> x.2 , groupArray(tuple(number, intDiv(number, 3) % 3))) from numbers(10);

**Expected behavior**

arrayCompact shall follow normal higher-order functons way and use results of lambda function ([0,0,0,1,1,1,2,2,2,0]) to compact original array ([(0,0),(1,0),(2,0),(3,1),(4,1),(5,1),(6,2),(7,2),(8,2),(9,0)]) into [(0,0),(3,1),(6,2),(9,0)]

**Additional context**

Use case: timeseries (time, value) with lots of repeated values that shall be compacted into (first time, value) when value repeats.

static bool needExpression() { return false; }
    static bool needOneArray() { return false; }
    static DataTypePtr getReturnType(const DataTypePtr & nested_type, const DataTypePtr &)
    {
        return std::make_shared<DataTypeArray>(nested_type);
    }
    template <typename T>
    static bool executeType(const ColumnPtr & mapped, const ColumnArray & array, ColumnPtr & res_ptr)
    {
        using ColVecType = ColumnVectorOrDecimal<T>;
        const ColVecType * src_values_column = checkAndGetColumn<ColVecType>(mapped.get());
        if (!src_values_column)
            return false;
        const IColumn::Offsets & src_offsets = array.getOffsets();
        const typename ColVecType::Container & src_values = src_values_column->getData();
        typename ColVecType::MutablePtr res_values_column;
        if constexpr (is_decimal<T>)
            res_values_column = ColVecType::create(src_values.size(), src_values_column->getScale());
        else
            res_values_column = ColVecType::create(src_values.size());
        typename ColVecType::Container & res_values = res_values_column->getData();
        size_t src_offsets_size = src_offsets.size();
        auto res_offsets_column = ColumnArray::ColumnOffsets::create(src_offsets_size);
        IColumn::Offsets & res_offsets = res_offsets_column->getData();
        size_t res_pos = 0;
        size_t src_pos = 0;
        for (size_t i = 0; i < src_offsets_size; ++i)