set hive.exec.dynamic.partition.mode=nonstrict; set hive.exec.parallel=true; set hive.exec.parallel.thread.number=30; --drop table if exists dm_finrisk.dm_event_walletSettleSuccessEvent_di; create table if not exists dm_finrisk.dm_event_cashLoanEvent_di( event_uuid string ,event_code string ,dt string ,event_time string ,rawSnapshot string ) COMMENT 'cashLoanEvent' PARTITIONED BY ( day bigint)stored as parquet; drop table if exists tmp.tmp_dm_event_cashLoanEvent_di_01_${zdt.addDay(-1).format("yyyyMMdd")}; create table if not exists tmp.tmp_dm_event_cashLoanEvent_di_01_${zdt.addDay(-1).format("yyyyMMdd")} as select uuid as event_uuid ,event as event_code ,from_unixtime(unix_timestamp(cast(day as string),'yyyymmdd'),'yyyy-mm-dd') as dt ,from_unixtime(cast(cast(`time` AS BIGINT)/1000 AS BIGINT),'yyyy-MM-dd HH:mm:ss') as event_time ,get_json_object(data,'$.hotPublish.rawSnapshot') as rawSnapshot from dm_finrisk.ods_event_hdfs_snapshot_di where code = 'shield@cashLoanEvent' and day=${zdt.addDay(-1).format("yyyyMMdd")} drop table if exists tmp.tmp_dm_event_cashLoanEvent_di_02_${zdt.addDay(-1).format("yyyyMMdd")}; create table if not exists tmp.tmp_dm_event_cashLoanEvent_di_02_${zdt.addDay(-1).format("yyyyMMdd")} as select event_uuid ,event_code ,dt ,event_time ,rawSnapshot from tmp.tmp_dm_event_cashLoanEvent_di_01_${zdt.addDay(-1).format("yyyyMMdd")}; alter table dm_finrisk.dm_event_cashLoanEvent_di drop if exists partition (day = ${zdt.addDay(-1).format("yyyyMMdd")}); insert overwrite table dm_finrisk.dm_event_cashLoanEvent_di partition (day = ${zdt.addDay(-1).format("yyyyMMdd")}) select event_uuid ,event_code ,dt ,event_time ,rawSnapshot from tmp.tmp_dm_event_cashLoanEvent_di_02_${zdt.addDay(-1).format("yyyyMMdd")}分析下上面代码
时间: 2024-04-22 13:21:47 浏览: 10
上面的代码主要是一个HiveQL脚本,用于从`dm_finrisk.ods_event_hdfs_snapshot_di`表中提取`code`为`shield@cashLoanEvent`且`day`为昨天日期的数据,并将其存储到`dm_finrisk.dm_event_cashLoanEvent_di`表中的对应分区中。
具体来说,该脚本的执行步骤如下:
1. 第1行:设置Hive执行参数,包括动态分区模式、并行执行和并行执行线程数等。
2. 第3-8行:创建`dm_finrisk.dm_event_cashLoanEvent_di`表,该表包含5个列,分别为`event_uuid`、`event_code`、`dt`、`event_time`和`rawSnapshot`,其中`dt`为分区列。
3. 第10-15行:创建临时表`tmp.tmp_dm_event_cashLoanEvent_di_01_${zdt.addDay(-1).format("yyyyMMdd")}`,该表从`dm_finrisk.ods_event_hdfs_snapshot_di`表中选择`code`为`shield@cashLoanEvent`且`day`为昨天日期的记录,并将其中的`uuid`、`event`、`day`、`time`和`data`字段分别映射到`event_uuid`、`event_code`、`dt`、`event_time`和`rawSnapshot`列中。
4. 第17-22行:创建临时表`tmp.tmp_dm_event_cashLoanEvent_di_02_${zdt.addDay(-1).format("yyyyMMdd")}`,该表从临时表`tmp.tmp_dm_event_cashLoanEvent_di_01_${zdt.addDay(-1).format("yyyyMMdd")}`中选择所有列,用于后续的数据处理。
5. 第24行:如果`dm_finrisk.dm_event_cashLoanEvent_di`表中昨天的分区已经存在,则删除该分区。
6. 第26-27行:将临时表`tmp.tmp_dm_event_cashLoanEvent_di_02_${zdt.addDay(-1).format("yyyyMMdd")}`中的数据插入到`dm_finrisk.dm_event_cashLoanEvent_di`表的昨天分区中。
整个脚本的作用是将来自`dm_finrisk.ods_event_hdfs_snapshot_di`表的特定数据提取出来,并存储到`dm_finrisk.dm_event_cashLoanEvent_di`表的对应分区中,以便后续的分析和查询。