最近在熟悉hive,使用hive中的sql語句過程當中出現了一些問題。sql
1,hive中的insert into語句安全
hive> select * from t_hive2; OK 16 2 3 61 12 13 41 2 31 17 21 3 71 2 31 1 12 34 11 2 34 Time taken: 0.218 seconds hive> insert into t_hive2 values(122,34,2); FAILED: Parse Error: line 1:12 mismatched input 't_hive2' expecting TABLE near 'into' in insert clause
2,不支持Date和DateTime類型dom
hive> alter table t_hive2 add columns (time_show Date); FAILED: Error in semantic analysis: DATE and DATETIME types aren't supported yet. Please use TIMESTAMP instead
Hive 建立內部表時,會將數據移動到數據倉庫指向的路徑;若建立外部表,僅記錄數據所在的路徑,不對數據的位置作任何改變。
在刪除表的時候,內部表的元數據和數據會被一塊兒刪除, 而外部表只刪除元數據,不刪除數據。這樣外部表相對來講更加安全些,數據組織也更加靈活,方便共享源數據。
函數
4,hive中兩個表連接時和之前有些不一樣spa
hive> select * > from t_hive,t_hive2 > where t_hive.a=t_hive2.b; FAILED: Parse Error: line 2:11 mismatched input ',' expecting EOF near 't_hive'5, 內置函數查看命令(show functions;desc function 函數名)
hive> desc function when; OK There is no documentation for function 'when' Time taken: 0.095 seconds hive> desc function rand; OK rand([seed]) - Returns a pseudorandom number between 0 and 1 Time taken: 0.078 seconds6,hive中不支持truncate table 表名的形式存在(也包括 delete from 表名),可經過 hive>dfs -rmr /user/hive/warehouse/表名來清空該表下的數據,以便保持表元數據信息不丟失;或者經過create table 表名 like 表名,也能夠。
hive> truncate table t_hive; FAILED: Parse Error: line 1:0 cannot recognize input near 'truncate' 'table' 't_hive' hive> delete from table t_hive; Usage: delete [FILE|JAR|ARCHIVE] <value> [<value>]*7,hive中不支持 in (子查詢語句),好比: in (select id from 表名) .能夠經過內鏈接或者 半鏈接 from 表1 left semi join 表2 on (表1.列名 = 表2.列名),表2只能在on中出現,不能在select中引用
8,hive中在不須要全局排序的狀況下,寫排序語句時,最好用distribute by 表名.字段名 sort by 表名.字段名 asc | desc 的形式,儘可能不用order by形式(只經過一個reduce來完成全部的排序結果)
code