免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Hive的DDL

DDL:data definittion language  數(shù)據(jù)定義語言

  主要是定義或改變表的結(jié)構(gòu)、數(shù)據(jù)類型、表之間的鏈接和約束等初始化操作

DML:data manipulation language  數(shù)據(jù)操作語言

  主要是對數(shù)據(jù)庫的數(shù)據(jù)進行增刪改查操作,如select、insert、delete、update等

一、對數(shù)據(jù)庫的操作

  1.創(chuàng)建數(shù)據(jù)庫并指定在hdfs的存儲路徑

  create database if not exists hive_db location '/hive_db';

  注釋:不指定路徑所創(chuàng)建的數(shù)據(jù)庫默認(rèn)存儲路徑為:“/user/hive/warehouse“

  create database if not exists hive_ab;

  2.查看數(shù)據(jù)庫信息

    1)查看數(shù)據(jù)庫結(jié)構(gòu)

    desc database hive_db;

    2)添加數(shù)據(jù)庫的描述信息

    alter database hive_db set dbproperties('creater'='wyh');

    3)查看數(shù)據(jù)庫的拓展信息

    desc database extended hive_db;

  3.篩選查詢數(shù)據(jù)庫

  show database like 'hive*';

  4.刪除數(shù)據(jù)庫

  drop database wyh;

  drop database if exists hive_db;

二、DDL操作

  hive中表的種類有很多,如管理表(Manager Table)、外部表(External Table)、分區(qū)表(Partition Table)、分桶表,下面我先介紹前三種表的定義、修改操作。

  1.管理表:Hive創(chuàng)建表時默認(rèn)創(chuàng)建的就是管理表,也叫內(nèi)部表,它不擅長數(shù)據(jù)共享,刪除表后數(shù)據(jù)也會被刪除。

 創(chuàng)建管理表

 create table if not exists emp1(id int,name string) row format delimited fields terminated by '\t';

 導(dǎo)入數(shù)據(jù)

 load data local inpath '/root/data/emp.txt' into table emp1;

 創(chuàng)建新管理表并從emp1表中導(dǎo)入name=wyh的該行數(shù)據(jù)

 create table if not exists emp2 as select * from emp1 where name = 'wyh';

 查詢表的結(jié)構(gòu)信息:

 desc formatted emp2;

  2.外部表:Hive不任務(wù)這張表擁有該數(shù)據(jù),所以刪除該表后數(shù)據(jù)不會刪除,當(dāng)再次創(chuàng)建結(jié)構(gòu)與數(shù)據(jù)類型相同的表(無論是外部表還是管理表)時,數(shù)據(jù)會自動關(guān)聯(lián)。但是若第二次創(chuàng)建的是管理表,再次刪除后即使創(chuàng)建相同格式和數(shù)據(jù)類型的表數(shù)據(jù)將不再恢復(fù)!

  創(chuàng)建外部表

  create external table if not exists student(id int,name string) row format delimited fields terminated by '\t';

  導(dǎo)入數(shù)據(jù)

  load data local inpath '/root/data/student.txt' into table student;

  查看表結(jié)構(gòu)

  desc formatted student;  (可以從Table Type看到:EXTERNAL_TABLE)

  刪除表

  drop table if exists student;

  3.分區(qū)表:分區(qū)表對應(yīng)HDFS的一個獨立的文件目錄,目錄下是該分區(qū)表所有分區(qū)的目錄,每個分區(qū)目錄下存儲該分區(qū)內(nèi)存儲的數(shù)據(jù)。

  創(chuàng)建分區(qū)表

  create table dept_partitions(id int,name string,loc string) partitioned by(day string) row format delimited fiedls terminated by '\t';

  導(dǎo)入數(shù)據(jù)

  load data local inpath '/root/data/dept.txt' into table dept_partition partition(day='1001'); 

  (注意:不能直接導(dǎo)入數(shù)據(jù),必須指定分區(qū))

  添加分區(qū)

  alter table dept_partition add partition(day='1002');

  (添加該分區(qū)后該分區(qū)內(nèi)是沒有數(shù)據(jù)的)

  查詢數(shù)據(jù)

  select * from dept_partition where day='1001';

  select * from dept_partition;

  刪除分區(qū)

  alter table dept_partition drop partition(day='1002');

  alter table dept_partition drop partition(day='1001'),partition(day='1002');

來源:http://www.icode9.com/content-4-160601.html
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Hive DDL DML及SQL操作
oracle 基礎(chǔ)學(xué)習(xí) - 絕影メ之殤 - JavaEye技術(shù)網(wǎng)站
Hive學(xué)習(xí)之路 (三)Hive元數(shù)據(jù)信息對應(yīng)MySQL數(shù)據(jù)庫表
hive基礎(chǔ) - 心如大海 - JavaEye技術(shù)網(wǎng)站
Hive總結(jié)(七)Hive四種數(shù)據(jù)導(dǎo)入方式
Hive 基礎(chǔ)之:分區(qū)、桶、Sort Merge Bucket Join
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服