#創建新表
hive> CREATE TABLE t_hive (a int, b int, c int) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
#導入數據t_hive.txt到t_hive表
hive> LOAD DATA LOCAL INPATH '/home/cos/demo/t_hive.txt' OVERWRITE INTO TABLE t_hive ;
#正則匹配表名
hive>show tables '*t*';
#增加一個字段
hive> ALTER TABLE t_hive ADD COLUMNS (new_col String);
#重命令表名
hive> ALTER TABLE t_hive RENAME TO t_hadoop;
#從HDFS加載數據
hive> LOAD DATA INPATH '/user/hive/warehouse/t_hive/t_hive.txt' OVERWRITE INTO TABLE t_hive2;
#從其他表導入數據
hive> INSERT OVERWRITE TABLE t_hive2 SELECT * FROM t_hive ;
#創建表並從其他表導入數據
hive> CREATE TABLE t_hive AS SELECT * FROM t_hive2 ;
#僅復制表結構不導數據
hive> CREATE TABLE t_hive3 LIKE t_hive;
#通過Hive導出到本地文件系統
hive> INSERT OVERWRITE LOCAL DIRECTORY '/tmp/t_hive' SELECT * FROM t_hive;
#Hive查詢HiveQL
from ( select b,c as c2 from t_hive) t select t.b, t.c2 limit 2;
select b,c from t_hive limit 2;
#創建視圖
hive> CREATE VIEW v_hive AS SELECT a,b FROM t_hive;
#刪表
drop table if exists t_hft;
#創建分區表
DROP TABLE IF EXISTS t_hft;
CREATE TABLE t_hft(
SecurityID STRING,
tradeTime STRING,
PreClosePx DOUBLE
) PARTITIONED BY (tradeDate INT)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
#導入分區數據
hive> load data local inpath '/home/BlueBreeze/data/t_hft_1.csv' overwrite into table t_hft partition(tradeDate=20130627);
#查看分區表
hive> SHOW PARTITIONS t_hft;