Hive QL是類SQL查詢語(yǔ)句,和數(shù)據(jù)庫(kù)的查詢語(yǔ)句類似,下面介紹一些基本的表操作:
1. 創(chuàng)建表
創(chuàng)建表的HQL語(yǔ)句如下,逐條輸入即可,以;結(jié)束。
CREATE TABLE students3(id int,name string,age tinyint,phone char(13),email varchar(30),courses smallint,score1 float, score2 double,tuition decimal(5,2),flow bigint,enDate1 timestamp,enDate2 date,enDate3 string,enDate4 char(30),enDate5 varchar(30),enDate6 string,enDate7 string,enDate8 string,enDate9 bigint)
COMMENT 'Students3 details'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;
表中數(shù)據(jù)如下,基本涵蓋了所有數(shù)據(jù)類型。
2. 向表中導(dǎo)入數(shù)據(jù)
在本地創(chuàng)建“test.txt”文件,表中只包含數(shù)據(jù),沒(méi)有表頭,同一行的數(shù)據(jù)以‘\t’分割,每行以'\n'結(jié)束。導(dǎo)入數(shù)據(jù)的語(yǔ)句為:
LOAD DATA LOCAL INPATH '/home/spark/Desktop/test.txt'
OVERWRITE INTO TABLE students3;
3. 查看表中數(shù)據(jù)
select * from students3;
4. 查看當(dāng)前有哪些表
show tables;
5. 刪除表
drop table students3;
6. 刪除表中所有數(shù)據(jù)
truncate table students3;