參考鏈接:ClickHouse官方檔案
存在節點目錄:CK集群某個節點下的 比如:/user/test_user/ 目錄
使用方式說明:sycn_ck.sh是一個可執行腳本檔案,只執行此腳本且在腳本后面添加上SQL即可;
特色功能說明:
- 支持同樣的SQL在CK所有節點同步執行;無法單獨在指定的節點上執行;
- 支持節點執行分行顯示;采用顏色高亮分割;
- 支持在CK集群顯示執行完成進度,以1/6方式顯示;
腳本示例:
#節點呼叫腳本,即每個節點都執行同樣的指令
#!/bin/bash
pcount=$#
if((pcount==0));then
tput setaf 1
tput bold
echo no args;
tput setaf 7
exit;
fi
params=$@
curr_job=1
total_jobs=6
for ip in host_ip1 host_ip2 host_ip3 host_ip4 host_ip5 host_ip6
do
echo $(tput setaf 3)"--------[ 在此節點 $ip 開始執行 ]--------"$(tput sgr0)
clickhouse client -m -n -h $ip --port 9000 -u user_name --password pass_word --query "$params"
echo $(tput setaf 2; tput bold)"--------[ 在此節點 $ip 完成執行, 完成進度 $curr_job/$total_jobs ]--------"$(tput sgr0)
curr_job=$[$curr_job+1]
done
2、分發工具運行示例
提示:如果想要查詢效果好一點,建議在SQL尾部添加上 format Pretty
-- 查詢庫
./sycn_ck.sh "show databases;"
-- 查詢有哪些表
./sycn_ck.sh "use musicad_superset; show tables;"
-- 查詢表
./sycn_ck.sh "use music_ad_income; select fdate, s_date, sum(total_income) as total_income from dws_datatalk_splash_ad_res_site_all where fdate = 20211208 and s_date = 20211208 group by fdate, s_date limit 1"
-- 創建local表
./sycn_ck.sh "use musicad_superset; CREATE TABLE city_local (fdate Int64,city_code Int32,city_name String,total_cnt Int64) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/city_local', '{replica}')
PARTITION BY fdate ORDER BY (fdate, city_code, city_name) SETTINGS index_granularity = 8192, storage_policy = 'ssd_to_hdd'"
-- 創建all表
./sycn_ck.sh "use musicad_superset; CREATE TABLE IF NOT EXISTS city_all AS city_local ENGINE = Distributed(musicad_ck_cluster, musicad_superset, city_local, rand());"
-- 查詢all表資料
./sycn_ck.sh "use musicad_superset; select * from city_all;"
-- 向all表插入資料
./sycn_ck.sh "use musicad_superset; insert into city_all (fdate, city_code, city_name, total_cnt) values (20211208, 100, 'guangzhou', 1000);"
-- 查詢all表資料
./sycn_ck.sh "use musicad_superset; select * from city_all;"
-- 洗掉表
./sycn_ck.sh "use musicad_superset; drop table city_all;"
./sycn_ck.sh "use musicad_superset; drop table city_local;"
tput 命令列使用說明
什么是 tput?
tput 命令將通過 terminfo 資料庫對您的終端會話進行初始化和操作,通過使用 tput,您可以更改幾項終端功能,如移動或更改游標、更改文本屬性,以及清除終端螢屏的特定區域,
什么是 terminfo 資料庫?
UNIX 系統上的 terminfo 資料庫用于定義終端和列印機的屬性及功能,包括各設備(例如,終端和列印機)的行數和列數以及要發送至該設備的文本的屬性,UNIX 中的幾個常用程式都依賴 terminfo 資料庫提供這些屬性以及許多其他內容,其中包括 vi 和 emacs 編輯器以及 curses 和 man 程式,
命令列使用說明:
1.文本屬性
tput Color Capabilities:
tput setab [0-7] – Set a background color using ANSI escape
tput setb [0-7] – Set a background color
tput setaf [0-7] – Set a foreground color using ANSI escape
tput setf [0-7] – Set a foreground color
Color Code for tput:
0 – Black
1 – Red
2 – Green
3 – Yellow
4 – Blue
5 – Magenta
6 – Cyan
7 – White
tput Text Mode Capabilities:
tput bold – Set bold mode
tput dim – turn on half-bright mode
tput smul – begin underline mode
tput rmul – exit underline mode
tput rev – Turn on reverse mode
tput smso – Enter standout mode (bold on rxvt)
tput rmso – Exit standout mode
tput sgr0 – Turn off all attributes
例子:使輸出的字串有顏色,底色,加粗
#!/bin/bash
printf $(tput setaf 2; tput bold)'color show\n\n'$(tput sgr0)
for((i=0; i<=7; i++)); do
echo $(tput setaf $i)"show me the money"$(tput sgr0)
done
printf '\n'$(tput setaf 2; tput setab 0; tput bold)'background color show'$(tput sgr0)'\n\n'
for((i=0,j=7; i<=7; i++,j--)); do
echo $(tput setaf $i; tput setab $j; tput bold)"show me the money"$(tput sgr0)
done
exit 0
運行效果截圖:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/379439.html
標籤:其他
上一篇:使用 SpringBoot+MybatisPlus實作網頁版閑魚
下一篇:Java實作關系型資料庫工具類JdbcUtils系列四:PreparedStatement執行sql陳述句實作查詢
