0
点赞
收藏
分享

微信扫一扫

ClickHouse亿点抽样展示

前程有光 2021-09-21 阅读 56

数据准备

    数据源 (点数据使用之前导入的数据120038310条,https://juejin.cn/post/6903100159484395534)

 CREATE TABLE default.points
(
    `id` UInt32,
    `Lon` Float32,
    `Lat` Float32
)
ENGINE = MergeTree()
ORDER BY (intHash64(id), Lon, Lat)
SAMPLE BY intHash64(id)
SETTINGS index_granularity = 8192
insert into points SELECT id,Lon,Lat FROM pnts

采样功能和Hash函数

SAMPLE 子句特点

    Hash函数intHash64可以用于将元素不可逆的伪随机打乱。经过测试一亿多个点得抽样性能比较满意,可以为页面提供比较满意得展示。注意事项:sample的字段必须是int类型,必须在主键或者排序中。

抽样sql,0.01为示例,可根据实际修改

SELECT id,Lon,Lat FROM points SAMPLE 0.01

增加服务端和网页

    使用Express作为服务端,请求数据并且在网页中使用Maptalks展示,本地测试
[图片上传失败...(image-4abeef-1609984875573)]


参考资料:

https://clickhouse.tech/docs/zh/sql-reference/functions/hash-functions/#md5

https://clickhouse.tech/docs/zh/sql-reference/statements/select/sample/

举报

相关推荐

0 条评论