hive ETL之物流行业-订单跟踪SLA sql
发表于:2025-01-23 作者:千家信息网编辑
千家信息网最后更新 2025年01月23日,-- case1 ----========== order_created ==========--/*10703007267488 2014-05-01 06:01:12.334+011010
千家信息网最后更新 2025年01月23日hive ETL之物流行业-订单跟踪SLA sql
-- case1 ----========== order_created ==========--/*10703007267488 2014-05-01 06:01:12.334+0110101043505096 2014-05-01 07:28:12.342+0110103043509747 2014-05-01 07:50:12.33+0110103043501575 2014-05-01 09:27:12.33+0110104043514061 2014-05-01 09:03:12.324+01*/CREATE EXTERNAL TABLE order_created ( orderNumber STRING , event_time STRING)ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/tmp/db_case1/order_created';CREATE EXTERNAL TABLE order_created_partition ( orderNumber STRING , event_time STRING)PARTITIONED BY (event_month string)ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/tmp/db_case1/order_created_partition';CREATE TABLE order_created_dynamic_partition ( orderNumber STRING , event_time STRING)PARTITIONED BY (event_month string);insert into table order_created_dynamic_partition PARTITION (event_month)select orderNumber, event_time, substr(event_time, 1, 7) as event_month from order_created;set hive.exec.dynamic.partition.mode=nonstrict;/* hive.exec.dynamic.partition=false hive.exec.dynamic.partition.mode=strict hive.exec.max.dynamic.partitions.pernode=100 Maximum number of dynamic partitions allowed to be created in each mapper/reducer node hive.exec.max.dynamic.partitions=1000 Maximum number of dynamic partitions allowed to be created in total hive.exec.max.created.files=100000 Maximum number of HDFS files created by all mappers/reducers in a MapReduce job hive.error.on.empty.partition=false*/select INPUT__FILE__NAME, ordernumber, event_time, BLOCK__OFFSET__INSIDE__FILE / (length(ordernumber) + length(event_time) + 2) + 1 from order_created_dynamic_partition;select INPUT__FILE__NAME, ordernumber, event_time, round(BLOCK__OFFSET__INSIDE__FILE / (length(ordernumber) + length(event_time) + 2) + 1) from order_created_dynamic_partition;desc formatted order_created_dynamic_partition;desc formatted order_created_dynamic_partition partition (event_month='2014-05');CREATE TABLE order_created_dynamic_partition_parquet ( orderNumber STRING , event_time STRING)PARTITIONED BY (event_month string)ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'STORED AS parquet;MSCK REPAIR TABLE order_created_dynamic_partition_parquet;-- set to text file format, bug in hiveALTER TABLE order_created_dynamic_partition_parquet PARTITION (event_month='2014-06') SET SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe';ALTER TABLE order_created_dynamic_partition_parquet PARTITION (event_month='2014-06') SET FILEFORMAT textfile;-- impalaALTER TABLE order_created_dynamic_partition_parquet PARTITION (event_month='2014-06') SET FILEFORMAT textfile;-- set to parquet file format, hive <= 0.12ALTER TABLE order_created_dynamic_partition_parquet PARTITION (event_month='2014-07') SET SERDE 'parquet.hive.serde.ParquetHiveSerDe';ALTER TABLE order_created_dynamic_partition_parquet PARTITION (event_month='2014-07') SET FILEFORMAT INPUTFORMAT 'parquet.hive.DeprecatedParquetInputFormat' OUTPUTFORMAT 'parquet.hive.DeprecatedParquetOutputFormat';-- impala or hive 0.13ALTER TABLE order_created_dynamic_partition_parquet PARTITION (event_month='2014-07') SET FILEFORMAT parquet;insert into table order_created_dynamic_partition_parquet PARTITION (event_month='2014-07') select orderNumber, event_time from order_created;--========== order_picked ==========--/*10703007267488 2014-05-01 07:02:12.334+0110101043505096 2014-05-01 08:29:12.342+0110103043509747 2014-05-01 10:55:12.33+01*/CREATE EXTERNAL TABLE order_picked ( orderNumber STRING , event_time STRING)ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/tmp/db_case1/order_picked';--========== order_shipped ==========--/*10703007267488 2014-05-01 10:00:12.334+0110101043505096 2014-05-01 18:39:12.342+01*/CREATE EXTERNAL TABLE order_shipped ( orderNumber STRING , event_time STRING)ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/tmp/db_case1/order_shipped';--========== order_received ==========--/*10703007267488 2014-05-02 12:12:12.334+01*/CREATE EXTERNAL TABLE order_received ( orderNumber STRING , event_time STRING)ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/tmp/db_case1/order_received';--========== order_cancelled ==========--/*10103043501575 2014-05-01 12:12:12.334+01*/CREATE EXTERNAL TABLE order_cancelled ( orderNumber STRING , event_time STRING)ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/tmp/db_case1/order_cancelled';--=====================================--CREATE TABLE order_tracking ASSELECT orderNumber , max(CASE WHEN type_id="order_created" THEN event_time ELSE '0' END) AS order_created_ts , max(CASE WHEN type_id="order_picked" THEN event_time ELSE '0' END) AS order_picked_ts , max(CASE WHEN type_id="order_shipped" THEN event_time ELSE '0' END) AS order_shipped_ts , max(CASE WHEN type_id="order_received" THEN event_time ELSE '0' END) AS order_received_ts , max(CASE WHEN type_id="order_cancelled" THEN event_time ELSE '0' END) AS order_cancelled_tsFROM ( select orderNumber, "order_created" as type_id, event_time FROM order_created UNION ALL select orderNumber, "order_picked" as type_id, event_time FROM order_picked UNION ALL select orderNumber, "order_shipped" as type_id, event_time FROM order_shipped UNION ALL select orderNumber, "order_received" as type_id, event_time FROM order_received UNION ALL select orderNumber, "order_cancelled" as type_id, event_time FROM order_cancelled) ugroup by orderNumber;select * from order_tracking order by order_created_ts limit 5;--=====================================--CREATE TABLE order_tracking_join ASselect t1.orderNumber , t1.event_time as order_created_ts , t2.event_time as order_picked_ts , t3.event_time as order_shipped_ts , t4.event_time as order_received_ts , t5.event_time as order_cancelled_tsfrom ( select ordernumber, max(event_time) as event_time from order_created group by ordernumber) t1left outer join ( select ordernumber, max(event_time) as event_time from order_picked group by ordernumber) t2on t1.ordernumber = t2.ordernumberleft outer join ( select ordernumber, max(event_time) as event_time from order_shipped group by ordernumber) t3on t1.ordernumber = t3.ordernumberleft outer join ( select ordernumber, max(event_time) as event_time from order_received group by ordernumber) t4on t1.ordernumber = t4.ordernumberleft outer join ( select ordernumber, max(event_time) as event_time from order_cancelled group by ordernumber) t5on t1.ordernumber = t5.ordernumber;select * from order_tracking_join order by order_created_ts limit 5;--=====================================--select orderNumber , order_created_ts , order_picked_ts , order_shipped_ts , order_received_ts , order_cancelled_ts from order_tracking WHERE order_created_ts != '0' AND order_cancelled_ts = '0' AND ( COALESCE(unix_timestamp(order_picked_ts, 'yyyy-MM-dd HH:mm:ss.S'), 0) - unix_timestamp(order_created_ts, 'yyyy-MM-dd HH:mm:ss.S') > 2 * 60 * 60 OR COALESCE(unix_timestamp(order_shipped_ts, 'yyyy-MM-dd HH:mm:ss.S'), 0) - unix_timestamp(order_created_ts, 'yyyy-MM-dd HH:mm:ss.S') > 4 * 60 * 60 OR COALESCE(unix_timestamp(order_shipped_ts, 'yyyy-MM-dd HH:mm:ss.S'), 0) - unix_timestamp(order_created_ts, 'yyyy-MM-dd HH:mm:ss.S') > 48 * 60 * 60 );select orderNumber , order_created_ts , order_picked_ts , order_shipped_ts , order_received_ts , order_cancelled_ts from order_tracking_join WHERE order_created_ts IS NOT NULL AND order_cancelled_ts IS NULL AND ( COALESCE(unix_timestamp(order_picked_ts, 'yyyy-MM-dd HH:mm:ss.S'), 0) - unix_timestamp(order_created_ts, 'yyyy-MM-dd HH:mm:ss.S') > 2 * 60 * 60 OR COALESCE(unix_timestamp(order_shipped_ts, 'yyyy-MM-dd HH:mm:ss.S'), 0) - unix_timestamp(order_created_ts, 'yyyy-MM-dd HH:mm:ss.S') > 4 * 60 * 60 OR COALESCE(unix_timestamp(order_shipped_ts, 'yyyy-MM-dd HH:mm:ss.S'), 0) - unix_timestamp(order_created_ts, 'yyyy-MM-dd HH:mm:ss.S') > 48 * 60 * 60 );
物流
物流行业
行业
订单
跟踪
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全宣传周的小礼物请收下
手机坏怎么倒出数据库
学生阅读软件开发公司
陕西加固服务器云空间
工行软件开发中心好跳槽吗
服务器项目实施方案
国家网络安全以什么为宗旨
软件开发过程及规范电子版
网红经济的网络技术
java怎么实时监控数据库
g口发包服务器渠道
国家网络安全等级
汽修厂网络安全管理
服务器连接显示器没有信号怎么办
法制江西网络安全法
网络安全产业包括哪些
软件开发基本标准和协议
数据库中tr
软件开发需要的笔记本类型
软件开发工作量调整因子
软件开发设计话术
企业用电量数据库
青浦区网络营销软件开发代理商
学生阅读软件开发公司
对身边网络安全认识论文
服务器考题
网络安全监督岗位积极分子
x局网络安全管理制度
网络安全法与酒店
软件开发零基础入门学习