v.20.1Improvement

Fix Column Already Exists Error with FINAL and SAMPLE in ClickHouse

Fix error Column ... already exists while using FINAL and SAMPLE together, e.g. select count() from table final sample 1/2. Fixes #5186. #7907 (Nikolai Kochetov)
Fixes the error Column ... already exists that occurs when using FINAL and SAMPLE together in queries, for example, select count() from table final sample 1/2.

Why it matters

This fix addresses the conflict that caused duplicate column errors when combining the FINAL modifier with SAMPLE clauses in queries. It ensures that users can safely perform sampling on finalized data parts without encountering errors, improving query reliability and usability.

How to use it

Simply use the FINAL modifier together with the SAMPLE clause in your query as usual. For example:

SELECT count() FROM table FINAL SAMPLE 1/2


This fix removes the previous limitation where such queries would fail due to column duplication errors.