实验8-10大数据分析_第1页
实验8-10大数据分析_第2页
实验8-10大数据分析_第3页
实验8-10大数据分析_第4页
实验8-10大数据分析_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验8-10大数据实时分析一、实验目的掌握使用Spark和Hsql进行数据分析的方法。二、数据处理基于Spark引擎来进行数据开发,所有的应用程序都将运行在Spark集群上,这样可以保证数据被高性能地处理,然后使用Zeppelin来快速将数据进行SQL指令交互,使用处理好的数据编写HQL语句并进行实时分析。由于在处理大规模数据时每次都需要占用较长时间,并将计算好的数据直接保存下来,以便快速查询数据结果,因此需要创建应用层表,保存的数据为某天的总订单数。三、实训内容步骤1.总订单笔数1.1创建表创建保存日期对应订单笔数的app表createtableifnotexistsapp_didi.t_order_total(date_valstringcomment'日期(年月日)',countintcomment'订单笔数')partitionedby(monthstringcomment'年月,yyyy-MM')rowformatdelimitedfieldsterminatedby',';1.2加载表--加载数据到app表insertoverwritetableapp_didi.t_order_totalpartition(month='2020-04')select'2020-04-12',count(orderid)astotal_cntfromdw_didi.t_user_order_widewheredt='2020-04-12';2.预约和非预约用户占比2.1创建表--创建保存日期对应订单笔数的app表createtableifnotexistsapp_didi.t_order_subscribe_percent(date_valstringcomment'日期',subscribe_namestringcomment'是否预约',percent_valstringcomment'百分比')partitionedby(monthstringcomment'年月yyyy-MM')rowformatdelimitedfieldsterminatedby',';2.2加载表-加载数据到app表insertoverwritetableapp_didi.t_order_subscribe_percentpartition(month='2020-04')select'2020-04-12','预约',concat(round(t1.total_cnt/t2.total_cnt*100,2),'%')assubscribefrom(selectcount(orderid)astotal_cntfromdw_didi.t_user_order_widewheresubscribe=1anddt='2020-04-12')t1,(selectcount(orderid)astotal_cntfromdw_didi.t_user_order_widewheredt='2020-04-12')t2unionallselect'2020-04-12','非预约',concat(round(t1.total_cnt/t2.total_cnt*100,2),'%')asnosubscribefrom(selectcount(orderid)astotal_cntfromdw_didi.t_user_order_widewheresubscribe=0anddt='2020-04-12')t1,(selectcount(orderid)astotal_cntfromdw_didi.t_user_order_widewheredt='2020-04-12')t2;3不同时段的占比分析3.1创建表--创建APP层表createtableifnotexistsapp_didi.t_order_timerange_total(date_valstringcomment'日期',timerangestringcomment'时间段',countintcomment'订单数量')partitionedby(monthstringcomment'年月,yyyy-MM')rowformatdelimitedfieldsterminatedby',';3.2加载表--加载数据到APP表insertoverwritetableapp_didi.t_order_timerange_totalpartition(month='2020-04')select'2020-04-12',order_time_range,count(*)asorder_cntfromdw_didi.t_user_order_widewheredt='2020-04-12'groupbyorder_time_range;4不同地域订单占比4.1创建表--创建APP表createtableifnotexistsapp_didi.t_order_province_total(date_valstringcomment'日期',provincestringcomment'省份',countintcomment'订单数量')partitionedby(monthstringcomment'年月,yyyy-MM')rowformatdelimitedfieldsterminatedby',';4.2加载表--数据加载到APP表insertoverwritetableapp_didi.t_order_province_totalpartition(month='2020-04')select'2020-04-12',province,count(*)asorder_cntfromdw_didi.t_user_order_widewheredt='2020-04-12'groupbyprovinceorderbyorder_cntdesc;5.不同年龄段,不同时段订单占比5.1创建表createtableifnotexistsapp_didi.t_order_age_and_time_range_total(date_valstringcomment'日期',age_rangestringcomment'年龄段',order_time_rangestringcomment'时段',countintcomment'订单数量')partitionedby(monthstringcomment'年月,yyyy-MM')rowformatdelimitedfieldsterminatedby',';5.2加载表--加载数据到APP表insertoverwritetableapp_didi.t_order_age_and_time_range_totalpartition(month='2020-04')select'2020-04-12',age_range,order_time_range,count(*)asorder_cntfromdw_didi.t_user_order_widewheredt='2020-04-12'groupbyage_range,order_time_range;6不同职业订单统计top56.1创建表createtableifnotexistsapp_didi.t_order_profession_total_topn(date_valstringcomment'日期',professionstringcomment'职业',Order_cntintcomment'订单数量',rkintcomment'排名')partitionedby(monthstringcomment'年月,yyyy-MM')rowformatdelimitedfieldsterminatedby',';6.2加载表insertoverwritetableapp_didi.t_order_profession_total_topnpartition(month='2020-04')select*from(select*,dense_rank()over(orderbytotal_cntdesc)asrkfrom(select'2020-04-12',profession,count(orderid)astotal_cntfromdw_didi.t_user_order_widegroupbyprofession)t)ttwhererk<=3;7.求取消订单百分比7.1创建表--创建app表createtableifnotexistsapp_didi.t_order_cancel_order_percent(date_valstringcomment'日期',cancel_order_percentstringcomment'百分比')partitionedby(monthstringcomment'年月,yyyy-MM')rowformatdelimitedfieldsterminatedby','7.2加载表--插入数据insertoverwritetableapp_didi.t_order_cancel_order_percentpartition(month='2020-04')select'2020-04-12'd

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论