
林子雨编著《大数据基础编程、实验和案例教程(第2版)》(教材官网)教材中的命令行和代码,在纸质教材中的印刷效果不是很好,可能会影响读者对命令行和代码的理解,为了方便读者正确理解命令行和代码或者直接拷贝命令行和代码用于上机实验,这里提供全书配套的所有命令行和代码。
查看教材所有章节的代码
第13章 大数据课程综合实验案例
教材第202页
(温馨提示:代码框上方的复制代码按钮,也就是“两张A4纸图标”,用鼠标点击复制代码按钮,就可以把代码框中的代码复制到粘贴板,粘贴到其他地方。但是,有的浏览器可能不支持该功能)
教材第203页
教材第204页
教材第205页
教材第206页
教材第207页
教材第208页
<pre><code><br />````hive
hive> use dblab; //使用dblab数据库
hive> show tables; //显示数据库中所有表
hive> show create table bigdata_user; //查看bigdata_user表的各种属性;
/p>
h3>教材第209页
/h3>
p>````hive
hive> desc bigdata_user;
/p>
p><pre><code><br />````hive
hive> select * from bigdata_user limit 10;
hive> select behavior_type from bigdata_user limit 10;
/code>
br /> hive> select behavior_type from bigdata_user limit 10; #查看前10位用户对商品的行为
br /> ````hive
br /> hive> select visit_date, item_category from bigdata_user limit 20;
br />
<pre><code> 教材第211页
````hive
hive> select count(*) from bigdata_user;
教材第212页
<pre><code><br />````hive
hive>select count(*) from (select uid,item_id,behavior_type,item_category,visit_date,province from bigdata_user group by uid,item_id,behavior_type,item_category,visit_date,province having count(*)=1)a;
教材第213页
<pre><code><br />````hive
hive> select count(distinct uid), day(visit_date) from bigdata_user where behavior_type='4' group by day(visit_date);
教材第214页
<pre><code><br />````hive
hive> select count(*) from bigdata_user where visit_date='2014-12-11'and behavior_type='4';#查询有多少用户在2014-12-11购买了商品
<pre><code> 教材第215页
````hive
hive> select count(*) from bigdata_user where uid= and visit_date='2014-12-12';#查询用户在2014-12-12点击网站的次数
<pre><code><br />````hive
hive> select uid from bigdata_user where behavior_type='4' and visit_date='2014-12-12' group by uid having count(behavior_type='4')>5;#查询某一天在该网站购买商品超过5次的用户id
````hive
hive> create table scan(province STRING,scan INT) COMMENT 'This is the search of bigdataday' ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' STORED AS TEXTFILE;#创建新的数据表进行存储
hive> insert overwrite table scan select province,count(behavior_type) from bigdata_user where behavior_type='1' group by province;#导入数据
hive> select * from scan;#显示结果
<pre><code> 教材第216页
````hive
hive> create table dblab.user_action(id STRING,uid STRING, item_id STRING, behavior_type STRING, item_category STRING, visit_date DATE, province STRING) COMMENT 'Welcome to XMU dblab! ' ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' STORED AS TEXTFILE;
教材第217页
<pre><code><br />````hive
hive> select * from user_action limit 10;
教材第218页
教材第219页
教材第220页
教材第221页
教材第222页
教材第223页
教材第页226
教材第227页
教材第229页
教材第230页
教材第231页
教材第232页
教材第233页
教材第234页
java基础教程236
教材第235页
教材第236页
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.bianchenghao6.com/h6javajc/19021.html