如何更新Clickhouse表以从中进行采样?

发布于 2025-01-29 14:24:56 字数 673 浏览 2 评论 0原文

我正在尝试从Clickhouse表中采样行。 下面您可以找到表定义

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

我想从表中采样10000行,

SELECT * FROM trades SAMPLE 10000 ;

但是当我尝试运行上面的查询时,我会收到以下错误:

db ::异常:非法示例:表不支持采样

我想alter为了能够从中取样,但与此同时,我想确保在更改该数据时不会损坏数据桌子。 桌子有大约10亿行。

在确保数据不会损坏的同时更改桌子的好方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁吢 2025-02-05 14:24:56

您可以尝试:

ALTER TABLE trades MODIFY SAMPLE BY toUnixTimestamp(toIntervalHour(epoch));

you can try:

ALTER TABLE trades MODIFY SAMPLE BY toUnixTimestamp(toIntervalHour(epoch));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文