Oracle 转化成 Hive Sql的规则 正则已写好 (要求讲清思路)

img

就是脚本转化,要用到正则表达式吧
正则我写好了

readme有相关规则
如下:
1、将103043.sql转化为103043_init.sql
2、规则:
2.1、select子查询提取出来,含有聚合函数的进行进行建表:
2.1.1:提取子查询
2.1.2:如果子查询含有聚合函数,需要组建新表,
新表 select 条件 含有 原子查询的 where 关联条件,聚合函数
新表 where 条件 含有 原子查询的过滤条件
新表 goup by 含有 原子查询的 where 关联条件
例如:

(select  wm_concat(e.insuredaddress)
          from gupolicyriskrelatedparty e
         where e.policyno = c.policyno
           and e.riskcode = c.riskcode
           and e.plancode = c.plancode
           and e.insuredflag = '2') insuredaddress

转化为 建新表 t_103043_tmp1:
    
   drop table if exists  t_103043_tmp1;  
create table t_103043_tmp1
with (ORIENTATION = COLUMN) AS 
select e.policyno,e.riskcode,e.plancode,string_agg(e.insuredaddress,',')insuredaddress,string_agg(e.contactname,',')contactname
from tpods.gupolicyriskrelatedparty e
where e.insuredflag = '2'
group by e.policyno,e.riskcode,e.plancode;

2.2select子查询提取出来,如果不含有聚合函数,做为单表 直接关联,见下一步:
2.3、将 where 条件中 exists 的子查询提取出来 ,按照关联 字段进行grou by  新建表
例如 子查询
    select  'X'
             from gppolicypaymentdetail gf,gppaymentmain gp
            where gf.chargetimes = gp.chargetimes
              and gf.paymentno = gp.paymentno
              and gp.paymentstatus = '6'
              and gf.policyno = c.policyno
              and gf.riskcode = c.riskcode
              and gf.feetypecode = 'OCST'
              and gp.voucherdate >= $V_DATE1

转化为:

  drop table if exists  t_103043_1_tmp1;  
create table t_103043_1_tmp1
with (ORIENTATION = COLUMN) AS 
select  sum(1) X,gf.policyno,gf.riskcode
             from gppolicypaymentdetail gf,gppaymentmain gp
            where gf.chargetimes = gp.chargetimes
              and gf.paymentno = gp.paymentno
              and gp.paymentstatus = '6'
              and gf.feetypecode = 'OCST'
              and gp.voucherdate >= $V_DATE1
              group by gf.policyno,gf.riskcode

2.4、将2.12.2提取出来的 表,使用 left join 进行关联 
例如:2.1 关联
left join t_103043_tmp1 tt1 on tt1.policyno = c.policyno and tt1.riskcode = c.riskcode and tt1.plancode = c.plancode

例如2.3 关联为
left join t_103043_1_tmp1 tt1 on gf.policyno=c.riskcode  and gf.riskcode=c.riskcode

 

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。


因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。