大数据学习

Impala更新元数据:invalidate metadata和

2020-11-13  本文已影响0人  xiaogp

摘要:ImpalaHive

invalidate metadata

对于通过Hive创建,删除或者修改表等操作,Impala无法自动感知到Hive元数据的变化,想让Impala识别到这个变化需要在impala shell中输入invalidate metadata,该语句会使得impala原元数据失效并且重新从元数据库同步元数据信息。可以对所有表执行,也可以指定某张表

invalidate metadata;           -- 废除所有表的元数据
invalidate metadata [table];   -- 废除表table的元数据

在hive中新建一张表

hive> create table create_hive_test (
    > f1 string,
    > f2 string
    > );
OK
Time taken: 0.697 seconds
hive> insert into create_hive_test values ("a", "b");
hive> select * from create_hive_test;
OK
a   b
Time taken: 0.462 seconds, Fetched: 1 row(s)

在impala shell查看没有此表

[cloudera01:21000] > show tables;
Query: show tables
+----------------+
| name           |
+----------------+
| load_data_test |
| logs           |
| student_info   |
+----------------+

使用invalidate metadata同步hive元数据

[cloudera01:21000] > invalidate metadata;
Query: invalidate metadata
Query submitted at: 2020-11-12 20:11:14 (Coordinator: http://cloudera01:25000)
Query progress can be monitored at: http://cloudera01:25000/query_plan?query_id=a84c5493ed1f024e:b87287800000000
Fetched 0 row(s) in 5.22s
[cloudera01:21000] > show tables;
+------------------+
| name             |
+------------------+
| create_hive_test |
| load_data_test   |
| logs             |
| student_info     |
+------------------+
[cloudera01:21000] > select * from create_hive_test;
+----+----+
| f1 | f2 |
+----+----+
| a  | b  |
+----+----+
Fetched 1 row(s) in 4.15s

refresh

对于通过hive加载,插入,改变的数据操作,或者通过hdfs对数据进行改变的操作,impala都无法自动识别数据的变化,可以使用REFRESH table_name,该语句可以让impala识别到数据的变化,可以对某张表更新元数据,也可以对某张表的某分区更新元数据。

refresh [table];                           -- 刷新表table的元数据
refresh [table] partition [partition];     -- 刷新表table的partition分区元数据

在hive表中插入一条数据

hive> insert into create_hive_test values ("c", "d");
hive> select * from create_hive_test;
a   b
c   d

在impala中无法自动识别到hive中表的变化,查询不到插入的数据

[cloudera01:21000] > select * from create_hive_test;
+----+----+
| f1 | f2 |
+----+----+
| a  | b  |
+----+----+

使用REFRESH命令同步数据表变化

[cloudera01:21000] > refresh create_hive_test;
[cloudera01:21000] > select * from create_hive_test;
+----+----+
| f1 | f2 |
+----+----+
| a  | b  |
| c  | d  |
+----+----+

测试在hdfs的impala表名目录中直接删除某块数据文件

[hdfs@cloudera01 gp]$ hdfs dfs -ls /user/hive/warehouse/test_gp.db/student_info
Found 7 items
-rw-r--r--   3 impala hive         13 2020-11-11 16:46 /user/hive/warehouse/test_gp.db/student_info/27405bb44af85efa-49d42b600000000_390716612_data.0.
-rw-r--r--   3 impala hive         10 2020-11-11 16:46 /user/hive/warehouse/test_gp.db/student_info/564d89653cdde3a2-8ed5550a00000000_903878524_data.0.
-rw-r--r--   3 impala hive         10 2020-11-11 16:46 /user/hive/warehouse/test_gp.db/student_info/624958465fedb197-13ace98200000000_47382019_data.0.
-rw-r--r--   3 impala hive         10 2020-11-11 17:26 /user/hive/warehouse/test_gp.db/student_info/8c4663903e81a83b-f08aa9bb00000000_1581121194_data.0.
drwxrwx--T   - impala hive          0 2020-11-11 17:26 /user/hive/warehouse/test_gp.db/student_info/_impala_insert_staging
-rw-r--r--   3 impala hive         10 2020-11-11 17:26 /user/hive/warehouse/test_gp.db/student_info/b743d2e0c79faa0b-85f9949400000000_111904767_data.0.
-rw-r--r--   3 impala hive         10 2020-11-11 17:26 /user/hive/warehouse/test_gp.db/student_info/d44aa3e348d67c1c-5776363300000000_593779736_data.0.

删除某块数据

[hdfs@cloudera01 gp]$ hdfs dfs -rm /user/hive/warehouse/test_gp.db/student_info/d44aa3e348d67c1c-5776363300000000_593779736_data.0.

在impala中查询原表报错,hdfs上某块数据不存在,元数据未更新导致获取不到被删除的数据

[cloudera01:21000] > select * from student_info;
Error(2): No such file or directory
Root cause: RemoteException: File does not exist: /user/hive/warehouse/test_gp.db/student_info/d44aa3e348d67c1c-5776363300000000_593779736_data.0.

使用REFRESH同步表元数据,即可查询到表数据,被删除的一条数据已经不存在

[cloudera01:21000] > refresh student_info;
[cloudera01:21000] > select * from student_info;
+--------+-----+
| name   | age |
+--------+-----+
| 王帆   | 15  |
| 小王   | 55  |
| 猪坚强 | 16  |
| 李想   | 17  |
| 老陈   | 12  |
+--------+-----+

更新元数据的使用

上一篇 下一篇

猜你喜欢

热点阅读