2017-02-07 36 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] ~]$