最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Clickhouse數(shù)據(jù)表、數(shù)據(jù)分區(qū)partition的基本操作代碼

 更新時間:2023年11月20日 10:22:56   作者:Bulut0907  
clickhouse的分區(qū)是指將數(shù)據(jù)按照分區(qū)鍵進(jìn)行劃分,每個分區(qū)可以包含多個數(shù)據(jù)塊,這篇文章主要介紹了Clickhouse數(shù)據(jù)表、數(shù)據(jù)分區(qū)partition的基本操作代碼,需要的朋友可以參考下

1. 數(shù)據(jù)表的基本操作

只有MergeTree系列、Merge、Distributed表引擎支持alter操作

1.1 添加字段

clickhouse1 :)
clickhouse1 :) create table alter_table_test(
:-] id UInt32,
:-] name String,
:-] city String
:-] ) engine = MergeTree()
:-] order by id;
clickhouse1 :) 
clickhouse1 :) alter table alter_table_test add column if not exists score Float32 default 8.8 after city;
clickhouse1 :) 

1.2 修改字段數(shù)據(jù)類型、添加或修改字段默認(rèn)值

clickhouse1 :) 
clickhouse1 :) alter table alter_table_test modify column if exists score Float64 default 0.0;
clickhouse1 :) 

修改前后的字段數(shù)據(jù)類型需要兼容

1.3 添加或修改字段備注

clickhouse1 :) 
clickhouse1 :) alter table alter_table_test comment column if exists score '分?jǐn)?shù)';
clickhouse1 :)

1.4 刪除字段

clickhouse1 :) 
clickhouse1 :) alter table alter_table_test drop column if exists score;
clickhouse1 :) 

1.5 重命名或移動數(shù)據(jù)表

clickhouse1 :) 
clickhouse1 :) rename table default.alter_table_test to default.alter_table_rename_test;
clickhouse1 :) 
  • 多個db.tb to db.tb用逗號分隔
  • 如果源表與目標(biāo)表數(shù)據(jù)庫不一樣,則表示移動數(shù)據(jù)表, 但數(shù)據(jù)表的移動只能在同一服務(wù)器
  • 支持on cluster cluster_name操作

1.6 清空數(shù)據(jù)表

clickhouse1 :) 
clickhouse1 :) truncate table if exists default.alter_table_rename_test;
clickhouse1 :) 

支持on cluster cluster_name操作

1.7 insert數(shù)據(jù)

2. 數(shù)據(jù)分區(qū)partition的基本操作

測試表和測試數(shù)據(jù)的準(zhǔn)備

clickhouse1 :) 
clickhouse1 :) create table partition_table_test(
:-] id UInt32,
:-] name String,
:-] city String
:-] ) engine = MergeTree()
:-] order by id
:-] partition by city;
clickhouse1 :) 
clickhouse1 :) insert into partition_table_test(id, name, city) values(1, 'name1', 'Beijing');
clickhouse1 :) insert into partition_table_test(id, name, city) values(2, 'name2', 'Shanghai');
clickhouse1 :) 
clickhouse1 :) create table partition_table_test2(
:-] id UInt32,
:-] name String,
:-] city String
:-] ) engine = ReplacingMergeTree()
:-] order by id
:-] partition by city;
clickhouse1 :) 

2.1 查詢數(shù)據(jù)表partition相關(guān)信息

clickhouse1 :) 
clickhouse1 :) select database, table, partition, partition_id, name, path from system.parts where database = 'default' and table = 'partition_table_test';
┌─database─┬─table────────────────┬─partition─┬─partition_id─────────────────────┬─name───────────────────────────────────┬─path────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ default  │ partition_table_test │ Shanghai  │ 6a9748c898bf80cb661db240706867aa │ 6a9748c898bf80cb661db240706867aa_2_2_0 │ /root/clickhouse/store/9eb/9ebd4336-b065-48ac-9ebd-4336b06588ac/6a9748c898bf80cb661db240706867aa_2_2_0/ │
│ default  │ partition_table_test │ Beijing   │ 8d2db6c332407299b732139fd8a261c0 │ 8d2db6c332407299b732139fd8a261c0_1_1_0 │ /root/clickhouse/store/9eb/9ebd4336-b065-48ac-9ebd-4336b06588ac/8d2db6c332407299b732139fd8a261c0_1_1_0/ │
└──────────┴──────────────────────┴───────────┴──────────────────────────────────┴────────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────┘
clickhouse1 :) 

一個partition_id下面存在多個name

2.2 刪除partition

clickhouse1 :) 
clickhouse1 :) alter table partition_table_test drop partition 'Beijing'
:-] ;
clickhouse1 :) 
clickhouse1 :) select * from partition_table_test;
┌─id─┬─name──┬─city─────┐
│  2 │ name2 │ Shanghai │
└────┴───────┴──────────┘
clickhouse1 :)

上面我們刪除了城市為Beijing的partition,然后再通過insert插入新的數(shù)據(jù),就間接實現(xiàn)了數(shù)據(jù)更新

2.3 復(fù)制partition

clickhouse1 :) 
clickhouse1 :) alter table partition_table_test2 replace partition 'Shanghai' from partition_table_test;
clickhouse1 :) 
clickhouse1 :) select * from partition_table_test2;
┌─id─┬─name──┬─city─────┐
│  2 │ name2 │ Shanghai │
└────┴───────┴──────────┘
clickhouse1 :) 
  • 將A表的數(shù)據(jù)partition,復(fù)制到B表的條件:

    兩張表字段結(jié)構(gòu)完全相同

    兩張表partition by、order by一樣

  • 會刪除目標(biāo)表partition_table_test2原來的城市Shanghai partition

2.4 將partition中某一列的數(shù)據(jù)變?yōu)槟J(rèn)值

clickhouse1 :)
clickhouse1 :) alter table partition_table_test clear column name in partition 'Shanghai';
clickhouse1 :)
clickhouse1 :) select * from partition_table_test;
┌─id─┬─name─┬─city─────┐
│  2 │      │ Shanghai │
└────┴──────┴──────────┘
clickhouse1 :) 
  • 變更字段不能為primary key、order by、partition by定義的字段
  • 如果該字段未聲明默認(rèn)值,則以字段數(shù)據(jù)類型的默認(rèn)值為準(zhǔn)

2.5 partition的卸載和裝載

clickhouse1 :)
clickhouse1 :) alter table partition_table_test detach partition 'Shanghai';
clickhouse1 :) 
clickhouse1 :) select * from partition_table_test;
SELECT *
FROM partition_table_test
Query id: 45460933-7b2e-4389-a056-85d3d75184a8
Ok.
0 rows in set. Elapsed: 0.005 sec. 
clickhouse1 :) 
clickhouse1 :) alter table partition_table_test attach partition 'Shanghai';
clickhouse1 :) 
clickhouse1 :) select * from partition_table_test;
┌─id─┬─name─┬─city─────┐
│  2 │      │ Shanghai │
└────┴──────┴──────────┘
clickhouse1 :) 
  • detach后,該分區(qū)目錄被移動到數(shù)據(jù)表目錄的detached目錄下
  • clickhouse除了能對detached目錄下的分區(qū)目錄執(zhí)行attach命令, 不能執(zhí)行其它操作
  • attach則將detached目錄下的分區(qū)目錄重新移回去

到此這篇關(guān)于Clickhouse數(shù)據(jù)表、數(shù)據(jù)分區(qū)partition的基本操作的文章就介紹到這了,更多相關(guān)Clickhouse 數(shù)據(jù)分區(qū)partition內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 數(shù)據(jù)庫索引并不是萬能藥

    數(shù)據(jù)庫索引并不是萬能藥

    幾乎所有的業(yè)務(wù)項目都會涉及數(shù)據(jù)存儲,今天,我們就以MySQL為例來深入理解下索引的原理,以及相關(guān)誤區(qū),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • SQL中過濾條件放on和where中的區(qū)別詳解

    SQL中過濾條件放on和where中的區(qū)別詳解

    這篇文章主要給大家介紹了關(guān)于SQL中過濾條件放on和where中的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧
    2019-01-01
  • Dbeaver做數(shù)據(jù)遷移的詳細(xì)過程記錄

    Dbeaver做數(shù)據(jù)遷移的詳細(xì)過程記錄

    DBeaver是一款跨平臺的通用數(shù)據(jù)庫開源管理工具,支持 MySQL,PostgreSQL,Oracle,DB2,MSSQL,Sybase,Mimer,HSQLDB,Derby以及其他兼容JDBC的數(shù)據(jù)庫,下面這篇文章主要給大家介紹了關(guān)于Dbeaver做數(shù)據(jù)遷移的詳細(xì)過程,需要的朋友可以參考下
    2023-05-05
  • 淺談數(shù)據(jù)庫緩存最終一致性的四種方案

    淺談數(shù)據(jù)庫緩存最終一致性的四種方案

    緩存是軟件開發(fā)中一個非常有用的概念,數(shù)據(jù)庫緩存更是在項目中必然會遇到的場景,緩存一致性的保證,更是在面試中被反復(fù)問到。下面我們就一起來了解一下
    2021-04-04
  • Hive日期格式轉(zhuǎn)換方法總結(jié)

    Hive日期格式轉(zhuǎn)換方法總結(jié)

    這篇文章主要為大家介紹了Hive日期格式轉(zhuǎn)換方法總結(jié),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06
  • SAP技巧之修改自帶搜索幫助為自定數(shù)據(jù)集

    SAP技巧之修改自帶搜索幫助為自定數(shù)據(jù)集

    這篇文章主要為大家介紹了SAP技巧之修改自帶搜索幫助為自定數(shù)據(jù)集實現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • 數(shù)據(jù)庫測試 實用技巧及測試方法

    數(shù)據(jù)庫測試 實用技巧及測試方法

    軟件應(yīng)用程序已經(jīng)離不開數(shù)據(jù)庫。無論是在Web、桌面應(yīng)用、客戶端服務(wù)器、企業(yè)和個人業(yè)務(wù),都需要數(shù)據(jù)庫在后端操作。
    2011-07-07
  • SQLite不支持Right Join的解決辦法GROUP BY

    SQLite不支持Right Join的解決辦法GROUP BY

    sqlite真的不錯,就是不支持right join,所以我們用下面的方法解決
    2008-06-06
  • postgres 數(shù)據(jù)庫中的數(shù)據(jù)轉(zhuǎn)換

    postgres 數(shù)據(jù)庫中的數(shù)據(jù)轉(zhuǎn)換

    postgres8.3以后,字段數(shù)據(jù)之間的默認(rèn)轉(zhuǎn)換取消了。如果需要進(jìn)行數(shù)據(jù)變換的話,在postgres數(shù)據(jù)庫中,我們可以用"::"來進(jìn)行字段數(shù)據(jù)的類型轉(zhuǎn)換。
    2009-07-07
  • 銀河麒麟V10安裝達(dá)夢8數(shù)據(jù)庫詳細(xì)操作過程及避坑

    銀河麒麟V10安裝達(dá)夢8數(shù)據(jù)庫詳細(xì)操作過程及避坑

    在數(shù)字化轉(zhuǎn)型的浪潮下,數(shù)據(jù)庫作為企業(yè)核心數(shù)據(jù)存儲與管理的基石,其安全性、穩(wěn)定性和自主可控性顯得尤為重要,這篇文章主要介紹了銀河麒麟V10安裝達(dá)夢8數(shù)據(jù)庫詳細(xì)操作過程及避坑的相關(guān)資料,需要的朋友可以參考下
    2026-04-04

最新評論

阳城县| 紫阳县| 改则县| 宣汉县| 平安县| 大洼县| 温宿县| 青阳县| 阿克| 顺义区| 称多县| 望谟县| 宾川县| 夏邑县| 凌海市| 田东县| 喀喇沁旗| 湟源县| 凤城市| 韶关市| 栾城县| 乐安县| 楚雄市| 紫阳县| 天镇县| 乾安县| 长兴县| 乡城县| 若尔盖县| 黄大仙区| 德惠市| 策勒县| 巴青县| 洱源县| 海伦市| 黄梅县| 天全县| 湘阴县| 兴仁县| 梧州市| 桐梓县|