2.4 Impala的初体验
1.启动Impala
[root@hadoop102 ~]# impala-shell
2.查看数据库
[hadoop102:21000] > show databases;
3.打开默认数据库
[hadoop102:21000] > use default;
4.显示数据库中的表
[hadoop102:21000] > show tables;
5.创建一张student表
[hadoop102:21000] > create table student(id int, name string)
> row format delimited
> fields terminated by '\t';
6.向表中导入数据
[hadoop103:21000] > load data inpath '/student.txt' into table student;
注意:
1)关闭(修改hdfs的配置dfs.permissions为false)或修改hdfs的权限,否则impala没有写的权限
[hdfs@hadoop103 ~]$ hadoop fs -chmod -R 777 /
2)Impala不支持将本地文件导入到表中
7.查询
[hadoop103:21000] > select * from student;
8.退出impala
[hadoop103:21000] > quit;
Impala的操作命令
3.1 Impala的外部shell
选项 描述
1.连接指定hadoop103的impala主机
[root@hadoop102 datas]# impala-shell -i hadoop103
2.使用-q查询表中数据,并将数据写入文件中
[hdfs@hadoop103 ~]$ impala-shell -q 'select * from student' -o output.txt
3.查询执行失败时继续执行
[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;
4.在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 |
+---------+
5.显示查询执行计划
[hdfs@hadoop103 ~]$ impala-shell -p
[hadoop103:21000] > select * from student;
6.去格式化输出
[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
3.2 Impala的内部shell
选项 描述
1.查看执行计划
explain select * from student;
2.查询最近一次查询的底层信息
[hadoop103:21000] > select count(*) from student;
[hadoop103:21000] > profile;
3.查看hdfs及linux文件系统
[hadoop103:21000] > shell hadoop fs -ls /;
[hadoop103:21000] > shell ls -al ./;
4.刷新指定表的元数据
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;
5.查看历史命令
[hadoop103:21000] > history;