大数据培训技术之Impala的操作命令

发布时间:2020年06月29日作者:atguigu浏览次数:1,014

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打印列名
  1. 连接指定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历史命令
  1. 查看执行计划

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;

大数据培训


上一篇:
下一篇:
相关课程

java培训 大数据培训 前端培训

关于尚硅谷
教育理念
名师团队
学员心声
资源下载
视频下载
资料下载
工具下载
加入我们
招聘岗位
岗位介绍
招贤纳师
联系我们
全国统一咨询电话:010-56253825
地址:北京市昌平区宏福科技园2号楼3层(北京校区)

深圳市宝安区西部硅谷大厦B座C区一层(深圳校区)

上海市松江区谷阳北路166号大江商厦3层(上海校区)

武汉市东湖高新开发区东湖网谷(武汉校区)

西安市雁塔区和发智能大厦B座3层(西安校区)

成都市成华区北辰星拱青创园综合楼3层(成都校区)