关于ClickHouse建表 集群表 SQL

ops/2024/9/22 12:32:02/

下面将介绍一下 ClickHouse 建表SQL ,集群名 star_cluster

我这里以test 表   test_all 集群表 为演示   可以执行下面的SQL 

新建本地表

sql">DROP TABLE IF EXISTS test ON CLUSTER star_cluster;
DROP TABLE IF EXISTS test_all ON CLUSTER star_cluster;
CREATE TABLE  test ON CLUSTER star_cluster
(`id` UInt32,`value` UInt8
)
ENGINE = MergeTree
ORDER BY id;

新建集群表 test_all  

sql">CREATE TABLE test_all ON CLUSTER star_cluster AS test
ENGINE = Distributed(star_cluster, demo, test, id);

注:其中demo 为 数据库名称  

下面我们插入一些数据  验证一下

sql">INSERT INTO test_all SELECT number AS id, toUInt8(rand()) FROM numbers(10000);

上面的sql 是 生成10000条数据  我们分别去查询一下 test_all集群表的数据 和test表的数据

sql">-- 查询集群表
SELECT count() FROM test_all;   --查询本地本
SELECT count() FROM test

如果当前集群节点为2个时,那么我们查询test_all表时,总数量为10000, 在任意一台服务器上查询test本地表,则数量为5000, 在另一台节点查询test本地表数量也为5000,则说明ClickHouse正常.

下面将介绍一个预警表  字段设计如下:

字段名称

类型

含义

date

Date

预警日期

info_id

FixedString(16)

唯一uuid

warning_info_id

FixedString(16)

uuid 

type

UInt8

预警类型

location_id

UInt64

点位id

warning_num

UInt8

预警数量

capture_time

UInt32

预警抓拍时间戳

duration_time

UInt64

停留时间 秒

orgin_info_id

FixedString(16)

原始uuid

task_id

UInt64

任务id 关联表主键

detection

String

坐标 {"x”:222,”y”:33,”w”:44,”h”:44} 

image_url

String

场景大图

feature

String CODEC(NONE)

特征值  (没有用)

name

String

姓名

id_number

String

身份证

similarity

String

相似度 单位%

license_plate2

String

车牌号

plate_type_id

UInt8

车牌种类

insert_time

UInt32

写入数据时间戳

sql">建表sql:
CREATE TABLE  warning_result ON CLUSTER star_cluster
(`date` Date DEFAULT toDate(capture_time),`info_id` FixedString(16),`warning_info_id` FixedString(16),`type` UInt8,`location_id` UInt64,`warning_num` UInt8,`capture_time` UInt32,`duration_time` UInt64,`orgin_info_id`   FixedString(16),`task_id`    UInt64,
`detection` String,
`image_url` String,
`feature` String CODEC(NONE),
`name`  String,
`id_number` String,
`similarity`  String,
`license_plate2` String,
`plate_type_id` UInt8,
`insert_time` UInt32 DEFAULT toUnixTimestamp(now())
)
ENGINE = MergeTree
PARTITION BY date
ORDER BY (capture_time,info_id);#集群表
CREATE TABLE warning_result_all ON CLUSTER star_cluster AS warning_result ENGINE = Distributed(star_cluster, demo, warning_result, rand());


http://www.ppmy.cn/ops/114240.html

相关文章

解决R包依赖版本不兼容问题

ERROR: dependency ‘Matrix’ is not available for package ‘irlba’ removing ‘/root/anaconda3/envs/myview/lib/R/library/irlba’ ERROR: dependency ‘Matrix’ is not available for package ‘N2R’ removing ‘/root/anaconda3/envs/myview/lib/R/library/N2R’ ER…

有关shell指令练习2

写一个shell脚本,将以下内容放到脚本中 在家目录下创建目录文件,dir dir下创建dir1和dir2 把当前目录下的所有文件拷贝到dir1中, 把当前目录下的所有脚本文件拷贝到dir2中 把dir2打包并压缩为dir2.tar.xz 再把dir2.tar.xz移动到dir1中 …

苍穹外卖学习笔记(五)

文章目录 二.新增菜品1.图片上传2.具体新增菜品 二.新增菜品 1.图片上传 这里采用了阿里云oss对象存储服务 application.yml alioss:endpoint: ${sky.alioss.endpoint}access-key-id: ${sky.alioss.access-key-id}access-key-secret: ${sky.alioss.access-key-secret}bucket…

[Admin] Advanced SF Reports Dashboards

Reports 1. 条件格式 参考:https://trailhead.salesforce.com/content/learn/projects/create-reports-and-dashboards-for-sales-and-marketing-managers/group-and-categorize-your-data 2. Summary Formula 例子:计算赢单比率 (WON:SUM/CLOSED:SUM)…

vue循环渲染动态展示内容案例(“更多”按钮功能)

当我们在网页浏览时,常常会有以下情况:要展示的内容太多,但展示空间有限,比如我们要在页面的一部分空间中展示较多的内容放不下,通常会有两种解决方式:分页,“更多”按钮。 今天我们的案例用于…

【Webpack--007】处理其他资源--视频音频

🤓😍Sam9029的CSDN博客主页:Sam9029的博客_CSDN博客-前端领域博主 🐱‍🐉若此文你认为写的不错,不要吝啬你的赞扬,求收藏,求评论,求一个大大的赞!👍* &#x…

【图虫创意-注册安全分析报告-无验证方式导致安全隐患】

前言 由于网站注册入口容易被黑客攻击,存在如下安全问题: 1. 暴力破解密码,造成用户信息泄露 2. 短信盗刷的安全问题,影响业务及导致用户投诉 3. 带来经济损失,尤其是后付费客户,风险巨大,造…

如何在ubuntu中安装code-server搭建一个在线编程环境

code-server 是一个开源项目,它允许你在浏览器中运行 Visual Studio Code。通过 code-server,你可以远程访问一个运行 Visual Studio Code 的服务器,并在任何设备上使用浏览器来编辑代码。这使得你可以在轻量级设备上(如平板电脑或…