【问题标题】:Table TTL on SummingMergeTreeSummingMergeTree 上的表 TTL
【发布时间】:2020-04-05 12:48:09
【问题描述】:

我有一张桌子:

CREATE TABLE metric (                                                                                           
    cid UInt32,
    sid UInt32,
    sub String,
    cc UInt32,
    ic UInt32,
    cmc UInt32,
    acc UInt32,
    ts_update DATETIME DEFAULT now()
) ENGINE = SummingMergeTree((cc, ic, cmc, acc)) 
PARTITION BY (cid, sid, sub) 
ORDER BY tuple() 
TTL ts_update + INTERVAL 5 MINUTE;

我在打电话

INSERT INTO metric (cid, sid, sub, cc, ic, cmc, acc, ts_update) 
VALUES (1000, 2000, 'test', 10, 1, 30, 40, now())

每 10 秒一次,持续 5 分钟 (TTL)。

在 5 分钟结束时,整行将被删除,因为 ts_update 字段在每次插入求和合并树时都不会更新。

我要做的就是,如果在 5 分钟内没有将行插入分区 (cid, sid, sub),则删除该行,但如果进行了任何插入,请将 TTL 更新为新的 ts_update + 5 分钟。

我怎样才能做到这一点?

【问题讨论】:

  • 您能否尝试将 ts_update 声明为 Int32 DEFAULT 0,TTL 声明为 TTL toDateTime(ts_update) + INTERVAL 5 MINUTE 并且在 INSERT 中总是通过 1 而不是 now()?
  • 创建表语句失败:Code: 450. DB::Exception: Received from clickhouse-server:9000. DB::Exception: TTL expression should use at least one Date or DateTime column. 当我按照@vladimir 所说的进行操作时

标签: clickhouse


【解决方案1】:
CREATE TABLE metric (                                                                                           
    cid UInt32,
    sid UInt32,
    sub String,
    cc  SimpleAggregateFunction(sum, UInt64),
    ic  SimpleAggregateFunction(sum, UInt64),
    cmc SimpleAggregateFunction(sum, UInt64),
    acc SimpleAggregateFunction(sum, UInt64),
    ts_update SimpleAggregateFunction(max, DateTime) DEFAULT now()
) ENGINE = AggregatingMergeTree()
ORDER BY (cid, sid, sub)
TTL ts_update + INTERVAL 5 MINUTE;

虽然它不会起作用。 TTL 在 SUMS 计算之前删除旧行。没有解决办法。

【讨论】:

  • 我想要实现的事情实际上应该是微不足道的。有趣的是没有解决方案。还是谢谢
猜你喜欢
  • 2018-12-06
  • 1970-01-01
  • 1970-01-01
  • 2019-09-16
  • 2017-01-30
  • 1970-01-01
  • 2017-05-23
  • 2019-05-11
  • 1970-01-01
相关资源
最近更新 更多