小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Hive的DDL

 印度阿三17 2019-04-10

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

  主要是定義或改變表的結構、數(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ù)庫默認存儲路徑為:“/user/hive/warehouse“

  create database if not exists hive_ab;

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

    1)查看數(shù)據(jù)庫結構

    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)建表時默認創(chuàng)建的就是管理表,也叫內部表,它不擅長數(shù)據(jù)共享,刪除表后數(shù)據(jù)也會被刪除。

 創(chuàng)建管理表

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

 導入數(shù)據(jù)

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

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

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

 查詢表的結構信息:

 desc formatted emp2;

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

  創(chuàng)建外部表

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

  導入數(shù)據(jù)

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

  查看表結構

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

  刪除表

  drop table if exists student;

  3.分區(qū)表:分區(qū)表對應HDFS的一個獨立的文件目錄,目錄下是該分區(qū)表所有分區(qū)的目錄,每個分區(qū)目錄下存儲該分區(qū)內存儲的數(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';

  導入數(shù)據(jù)

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

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

  添加分區(qū)

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

  (添加該分區(qū)后該分區(qū)內是沒有數(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./content-4-160601.html

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多