2017-02-07 420 views
3

有没有办法将Impala查询的结果与查询一起输出?如何输出Impala查询的结果以及查询

例如,如果我的查询语句'show databases',我将结果输出到一个文件是这样的:

Query: show databases 
Result: ------default------- 

当我运行impala-shell -i someip -f 'filename' -o 'output',我只看到了结果,一个一个之后,所以很难将哪个结果与哪个查询关联起来(特别是当输入文件包含很多查询时)。

回答

1

重定向stderr和标准输出到文件
(该查询是在标准错误)

impala-shell -f 'filename' &>'output' 

演示

[[email protected] ~]$ cat>filename 
select 1; 
select 2; 
select 3; 
[[email protected] ~]$ impala-shell -f 'filename' &>'output' 
[[email protected] ~]$ cat output 
Starting Impala Shell without Kerberos authentication 
Connected to quickstart.cloudera:21000 
Server version: impalad version 2.5.0-cdh5.7.0 RELEASE (build ad3f5adabedf56fe6bd9eea39147c067cc552703) 
Query: select 1 
+---+ 
| 1 | 
+---+ 
| 1 | 
+---+ 
Fetched 1 row(s) in 0.16s 
Query: select 2 
+---+ 
| 2 | 
+---+ 
| 2 | 
+---+ 
Fetched 1 row(s) in 0.02s 
Query: select 3 
+---+ 
| 3 | 
+---+ 
| 3 | 
+---+ 
Fetched 1 row(s) in 0.02s 
[[email protected] ~]$