非等同配置单元查询的解决方法

时间:2013-11-26 14:44:48

标签: join hadoop mapreduce left-join hive

我尝试在hive上重写关注查询

select 
    TFCT_CHARGE.SUBS_KEY, 
    TFCT_CHARGE.PRODUCT_KEY, 
    TFCT_CHARGE.CHARGE_NVAL, 
    TFCT_CHARGE.B_SUBS_KEY, 
    TFCT_CHARGE.DELETE_DT, 
    HFCT_SUBS_SEGMENT.SEGMENT_KEY, 
    TFCT_CHARGE.EVENT_DT, 
    TFCT_CHARGE.DWH_SRC_TABLE_KEY
  from
TFCT_CHARGE LEFT OUTER JOIN HFCT_SUBS_SEGMENT
ON (
TFCT_CHARGE.B_SUBS_KEY = HFCT_SUBS_SEGMENT.SUBS_KEY and
TFCT_CHARGE.EVENT_DT >= HFCT_SUBS_SEGMENT.EFF_DT    and
TFCT_CHARGE.EVENT_DT < HFCT_SUBS_SEGMENT.EXP_DT     and
HFCT_SUBS_SEGMENT.SEGMENT_TYPE_KEY = 1)

但是有不平等的查询。 任何人都可以提示我一些解决方法吗? TNX!

2 个答案:

答案 0 :(得分:0)

模拟非等左外连接:

  1. 使用添加的序列行号创建左表的副本
  2. 进行内部联接:
  3. 串行左连接:
  4. 请在此处查看我的答案代码:Hive: work around for non equi left join

答案 1 :(得分:-1)

这很容易)))

select 
    TFCT_CHARGE.SUBS_KEY, 
    TFCT_CHARGE.PRODUCT_KEY, 
    TFCT_CHARGE.CHARGE_NVAL, 
    TFCT_CHARGE.B_SUBS_KEY, 
    TFCT_CHARGE.DELETE_DT, 
    HFCT_SUBS_SEGMENT.SEGMENT_KEY, 
    TFCT_CHARGE.EVENT_DT, 
    TFCT_CHARGE.DWH_SRC_TABLE_KEY
  from
TFCT_CHARGE INNER JOIN HFCT_SUBS_SEGMENT
ON (
TFCT_CHARGE.B_SUBS_KEY = HFCT_SUBS_SEGMENT.SUBS_KEY
HFCT_SUBS_SEGMENT.SEGMENT_TYPE_KEY = 1)
where
TFCT_CHARGE.EVENT_DT >= HFCT_SUBS_SEGMENT.EFF_DT    and
TFCT_CHARGE.EVENT_DT < HFCT_SUBS_SEGMENT.EXP_DT     and