Hive SQL语法与经常用的mysql语法具有一定差异性,按照写mysql的习惯写出的sql经常报错,且报错很难看出问题原因,因此在此记录出现问题的现象和解决方式
-
Error: Error while compiling statement: FAILED: ParseException line 3:2 cannot recognize input near '(' 'SELECT' 'a' in joinSource (state=42000,code=40000)
原因:如果你发现你的sql没有任何问题,此时一般是因为子查询没有别名造成的
解决:select * from (select * from a) 更改成 select * from (select * from a) t
-
Error: Error while compiling statement: FAILED: SemanticException [Error 10025]: Expression not in GROUP BY key id (state=42000,code=10025)
原因:在select语句中而不在group by 语句中的字段会导致该报错
解决: select id,name from a group by name 更改成 select collect_set(id),name from a group by name
-
Error: Error while compiling statement: FAILED: SemanticException [Error 10004]: Line 1:13 Invalid table alias or column reference 'id':
原因:子查询语句中对应字段有变化,如使用了函数或重命名了
解决:select id,name from (select collect_set(id),name from a group by name ) t 更改成 select id,name from (select collect_set(id) id,name from a group by name) t 或 select t.id,name from (select collect_set(id),name from a group by name) t
- 问题:HIVE 多个Sql Union后的查询不到数据
原因:Union后的数据在hdfs上存到表目录下的多个新建目录下
解决:增加配置(可以直接在cli 命令行输入) set mapred.input.dir.recursive=true;
或者使用一个Select语句把多个Union语句包起来
-
再TEZ上执行hsql报错Out of memory
需要调整container大小
set hive.tez.container.size=4096;
set hive.tez.java.opts=-Xmx3072m;
-
Hive默认不递归查询子目录所以在创建表时,如果指定目录下有子目录会报ERROR:not a file
可以通过在hive-cli里面执行下面四条配置来在回话里面开启递归访问子目录,不会递归查询会把所有目录下面的数据加载进来,所以在子目录特别深或者子目录特别多时,速度会特别慢。
set hive.input.dir.recursive=true;
set hive.mapred.supports.subdirectories=true;
set hive.supports.subdirectories=true;
set mapred.input.dir.recursive=true;