常用命令行选项
-h或–help
显示帮助信息。
[root@node2 ~]# impala-shell -h
-k or --kerberos
当连接到 impalad 时使用 Kerberos 认证。如果要连接的 impalad 实例不支持 Kerberos,将显示一个错误
-i或–impalad
连接到指定的impalad节点。
[root@node2 ~]# impala-shell -i node3
-q或–query
指定要执行的Sql语句。
[root@node2 ~]# impala-shell -q "select studentid,sum(language) sum_language from data_warehouse.student_scores group by studentid"
-f或–query_file
可指定一个Sql脚本文件,脚本文件中多个Sql间用";"分隔。
# sql脚本文件
[root@node2 ~]# cat query.sql
use data_warehouse;
select studentid,sum(language) sum_language from student_scores group by studentid;
# impala执行查询
[root@node2 ~]# impala-shell -f query.sql
-o或–output_file
查询结果输出到指定文件。
[root@node2 ~]# impala-shell -o result.txt -q "select studentid,sum(language) sum_language from data_warehouse.student_scores group by studentid limit 3"
#查看结果文件
[root@node2 ~]# cat result.txt
+-----------+--------------+
| studentid | sum_language |
+-----------+--------------+
| 214 | 94 |
| 121 | 96 |
| 212 | 76 |
+-----------+--------------+
-B或–delimited
不使用默认格式化输出,以分隔模式输出。一般和–output_delimiter参数连用。
–output_delimiter
对使用-B模式输出的查询结果指定各字段间的分隔符。
–print_header
输出列名。
[root@node2 ~]# impala-shell -B --output_delimiter=',' --print_header -q "select studentid,sum(language) sum_language from data_warehouse.student_scores group by studentid" -o result.txt
#查看结果文件
[root@node2 ~]# cat result.txt
studentid,sum_language
214,94
121,96
212,76
-p或–show_profiles
显示查询的执行计划(与Explain语句输出相同)和查询语句底层执行步骤的详细信息。
-V或–verbose
输出详细信息。会输出Impala版本、Query语句、Coordinator信息、Query计划信息、Sql执行结果。
[root@node2 ~]# impala-shell -V -q "select studentid,sum(language) sum_language from data_warehouse.student_scores group by studentid limit 3"
–quiet
禁用详细信息输出。只会输出Sql执行结果。
[root@node2 ~]# impala-shell --quiet -q "select studentid,sum(language) sum_language from data_warehouse.student_scores group by studentid limit 3"
-v或–version
显示版本信息。
[root@node2 ~]# impala-shell -v
Impala Shell v2.12.0-cdh5.16.1 (4a3775e) built on Wed Nov 21 21:02:28 PST 2018
-r或–refresh_after_connect
连接后刷新Impala catalog。
注意:当Hive创建表后,通过Impala查询,需要在连接后刷新(类似于invalidate metadata),才能看到最新的Hive元数据。
[root@node2 ~]# impala-shell -r -q "select studentid,sum(language) sum_language from data_warehouse.student_scores group by studentid limit 3"
-d或–database
指定要连接到的数据库。
[root@node2 ~]# impala-shell -d data_warehouse -q "select studentid,sum(language) sum_language from student_scores group by studentid limit 3"
–var
定义变量。
[root@node2 ~]# cat query_has_variable.sql
select studentid,language from data_warehouse.student_scores where language>=${var:tmp_var};
[root@node2 ~]# impala-shell --var tmp_var=90 -f query_has_variable.sql
-c
查询执行失败时继续执行
-l
启用 LDAP 认证
-u
当使用 -l 选项启用 LDAP 认证时,提供用户名(使用短用户名,而不是完整的 LDAP 专有名称(distinguished name)) ,shell 会提示输入密码
常用命令
查看相关内网IP:cat /etc/hosts
进入impala:
impala-shell;
显示数据库,数据表
show databases;
show tables;
查看表结构定义
desc my_first;
help命令
显示可用命令列表,如下:
[node2:21000] > help;
Documented commands (type help <topic>):
========================================
compute exit history rerun shell unset version
connect explain profile select show use with
describe help quit set tip values
Undocumented commands:
======================
alter delete drop load src update
create desc insert source summary upsert
version命令
显示当前impala版本,如下:
[node2:21000] > version;
Shell version: Impala Shell v2.12.0-cdh5.16.1 (4a3775e) built on Wed Nov 21 21:02:28 PST 2018
Server version: impalad version 2.12.0-cdh5.16.1 RELEASE (build 4a3775ef6781301af81b23bca45a9faeca5e761d)
history命令
显示历史命令列表。历史命令在 ~/.impalahistory文件中。如下:
[node2:21000] > history;
[1]: show databases;
[2]: connect node3;
[3]: compute stats;
[4]: compute stats data_warehouse.student_scores;
[5]: history;
[6]: profile;
[7]: exit;
[8]: connect node3;
[9]: exit;
[10]: select version;
[11]: version;
[12]: help;
[13]: version;
[14]: history;
quit/exit命令
退出impala shell,如下:
[node2:21000] > exit;
Goodbye root
connect命令
连接到指定impalad节点,如下:
[node2:21000] > connect node3;
Connected to node3:21000
Server version: impalad version 2.12.0-cdh5.16.1 RELEASE (build 4a3775ef6781301af81b23bca45a9faeca5e761d)
compute stats命令
收集表、列的统计信息,如下:
[node2:21000] > compute stats student_scores;
Query: compute stats student_scores
+-----------------------------------------+
| summary |
+-----------------------------------------+
| Updated 1 partition(s) and 7 column(s). |
+-----------------------------------------+
Fetched 1 row(s) in 0.66s
explain命令
返回给定查询的执行计划,如下:
[node2:21000] > explain select * from student_scores limit 10;
Query: explain select * from student_scores limit 10
+----------------------------------------------+
| Explain String |
+----------------------------------------------+
| Max Per-Host Resource Reservation: Memory=0B |
| Per-Host Resource Estimates: Memory=16.00MB |
| Codegen disabled by planner |
| |
| PLAN-ROOT SINK |
| | |
| 00:SCAN HDFS [data_warehouse.student_scores] |
| partitions=1/1 files=1 size=691B |
| limit: 10 |
+----------------------------------------------+
Fetched 9 row(s) in 0.02s
profile命令
返回最近执行语句的底层信息,常用于问题诊断和性能优化。如下:
[node2:21000] > Profile;
invalidate metadata 与 refresh命令
invalidate metadata 刷新全库所有表或某个表的元数据。
invalidate metadata语法:
#重新加载所有库中所有表的元数据和数据
INVALIDATE METADATA
#重新加载某个表的元数据和数据
INVALIDATE METADATA [table]
refresh 刷新某个表或某个分区的数据。
refresh语法:
#刷新某个表的数据
REFRESH [table]
#刷新某个表某个分区的数据
REFRESH [table] PARTITION [partition]
set与unset命令
set 设置查询的参数,对当前会话中所有查询生效。如下:
# 只输入set,返回所有选项当前值
[node2:21000] > set;
# 设置Explain语句输出的信息量
[node2:21000] > set EXPLAIN_LEVEL=3;
EXPLAIN_LEVEL set to 3
unset 重置set命令设置的参数为默认值。如下:
[node2:21000] > unset EXPLAIN_LEVEL;
Unsetting option EXPLAIN_LEVEL
其他命令
其他命令如Create、Drop、Alter、Desc、Show、Insert、Updata、Upsert、Select
略。
参考:https://blog.csdn.net/wangpei1949/article/details/88565085
https://blog.csdn.net/oracle8090/article/details/53038090
https://www.cnblogs.com/shaosks/p/9528228.html