问题描述
当我查询一个物化视图时,我得到的数据多于它所基于的本地表。 有什么问题吗?
查询 mv search_uv_minute_level:
toYYYYMMDD(stime) AS dt,uniqExactMerge(imp_uv) AS imp_uv,uniqExactMerge(clk_uv) AS clk_uv,uniqExactMerge(imp_count) AS imp_count,sumMerge(clk_count) AS clk_count
FROM search_uv_minute_level
WHERE (toYYYYMMDD(stime) = 20210623) AND (toYYYYMMDDhhmmss(stime) >= 20210623150500) AND (toYYYYMMDDhhmmss(stime) <= 20210623150800)
GROUP BY toYYYYMMDD(stime)
┌───────dt─┬─imp_uv─┬─clk_uv─┬─imp_count─┬─clk_count─┐
│ 20210623 │ 114108 │ 66320 │ 179590 │ 110870 │
└──────────┴────────┴────────┴───────────┴───────────┘
查询本地表search_action_dwd:
SELECT
toYYYYMMDD(dt) AS t,uniqExact(IF(type = 'IMP',uid,NULL)) AS uv,uniqExact(IF(type = 'CLK',NULL)) AS clk_uv,e,NULL)) AS imp,SUM(IF(type = 'CLK',1,0)) AS clk
FROM search_action_dwd
WHERE (toYYYYMMDD(dt) = 20210623) AND (toYYYYMMDDhhmmss(dt) >= 20210623150500) AND (toYYYYMMDDhhmmss(dt) <= 20210623150800)
GROUP BY t
┌────────t─┬────uv─┬─clk_uv─┬────imp─┬───clk─┐
│ 20210623 │ 92755 │ 54265 │ 141838 │ 87337 │
└──────────┴───────┴────────┴────────┴───────┘
MV 定义:
CREATE MATERIALIZED VIEW qiso_bi.search_uv_minute_level (`stime` DateTime('Asia/Shanghai'),`imp_uv` AggregateFunction(uniqExact,String),`clk_uv` AggregateFunction(uniqExact,`imp_count` AggregateFunction(uniqExact,`clk_count` AggregateFunction(sum,UInt8)) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{cluster}/{shard}/search_uv_minute_level','{replica}') PARTITION BY toYYYYMMDD(stime) ORDER BY toYYYYMMDDhhmmss(stime) SETTINGS index_granularity = 8192 AS SELECT toStartOfMinute(dt) AS stime,uniqExactState(IF(type = 'IMP',NULL)) AS imp_uv,uniqExactState(IF(type = 'CLK',NULL)) AS imp_count,sumState(IF(type = 'CLK',0)) AS clk_count FROM search_action_dwd WHERE toYYYYMMDD(dt) >= 20210623 GROUP BY toStartOfMinute(dt)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)