Impala的操作命令
一、Impala的外部shell
| 選項 |
描述 |
| -h, --help |
顯示幫助信息 |
| -v or --version |
顯示版本信息 |
| -i hostname, --impalad=hostname |
指定連接運行 impalad 守護進程的主機。默認端口是 21000。 |
| -q query, --query=query |
從命令行中傳遞一個shell 命令。執行完這一語句后 shell 會立即退出。 |
| -f query_file, --query_file= query_file |
傳遞一個文件中的 SQL 查詢。文件內容必須以分號分隔 |
| -o filename or --output_file filename |
保存所有查詢結果到指定的文件。通常用於保存在命令行使用 -q 選項執行單個查詢時的查詢結果。(會覆蓋原目標文件的內容) |
| -c |
查詢執行失敗時繼續執行 |
| -d default_db or --database=default_db |
指定啟動后使用的數據庫,與建立連接后使用use語句選擇數據庫作用相同,如果沒有指定,那么使用default數據庫 |
| -r or --refresh_after_connect |
建立連接后刷新 Impala 元數據 |
| -p, --show_profiles |
對 shell 中執行的每一個查詢,顯示其查詢執行計划 |
| -B(--delimited) |
去格式化輸出(就是去掉查詢結果的表外框) |
| --output_delimiter=character |
指定分隔符 |
| --print_header |
打印列名 |
1.連接指定bigdata12的impala主機-i
[root@bigdata11 datas]# impala-shell -i bigdata12
2.查詢表中數據,並將數據寫入文件中-q、-o
引號內部可以不寫分號,因為它只識別一條語句。
[root@cdh2 ~]# impala-shell -q "select * from student"
[hdfs@bigdata12 ~]$ impala-shell -q 'select * from student' -o output.txt
3.查詢執行失敗時繼續執行-c
select * from student;
select * from 111;
select id from student;
[root@cdh2 ~]$ impala-shell -c -f impalasql;

將-f、-c、-o組合使用
[root@cdh2 ~]# impala-shell -c -f /root/impalasql -o /root/impalasqlout
將含有問題的查詢語句的文件執行出來的結果保存到指定文件中去
[root@cdh2 ~]# vi impalasqlout

4.執行一個文件-f
1)先創建一個文件,文件內容為:
select * from student;
select id from student;
2)執行該文件-f:
[root@cdh2 ~]# impala-shell -f /root/impalasql

5.去格式化輸出-B:
[root@cdh2 ~]# impala-shell -c -f /root/impalasql -o /root/impalasqlout -B
[root@cdh2 ~]# vi impalasqlout

對比之前的文件,不難看出是以覆蓋的方式寫入到此文件中
再舉個例子:
[root@bigdata12 ~]# impala-shell -q 'select * from student' -B --output_delimiter="\t" -o output.txt
注:output.txt 是相對於Linux本地的相對路徑,並且是以覆蓋的方式寫入到此文件中
[root@bigdata12 ~]# cat output.txt
1001 tignitgn
1002 yuanyuan
1003 haohao
1004 yunyun
6.加上分隔符--output_delimiter=
[root@cdh2 ~]# impala-shell -c -f /root/impalasql -o /root/impalasqlout -B --output_delimiter=,
像這里就是用逗號作為分隔符分割各列數據

7.在hive中創建表后,刷新元數據-r
hive> create table stu(id int, name string);
[bigdata12:21000] > show tables;
Query: show tables
+---------+
| name |
+---------+
| student |
+---------+
[hdfs@bigdata12 ~]$ impala-shell -r
[bigdata12:21000] > show tables;
Query: show tables
+---------+
| name |
+---------+
| stu |
| student |
+---------+
8.顯示查詢執行計划
[hdfs@bigdata12 ~]$ impala-shell -p
[bigdata12:21000] > select * from student;
二、Impala的內部shell
| 選項 |
描述 |
| help |
顯示幫助信息 |
| explain <sql> |
顯示執行計划 |
| profile |
(查詢完成后執行) 查詢最近一次查詢的底層信息 |
| shell <shell> |
不退出impala-shell執行shell命令 |
| version |
顯示版本信息(同於impala-shell -v) |
| connect |
連接impalad主機,默認端口21000(同於impala-shell -i) |
| refresh <tablename> |
增量刷新元數據庫(指定某張表的數據進行刷新) |
| invalidate metadata |
全量刷新元數據庫(慎用,刷新所有表)(同於 impala-shell -r) |
| history |
歷史命令 |
1.查看執行計划
explain select * from student;
2.查詢最近一次查詢的底層信息
[bigdata12:21000] > select count(*) from student;
[bigdata12:21000] > profile;
3.查看hdfs及linux文件系統
[bigdata12:21000] > shell hadoop fs -ls /;
[bigdata12:21000] > shell ls -al ./;
4.刷新指定表的元數據
hive> load data local inpath '/opt/module/datas/student.txt' into table student;
[bigdata12:21000] > select * from student;
[bigdata12:21000] > refresh student;
[bigdata12:21000] > select * from student;
5.查看歷史命令
[bigdata12:21000] > history;
