瀏覽代碼

添加ods到dwd层

wudianlong 2 年之前
父節點
當前提交
b8f0a114a3
共有 1 個文件被更改,包括 35 次插入27 次删除
  1. 35 27
      energy/dayTask/ods_to_dwd.sh

+ 35 - 27
energy/dayTask/ods_to_dwd.sh

@@ -18,18 +18,18 @@ SET hive.input.format=org.apache.hadoop.hive.ql.io.HiveInputFormat;
 SET hive.exec.dynamic.partition.mode=nonstrict;"
 
 dwd_energy_15_min_hour="
-with total_energy_hour as (
-    with oe15m_hour as (
-        select building,
-               func_id,
-               meter,
-               data_time,
-               substr(data_time, 0, 13) hour_,
-               data_value,
-               dt
-        from ods_energy_15_min oe15m
-        where dt >= '2022-01-01'
-    )
+insert overwrite table saga_dw.dwd_energy_15_min_hour partition (dt)
+select building,
+       func_id,
+       branch_type,
+       branch_type_name,
+       cast(value_sum as decimal(30, 15)) as value_sum ,
+       hour_ as current_hour,
+       current_year,
+       year_mouth,
+       week_of_year,
+       dt
+from (
     select building,
            func_id,
            branch_type,
@@ -46,7 +46,17 @@ with total_energy_hour as (
              sum(if((branch_type == 'AL' and use_range_type in (2, 3, 4, 6, 7)), data_value, 0)) al_sum,
              dt,
              o15mh.hour_
-      from oe15m_hour o15mh
+      from (
+          select building,
+               func_id,
+               meter,
+               data_time,
+               substr(data_time, 0, 13) hour_,
+               data_value,
+               dt
+        from ods_energy_15_min oe15m
+        where dt >= '2022-01-01'
+           ) o15mh
           left join dim_office_meter dom on o15mh.meter = dom.meter
       where dt >= '2022-01-01' and  branch_type in ('AP', 'AL')
       group by building, func_id, dt, o15mh.hour_ ) t1
@@ -58,22 +68,20 @@ with total_energy_hour as (
            dt,
            o15mh.hour_,
            sum(data_value) value_sum
-    from oe15m_hour o15mh
+    from (
+        select building,
+               func_id,
+               meter,
+               data_time,
+               substr(data_time, 0, 13) hour_,
+               data_value,
+               dt
+        from ods_energy_15_min oe15m
+        where dt >= '2022-01-01'
+         ) o15mh
         left join dim_office_meter dom2 on o15mh.meter = dom2.meter
     group by building, func_id, branch_type, branch_type_name, use_range_type, dt, o15mh.hour_
-)
-insert overwrite table saga_dw.dwd_energy_15_min_hour partition (dt)
-select building,
-       func_id,
-       branch_type,
-       branch_type_name,
-       cast(value_sum as decimal(30, 15)) as value_sum ,
-       hour_ as current_hour,
-       current_year,
-       year_mouth,
-       week_of_year,
-       dt
-from total_energy_hour teh
+     ) teh
     left join dim_date_day ddd on dt = date_id
 order by current_hour;"