1 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 | 打印列名 |
- 连接指定hadoop103的impala主机
[root@hadoop102 datas]# impala-shell -i hadoop103
- 使用-q查询表中数据,并将数据写入文件中
[hdfs@hadoop103 ~]$ impala-shell -q ‘select * from student’ -o output.txt
- 查询执行失败时继续执行
[hdfs@hadoop103 ~]$ vim impala.sql
select * from student;
select * from stu;
select * from student;
[hdfs@hadoop103 ~]$ impala-shell -f impala.sql;
[hdfs@hadoop103 ~]$ impala-shell -c -f impala.sql;
- 在hive中创建表后,使用-r刷新元数据
hive> create table stu(id int, name string);
[hadoop103:21000] > show tables;
Query: show tables
+———+
| name |
+———+
| student |
+———+
[hdfs@hadoop103 ~]$ impala-shell -r
[hadoop103:21000] > show tables;
Query: show tables
+———+
| name |
+———+
| stu |
| student |
+———+
- 显示查询执行计划
[hdfs@hadoop103 ~]$ impala-shell -p
[hadoop103:21000] > select * from student;
所谓执行计划,即在查询sql执行之前,先对该sql做一个分析,列出需要完成这一项查询的详细方案:
- 去格式化输出
[root@hadoop103 ~]# impala-shell -q ‘select * from student’ -B –output_delimiter=”\t” -o output.txt
[root@hadoop103 ~]# cat output.txt
1001 tignitgn
1002 yuanyuan
1003 haohao
1004 yunyun
2 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 | 历史命令 |
- 查看执行计划
explain select * from student;
- 查询最近一次查询的底层信息
[hadoop103:21000] > select count(*) from student;
[hadoop103:21000] > profile;
- 查看hdfs及linux文件系统
[hadoop103:21000] > shell hadoop fs -ls /;
[hadoop103:21000] > shell ls -al ./;
- 刷新指定表的元数据
hive> load data local inpath ‘/opt/module/datas/student.txt’ into table student;
[hadoop103:21000] > select * from student;
[hadoop103:21000] > refresh student;
[hadoop103:21000] > select * from student;
- 查看历史命令
[hadoop103:21000] > history;
上一篇: 前端培训面试题分析-socket
下一篇: 大数据培训技术之mpala的数据类型