Impala(一) 基本命令及操作

-- 在impala中创建表a,在Hive中可以查到,Hive会自动更新元数据
create table a(id int ,name string);
-- 在Hive中创建表b,在impala中查询不到,impala不会自动更新元数据
create table b(id int ,name string);
-- 需要刷新才可以查到
invalidate metadata;

-- 1.使用Hive向impala创建的表a中插入数据,发现没有权限
-- 2.vi /etc/passwd 文件中将 hdfs 后的 hdfs:x:996:993:Hadoop HDFS:/var/lib/hadoop-hdfs:/sbin/nologin 改为hdfs:x:996:993:Hadoop HDFS:/var/lib/hadoop-hdfs:/bin/bash
-- 3.切换用户 su hdfs  执行 hdfs dfs -chmod -R 777 / 修改权限
-- 4.在Hive中设置 set mapreduce.framework.name=local; 即可成功插入数据
-- 5.在Hive中插入的数据,在impala中查询不到,需要刷新a表, refresh a; 

-- 指定主机名
impala-shell -i localhost
-- 安静的启动
impala-shell --quiet  

-- 外部命令
-- 
impala-shell -q 'select * from a'
-- 
impala-shell -q 'select * from a' -o a.txt
-- -b 去除表结构 -o 输出到文件中 --output_delimiter=',' 分隔符
impala-shell -q 'select * from a' -B --output_delimiter=',' -o a.txt
-- shell 不退出impala执行shell命令
shell hdfs dfs -ls /;

explain select * from a;
+------------------------------------------------------------------------------------+
| Explain String                                                                     |
+------------------------------------------------------------------------------------+
| Max Per-Host Resource Reservation: Memory=8.00KB Threads=3                         |
| Per-Host Resource Estimates: Memory=64MB                                           |
| WARNING: The following tables are missing relevant table and/or column statistics. |
| default.a                                                                          |
|                                                                                    |
| PLAN-ROOT SINK                                                                     |
| |                                                                                  |
| 01:EXCHANGE [UNPARTITIONED]                                                        |
| |                                                                                  |
| 00:SCAN HDFS [default.a]                                                           |
|    partitions=1/1 files=6 size=34B                                                 |
|    row-size=15B cardinality=unavailable                                            |
+------------------------------------------------------------------------------------+
[cdh01:21000] default> explain select count(1) from a;
+------------------------------------------------------------------------------------+
| Explain String                                                                     |
+------------------------------------------------------------------------------------+
| Max Per-Host Resource Reservation: Memory=8.00KB Threads=3                         |
| Per-Host Resource Estimates: Memory=84MB                                           |
| WARNING: The following tables are missing relevant table and/or column statistics. |
| default.a                                                                          |
|                                                                                    |
| PLAN-ROOT SINK                                                                     |
| |                                                                                  |
| 03:AGGREGATE [FINALIZE]                                                            |
| |  output: count:merge(*)                                                          |
| |  row-size=8B cardinality=1                                                       |
| |                                                                                  |
| 02:EXCHANGE [UNPARTITIONED]                                                        |
| |                                                                                  |
| 01:AGGREGATE                                                                       |
| |  output: count(*)                                                                |
| |  row-size=8B cardinality=1                                                       |
| |                                                                                  |
| 00:SCAN HDFS [default.a]                                                           |
|    partitions=1/1 files=6 size=34B                                                 |
|    row-size=0B cardinality=unavailable                                             |
+------------------------------------------------------------------------------------+

-- 查看当前数据库
select current_database();
-- 展示默认数据库中的表
show tables in default;
-- 模糊查询
show tables in default like 't*';
-- 查看表结构
desc tb_name
-- 查看表结构详细信息
desc formatted tb_name;
















 

你可能感兴趣的:(BigData,大数据,Impala)