温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

hive中使用sql语句需要注意什么问题

发布时间:2021-07-29 19:20:09 来源:亿速云 阅读:202 作者:chen 栏目:云计算

这篇文章主要讲解了“ hive中使用sql语句需要注意什么问题”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“ hive中使用sql语句需要注意什么问题”吧!


最近在熟悉hive,使用hive中的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


从上面可以看出,hive是不支持insert into 语句的


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的表分为外部表和内部表

Hive 创建内部表时,会将数据移动到数据仓库指向的路径;若创建外部表,仅记录数据所在的路径,不对数据的位置做任何改变。
在删除表的时候,内部表的元数据和数据会被一起删除, 而外部表只删除元数据,不删除数据。这样外部表相对来说更加安全些,数据组织也更加灵活,方便共享源数据。

4,hive中两个表链接时和以前有些不同

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 seconds

6,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来完成所有的排序结果)

感谢各位的阅读,以上就是“ hive中使用sql语句需要注意什么问题”的内容了,经过本文的学习后,相信大家对 hive中使用sql语句需要注意什么问题这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI