一、前言
项目需要,需要知道hive的支持的最大并发用户数目是否满足需求,因此,写了个小程序测试 ,方式是java调用命令行程序的方式进行。
即:
- Process executor = Runtime.getRuntime().exec(command,env);
但是这样做面临一个问题,就是在命令行输入hive -e "show tables"一切正常,如下所示。
- [niy@niy-computer /]$ hive -e "show tables"
- Logging initialized using configuration in file:/home/niy/workspace1/hive/trunk/conf/hive-log4j.properties
- Hive history file=/tmp/niy/hive_job_log_niy_201305201234_366682237.txt
- OK
- alter2
- niytab
- part_nowhitelist_test
- part_whitelist_test
- poke
- poke1
- poke3
- raw
- src_rc_concatenate_test
- table1
- table3
- test_table
- test_table_like
- xx
- Time taken: 6.217 seconds, Fetched: 14 row(s)
二 解决方案
提示 cannot recognize input near 'show' '<EOF>' '<EOF>' in ddl statement,即告知 show 以后的语句“ tables”没有读取成功,换成"show databases"可以发现错误依旧。
调试发现程序 在运行到
- Process executor = Runtime.getRuntime().exec(command,env);
command 的值是hive -e "show tables",即交给hive 时是准确无误的,可以断定解析出错是hive 本身的问题。
由于时间有限,暂给出解决方案,采用hive -f 来避开该问题,至于这问题的正面解决方案以后有时间 再处理,初步感觉可能是hive 的bug。
首先将hive ql语句 写入 文件/home/niy/tmp.ql (.ql后缀)
采用hive -v -f /home/niy/tmp.ql
搞定。
三 总结
问题的解决有时不是兵来将挡,水来土埋的正面回应,也可以是采用迂回战术。