```
SELECT *
FROM xrollup

Query id: e702f6fe-8595-4a9f-aeff-ea65e2045801

┌─metric─┬──────────b─┬─v─┐
│      2 │ 2018-01-01 │ 1 │
│      2 │ 2018-02-02 │ 1 │
└────────┴────────────┴───┘
┌─metric─┬──────────b─┬─v─┐
│      1 │ 2018-01-01 │ 1 │
│      1 │ 2018-01-02 │ 1 │
│      1 │ 2018-02-01 │ 1 │
│      1 │ 2017-03-01 │ 1 │
└────────┴────────────┴───┘

6 rows in set. Elapsed: 0.004 sec.
```

`WITH TOTALS + WITH FILL:`

```
SELECT
    b,
    sum(v)
FROM xrollup
GROUP BY b
    WITH TOTALS
ORDER BY b DESC WITH FILL
LIMIT 5

Query id: ae21086d-eb89-4b73-b9be-7baa4c0cee27

┌──────────b─┬─sum(v)─┐
│ 2018-02-02 │      1 │
│ 2018-02-01 │      1 │
│ 2018-01-31 │      0 │
│ 2018-01-30 │      0 │
│ 2018-01-29 │      0 │
└────────────┴────────┘

Totals:
┌──────────b─┬─sum(v)─┐
│ 1970-01-01 │      6 │
└────────────┴────────┘

5 rows in set. Elapsed: 0.003 sec.
```

`WITH TOTALS + WITH FILL FROM:`

```
SELECT
    b,
    sum(v)
FROM xrollup
GROUP BY b
    WITH TOTALS
ORDER BY b DESC WITH FILL FROM today()
LIMIT 5

Query id: cbf3d659-cf10-4b3b-800f-a5af11fc9faa

┌──────────b─┬─sum(v)─┐
│ 2021-02-18 │      0 │
│ 2021-02-17 │      0 │
│ 2021-02-16 │      0 │
│ 2021-02-15 │      0 │
│ 2021-02-14 │      0 │
└────────────┴────────┘

Totals:
┌──────────b─┬─sum(v)─┐
│ 2021-02-18 │      0 │
└────────────┴────────┘

5 rows in set. Elapsed: 0.006 sec.
```

if (fill_to.isNull() || less(current_value, fill_to, filling_row.getDirection(i)))
                next_row[i] = current_value;
            else
                next_row[i] = fill_to;
        }
        
        
        if (should_insert_first && filling_row < next_row)
            insertFromFillingRow(res_fill_columns, res_other_columns, filling_row);
        
        while (filling_row.next(next_row))
            insertFromFillingRow(res_fill_columns, res_other_columns, filling_row);
        copyRowFromColumns(res_fill_columns, old_fill_columns, row_ind);
        copyRowFromColumns(res_other_columns, old_other_columns, row_ind);
    }
    setResultColumns(chunk, res_fill_columns, res_other_columns);
}
void FillingTransform::setResultColumns(Chunk & chunk, MutableColumns & fill_columns, MutableColumns & other_columns) const
{
    MutableColumns result_columns(fill_columns.size() + other_columns.size());
    
    size_t num_rows = fill_columns[0]->size();
    for (size_t i = 0; i < fill_columns.size(); ++i)
        result_columns[fill_column_positions[i]] = std::move(fill_columns[i]);
    for (size_t i = 0; i < other_columns.size(); ++i)
        result_columns[other_column_positions[i]] = std::move(other_columns[i]);
    chunk.setColumns(std::move(result_columns), num_rows);
}
}