Hive 配置单元:通过映射没有公共列的另一个表中的行,从表中获取行

Hive 配置单元:通过映射没有公共列的另一个表中的行,从表中获取行,hive,conditional-statements,hiveql,Hive,Conditional Statements,Hiveql,我有两张桌子 表1: 时间戳 表2: 时间戳\u下限, 时间戳上界 如果时间戳位于配置单元中表2中的下限和上限之间,我想从表1中选择行 我尝试了以下代码 SELECT * FROM Table1 where from_unixtime(unix_timestamp(timestamp, 'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm') BETWEEN (select from_unixtime(unix_timestamp(timestamp_low

我有两张桌子

表1:

时间戳

表2:

时间戳\u下限, 时间戳上界

如果时间戳位于配置单元中表2中的下限和上限之间,我想从表1中选择行

我尝试了以下代码

SELECT *
FROM Table1
where from_unixtime(unix_timestamp(timestamp, 'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm') 
BETWEEN (select from_unixtime(unix_timestamp(timestamp_lower_bound, 'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm') from Table2) 
AND (select from_unixtime(unix_timestamp(timestamp_upper_bound, 'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm') from Table2) 
它给出了下面的错误

DAG did not succeed due to VERTEX_FAILURE. failedVertices:1 killedVertices:1
我也遵循了stackoverflow的说明,下面是代码。由于顶点失败,它也失败了

SELECT a.*
FROM Table1 AS a
WHERE EXISTS
    (SELECT 1
     FROM Table2 AS b
     WHERE a.timestamp BETWEEN from_unixtime(unix_timestamp(b.timestamp_lb, 'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm') 
     AND from_unixtime(unix_timestamp(b.timestamp_ub, 'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm') )
你知道怎么做吗?不需要在蜂箱中进行,Spark也可以工作。有什么想法吗

EIDT

这里是一个玩具的例子

假设在表1时间戳中,我有以下内容

|---------------------|
|    Timestamp        |  
|---------------------|
|  2018-01-15 17:56   | 
|---------------------|
|  2019-04-29 08:43   | 
|---------------------|
|  2018-10-23 23:43   | 
|---------------------|
|  2018-08-21 04:54   | 
|---------------------|
|  2019-12-06 14:09   | 
|---------------------|
在表2中,我有以下上界和下界

|----------------------|------------------------|
|timestamp_lower_bound |timestamp_upper_bound   |
|----------------------|------------------------|
|  2018-04-15 12:37    |  2018-04-15 12:57      |
|----------------------|------------------------|
|  2018-10-23 23:38    |  2018-10-23 23:58      |
|----------------------|------------------------|
|  2018-08-21 04:50    |  2018-08-21 05:10      |
|----------------------|------------------------|

在这种情况下,只应选择表1中的第三条和第四条记录。如何实现这一点?

根据上述示例,它清楚地表明“表2”在两列中包含相同的数据(时间戳下界和时间戳上界),即日期,只能更改“HH:MM”或只能更改“MM”

如果只扫描一列就足够了,那么不必同时扫描两列

例如:

create table table1
(TTimestamp string);

insert into table1 values('2018-01-15 17:56');
insert into table1 values('2019-04-29 08:43');
insert into table1 values('2018-10-23 23:43');
insert into table1 values('2018-08-21 04:54');
insert into table1 values('2019-12-06 14:09');

create table table2
(timestamp_lower_bound string,
timestamp_upper_bound  string);

insert into table2 values('2018-04-15 12:37','2018-04-15 12:57');
insert into table2 values('2018-10-23 23:43','2018-10-23 23:58');
insert into table2 values('2018-08-21 04:54','2018-08-21 05:10');
在这里,我将数据类型作为字符串并按原样插入记录

select TTimestamp from table1 where from_unixtime(unix_timestamp(timestamp, 'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm') in(select from_unixtime(unix_timestamp(timestamp_lower_bound, 'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm') from table2); 

谢谢你的评论。事实上,表1是一个大表,而表2是非常小的。关于您建议的代码,当应用min/max运算符时,“between and”子句实际上连接两个值,而不是两列值,对吗?但是我想得到表1中的时间戳,它位于表2中每一对下限和上限之间。@Tracy Yang,你能用适当的例子详细说明你的问题吗?谢谢你的建议。我更新了我的问题,加入了一个玩具的例子。如果你有任何想法,请告诉我。
select TTimestamp from table1 where from_unixtime(unix_timestamp(timestamp, 'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm') in(select from_unixtime(unix_timestamp(timestamp_lower_bound, 'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm') from table2);