'How do I update a Clickhouse table to be able to sample from it?

I'm trying to sample rows from a clickhouse table. Below you can find the table definition

CREATE TABLE trades
(
    `id` UInt32,
    `ticker_id` UUID,
    `epoch` DateTime,
    `nanoseconds` UInt32,
    `amount` Float64,
    `cost` Float64,
    `price` Float64,
    `side` UInt8
)
ENGINE = MergeTree
PARTITION BY (ticker_id, toStartOfInterval(epoch, toIntervalHour(1)))
ORDER BY (ticker_id, epoch)

SETTINGS index_granularity = 8192

I want to sample 10000 rows from the table

SELECT * FROM trades SAMPLE 10000 ;

But when I'm trying to run the query above I'm getting the following error:

DB::Exception: Illegal SAMPLE: table doesn't support sampling

I want to ALTER the table in order to be able to sample from it, but at the same time I want to make sure that I won't corrupt the data while altering the table. The table has about 1 billion rows.

What would be a good way to ALTER the table while making sure the data won't get corrupted?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source