CLICKHOUSE學習之:分佈式建表

CLICKHOUSE學習之:分佈式建表

聲明:

此篇文章涉及到一下操作:clickhouse的分佈式 建表規則以及,刪表語句等
本篇文章的clickhouse部署在4臺機器上,所以建表需要在4臺機器上創建相同的物理表,而一臺機上上有邏輯庫,所以還需要多建一張邏輯庫對應物理庫的表。邏輯表內存儲的是表結構,用於快速查詢,實際數據存儲在4臺不同機器的物理表中。

本篇文章僅介紹物理表以及邏輯表的創建規則及語句。涉及少部分其他語句在一下內容中顯示

建表規則

1、首先創建物理表,準備好建表語句

聲明clickhouse不是隻能創建string字符串字段,int對應 iInt64    數值對應Float64

 CREATE TABLE 庫名.表名_physical (
  fr String
  ad_account_id String,
  ad_account_name String,
  balance String,
  budget String,
  user_stat String,
  user_stat_desc String,
  valid_flows String,
  valid_flows_desc String,
  category String,
  is_deleted String,
  create_time String
) ENGINE = MergeTree() 
PARTITION BY ad_account_id ORDER BY (fr, ad_account_id, category) SETTINGS index_granularity = 8192

ENGINE = MergeTree() ,SETTINGS index_granularity = 8192 是固定的
PARTITION BY 分區字段    
ORDER BY (所有維度字段)

2、首先創建邏輯表,準備好建表語句

CREATE TABLE 邏輯庫名.表名(
  fr String,
  ad_account_id String,
  ad_account_name String,
  balance String,
  budget String,
  user_stat String,
  user_stat_desc String,
  valid_flows String,
  valid_flows_desc String,
  category String,
  is_deleted String,
  create_time String
) ENGINE = Distributed(mkt_ck_test, 物理庫名, 對應的物理表名, cityHash64(fr)) 

ENGINE = Distributed(mkt_ck_test, 物理庫名, 對應的物理表名, cityHash64(fr)) 規則固定

 

示例:
 

CREATE TABLE marketing_physical.fem_baidu_account_physical (
  fr String,
  ad_account_id String,
  ad_account_name String,
  balance String,
  budget String,
  user_stat String,
  user_stat_desc String,
  valid_flows String,
  valid_flows_desc String,
  category String,
  is_deleted String,
  create_time String
) ENGINE = MergeTree() 
PARTITION BY ad_account_id ORDER BY (fr, ad_account_id, category) SETTINGS index_granularity = 8192

邏輯板建表語句:
CREATE TABLE marketing.fem_baidu_account (
  fr String,
  ad_account_id String,
  ad_account_name String,
  balance String,
  budget String,
  user_stat String,
  user_stat_desc String,
  valid_flows String,
  valid_flows_desc String,
  category String,
  is_deleted String,
  create_time String
) ENGINE = Distributed(mkt_ck_test, marketing_physical, fem_baidu_account_physical, cityHash64(fr)) 

 

分別在不同的機器邏輯庫以及物理庫中創建重複上述的建表語句即可

clickhoues的命令行操作與mysql語句基本一致一下是幾個常用的命令

1.show databases;//查看數據庫
2.use 庫名;//使用數據庫
3.show tables;//展示數據庫所有表
4.show create table 表名 ;//查看錶的建表語句
5.DROP TABLE 表名;//刪除此表

以上結束

感謝觀看

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章