日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

mysql和hive的sql语句,hive中使用sql语句需要注意的事项

發(fā)布時(shí)間:2025/3/21 数据库 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql和hive的sql语句,hive中使用sql语句需要注意的事项 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

最近在熟悉hive,使用hive中的sql語(yǔ)句過(guò)程中出現(xiàn)了一些問(wèn)題。

1,hive中的insert into語(yǔ)句

hive> select * from t_hive2;

OK

1623

611213

41231

17213

71231

11234

11234

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

從上面可以看出,hive是不支持insert into 語(yǔ)句的

2,不支持Date和DateTime類型

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

3,hive的表分為外部表和內(nèi)部表

Hive 創(chuàng)建內(nèi)部表時(shí),會(huì)將數(shù)據(jù)移動(dòng)到數(shù)據(jù)倉(cāng)庫(kù)指向的路徑;若創(chuàng)建外部表,僅記錄數(shù)據(jù)所在的路徑,不對(duì)數(shù)據(jù)的位置做任何改變。

在刪除表的時(shí)候,內(nèi)部表的元數(shù)據(jù)和數(shù)據(jù)會(huì)被一起刪除, 而外部表只刪除元數(shù)據(jù),不刪除數(shù)據(jù)。這樣外部表相對(duì)來(lái)說(shuō)更加安全些,數(shù)據(jù)組織也更加靈活,方便共享源數(shù)據(jù)。

4,hive中兩個(gè)表鏈接時(shí)和以前有些不同

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, 內(nèi)置函數(shù)查看命令(show functions;desc function 函數(shù)名)

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 seconds

6,hive中不支持truncate table 表名的形式存在(也包括 delete from 表名),可通過(guò) hive>dfs -rmr /user/hive/warehouse/表名來(lái)清空該表下的數(shù)據(jù),以便保持表元數(shù)據(jù)信息不丟失;或者通過(guò)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] []*

7,hive中不支持 in (子查詢語(yǔ)句),比如: in (select id from 表名) .可以通過(guò)內(nèi)連接或者 半連接 from 表1 left? semi join 表2 on (表1.列名 = 表2.列名),表2只能在on中出現(xiàn),不能在select中引用

8,hive中在不需要全局排序的情況下,寫排序語(yǔ)句時(shí),最好用distribute by 表名.字段名 sort by?表名.字段名 asc | desc 的形式,盡量不用order by形式(只通過(guò)一個(gè)reduce來(lái)完成所有的排序結(jié)果)

總結(jié)

以上是生活随笔為你收集整理的mysql和hive的sql语句,hive中使用sql语句需要注意的事项的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。