如何在不使用时间戳的情况下在配置单元中查找最近更新的值

时间:2018-03-08 17:29:59

标签: hadoop hive hiveql hadoop2

我有一张像

这样的表格
id name sal 
1  Saa  45000
2  aaa  33000
增量加载后

id name sal
3  bbb  55000

如何只获取最近更新的没有时间戳的值

2 个答案:

答案 0 :(得分:0)

最简单,最有效的方法是使用分区。每次执行增量加载时,您都可以拥有分区表并创建新分区。这样最新的分区将只有最新的记录。

请注意,非常频繁的增量加载会导致许多小分区,这可能不是最佳数据设计。

可以采用其他几种方法,但这完全取决于您的用例,数据速率和数量。

希望有所帮助!

答案 1 :(得分:0)

创建表格。

hive> create table student(id int, name string);
OK
Time taken: 3.503 seconds

在表格中插入一条记录。

hive> insert into student values(1, 'first');

hive> select * from student;
OK
1   first
Time taken: 0.109 seconds, Fetched: 1 row(s)

在Hive终端上使用以下命令查找表的位置。即学生桌的元商店位置。

hive> describe formatted student;

You should get the details as shown below.

# Detailed Table Information         
Database:               retaildb                 
Owner:                  root                     
CreateTime:             Thu Mar 08 15:52:47 PST 2018     
LastAccessTime:         UNKNOWN                  
Protect Mode:           None                     
Retention:              0                        
Location:               hdfs://quickstart.cloudera:8020/user/hive/warehouse/retaildb.db/student

现在检查内容

[root@quickstart cloudera]# hdfs dfs -ls hdfs://quickstart.cloudera:8020/user/hive/warehouse/retaildb.db/student
Found 1 items
-rwxr-xr-x   1 root supergroup          8 2018-03-08 15:53 hdfs://quickstart.cloudera:8020/user/hive/warehouse/retaildb.db/student/000000_0
[root@quickstart cloudera]# hdfs dfs -cat hdfs://quickstart.cloudera:8020/user/hive/warehouse/retaildb.db/student/*
1first

再插入一条记录。

hive> select * from student;
OK
1   first
1   second
Time taken: 0.095 seconds, Fetched: 2 row(s)

检查Metastore位置。

[root@quickstart cloudera]# hdfs dfs -ls hdfs://quickstart.cloudera:8020/user/hive/warehouse/retaildb.db/student/
Found 2 items
-rwxr-xr-x   1 root supergroup          8 2018-03-08 15:53 hdfs://quickstart.cloudera:8020/user/hive/warehouse/retaildb.db/student/000000_0
-rwxr-xr-x   1 root supergroup          9 2018-03-08 15:57 hdfs://quickstart.cloudera:8020/user/hive/warehouse/retaildb.db/student/000000_0_copy_1


[root@quickstart cloudera]# hdfs dfs -cat hdfs://quickstart.cloudera:8020/user/hive/warehouse/retaildb.db/student/000000_0_copy_1
1second
[root@quickstart cloudera]# hdfs dfs -cat hdfs://quickstart.cloudera:8020/user/hive/warehouse/retaildb.db/student/*
1first
1second