You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

初始化空聚合时sumMerge与maxMerge返回0而非NULL的疑问

ClickHouse聚合状态合并疑问:sumMerge/maxMerge返回0而非NULL?

我执行了以下ClickHouse查询:

SELECT 
  uniqMerge (uniq_state) as uniq_merge  -- 0: ok
, sumMerge  (sum_state)  as sum_merge   -- 0: why not NULL?
, maxMerge  (max_state)  as max_merge   -- 0: why not NULL?
FROM 
(
  SELECT 
    initializeAggregation ('uniqStateIf', '', 0) as uniq_state
  , initializeAggregation ('sumStateIf',   0, 0) as sum_state
  , initializeAggregation ('maxStateIf',   0, 0) as max_state
)

查询结果:

uniq_mergesum_mergemax_merge
000

我不清楚为什么sumMerge和maxMerge返回0而非NULL,这属于预期行为吗?


更新:与基础列可空性相关的测试结果

我做了进一步测试,发现结果似乎和基础列的可空性有关:

SELECT 
  sumMerge (sum_state_null)  as sum_merge_null
, sumMerge (sum_state_0)     as sum_merge_0
FROM
(
  SELECT 
    sumState (cast (null as Nullable(UInt8)))   as sum_state_null
  , sumState (0)                                as sum_state_0
/*  
    UNION ALL
  SELECT 
    sumState (cast (1 as Nullable(UInt8)))
  , sumState (0)
*/  
)

查询结果:

sum_merge_nullsum_merge_0
NULL0

内容的提问来源于stack exchange,提问作者Mark Barinstein

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 15:06:08