Hive QL是類SQL查詢語句铭拧,和數(shù)據(jù)庫的查詢語句類似惹恃,下面介紹一些基本的表操作:
1. 創(chuàng)建表
創(chuàng)建表的HQL語句如下淆游,逐條輸入即可傍睹,以;結(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ù)访得,沒有表頭,同一行的數(shù)據(jù)以‘\t’分割陕凹,每行以'\n'結(jié)束悍抑。導(dǎo)入數(shù)據(jù)的語句為:
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;