林子雨编著《大数据基础编程、实验和案例教程(第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表的各种属性;
教材第209页
hive> desc bigdata_user;<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 /> ````hivebr /> hive> select visit_date, item_category from bigdata_user limit 20;br />````hive
hive> select e.bh, e.it from (select behavior_type as bh, item_category as it from bigdata_user) as e limit 20;<pre><code> 教材第211页
````hive
hive> select count(*) from bigdata_user;教材第212页
````hive
hive> select count(distinct uid) from bigdata_user;<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页
````hive
hive> select count(*) from bigdata_user where behavior_type='1' and visit_date<'2014-12-13' and visit_date>'2014-12-10';<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页
````hive
hive> select count(*) from bigdata_user where province='江西' and visit_date='2014-12-12' and behavior_type='4';<pre><code><br />````hive
hive> select count(*) from bigdata_user where visit_date='2014-12-11'and behavior_type='4';#查询有多少用户在2014-12-11购买了商品````hive
hive> select count(*) from bigdata_user where visit_date ='2014-12-11';#查询有多少用户在2014-12-11点击了该店<pre><code> 教材第215页
````hive
hive> select count(*) from bigdata_user where uid= and visit_date='2014-12-12';#查询用户在2014-12-12点击网站的次数````hive
hive> select count(*) from bigdata_user where visit_date='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页
````hive
hive> INSERT OVERWRITE TABLE dblab.user_action select * from dblab.bigdata_user;<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://51itzy.com/kjqy/10162.html