日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HIVE入门之数据模型

發布時間:2023/12/19 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HIVE入门之数据模型 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


內部表

內部表(Table)
-與數據庫的Table在概念上類似
-每一個Table在Hive中都有一個相應的目錄(HDFS上的目錄)存儲數據
-所有的Table數據(不包括External Table)都保存在這個目錄(HDFS目錄)中
-表的元數據信息,存儲在元數據數據庫中(mysql)
-刪除表后,元數據和數據都會被刪除


創建表--案例:

create table t1 (t1 int, tname string, age int);

在hive中創建一張表,如果不指定表所保存的位置,那么這張表會創建在HDFS文件系統中的/user/hive/warehouse目錄下


create table t2 (tid int, tname string, age int) location '/mytable/hive/t2';指定表的位置為HDFS中的/mytable/hive/t2


create table t3 (tid int, tname string, age int) row format delimited fields terminated by ',';
表示以csv文件格式存儲,因為csv存儲的分隔符為逗號
//row format 指定表示行的格式


加入數據--案例:
create table t4 as select * from sample_data;//采用sample_data查詢的集合來創建t4表
//查看HDFS中的文件發現,t4表中數據與數據之間沒有分隔符
這里我們同樣可以指定分隔符:
create table t4 row format delimited fields terminated by ',' as select * from sample_data;//采用sample_data查詢的集合來創建t5表,并以','為分隔符


在一張表上加入新的列---案例:
alter table t1 add columns(english int);
刪除一張表--案例:
drop table t1;//當刪除一張表時,它會把對應的文件放入HDFS的回收站中,所以刪除之后
//我們可以利用一定的方式恢復表中的數據



分區表

分區表(Partition):
(可以提高查詢的效率)
-Partition對應于數據庫Partiton列的密集索引
-在Hive中,表中的一個Partition對應于表下的一個目錄,所有的Partition的數據都存儲在對應的目錄中


創建表--案例

create table partition_table (sid int, sname string) partitioned by (gender string) row format delimited fields terminated by ',';//創建一張以','分隔,以性別進行分區的分區表partition_table


insert into table partition_table partition(gender = 'M') select sid,sname from sample_data where gender = 'M';//將sample_data表中,gender為'M'的行數據,插入到paetition_table表中gender為'M'的分區中
insert into table partition_table partition(gender = 'F') select sid,sname from sample_data where gender = 'F';//將sample_data表中,gender為'F'的行數據,插入到paetition_table表中gender為'F'的分區中

外部表

外部表(External Table) -指向已經在HDFS中存在的數據,可以創建Partition -它和內部表在元數據的組織上時相同的,而實際存儲則有極大的差異 -外部表只有一個過程,加載數據和創建表同時完成,并不會移動到數據倉庫目錄中,只會與外部數據創建一個鏈接,當刪除該表時,僅刪除該鏈接而不刪除實際的數據


外部表創建--案例

create external table external_student (sid int, sname string, age int) row format delimited fields terminate location '/input';//創建一個以','為分隔符的外部表,這個外部表與HDFS中/input目錄下的文件相關聯


桶表

桶表(Bucket Table)
桶表是對數據進行哈希取值,然后放到不同文件存儲。也就是說,桶表中的數據,是通過哈希運算后,將其打散,再存入文件當中,這樣做會避免造成熱塊,從而提高查詢速度。


桶表創建--案例

create table bucket_table (sid int, sname string, age int) clustered by (sname) into 5 buckets;//創建一個桶表,這個桶表是以sname作為哈希運算,運算后的結果放到5個桶中



后記:網課筆記




總結

以上是生活随笔為你收集整理的HIVE入门之数据模型的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。