Simple Example Use Cases

MovieLens User Ratings

First, create a table with tab-delimited text file format:

CREATE TABLE u_data (
userid INT,
movieid INT,
rating INT,
unixtime STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE;

Then, download the data files from MovieLens 100k on the GroupLens datasets page (which also has a README.txt file and index of unzipped files):

wget http://files.grouplens.org/datasets/movielens/ml-100k.zip

or:

curl --remote-name http://files.grouplens.org/datasets/movielens/ml-100k.zip

Note:  If the link to GroupLens datasets does not work, please report it on HIVE-5341 or send a message to the user@hive.apache.org mailing list.

Unzip the data files:

unzip ml-100k.zip

And load u.data into the table that was just created:

LOAD DATA LOCAL INPATH '<path>/u.data'
OVERWRITE INTO TABLE u_data;

Count the number of rows in table u_data:

SELECT COUNT(*) FROM u_data;

Note that for older versions of Hive which don't include HIVE-287, you'll need to use COUNT(1) in place of COUNT(*).

Now we can do some complex data analysis on the table u_data:

Create weekday_mapper.py:

import sys
import datetime for line in sys.stdin:
line = line.strip()
userid, movieid, rating, unixtime = line.split('\t')
weekday = datetime.datetime.fromtimestamp(float(unixtime)).isoweekday()
print '\t'.join([userid, movieid, rating, str(weekday)])

https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-DDLOperations

Use the mapper script:

CREATE TABLE u_data_new (
userid INT,
movieid INT,
rating INT,
weekday INT)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'; add FILE weekday_mapper.py; INSERT OVERWRITE TABLE u_data_new
SELECT
TRANSFORM (userid, movieid, rating, unixtime)
USING 'python weekday_mapper.py'
AS (userid, movieid, rating, weekday)
FROM u_data; SELECT weekday, COUNT(*)
FROM u_data_new
GROUP BY weekday;

STREAMING HIVE流过滤 官网例子 注意中间用的py脚本的更多相关文章

  1. OpenLayers 官网例子的中文详解

    https://segmentfault.com/a/1190000009679800?utm_source=tag-newest 当你希望实现某种功能的时候,即使你对 openlayers 几乎一窍 ...

  2. 针对Openlayer3官网例子的简介

    网址:http://openlayers.org/en/latest/examples/ 如果大家想了解ol3能做什么,或者说已提供的API有什么,又闲一个个翻例子跟API累的话,就看看这个吧. 1. ...

  3. Vue组件化应用构建 官网例子 Unknown custom element: <todo-item>

     [博客园cnblogs笔者m-yb原创,转载请加本文博客链接,笔者github: https://github.com/mayangbo666,公众号aandb7,QQ群927113708] htt ...

  4. 【转】一个lucene的官网例子

    创建索引: import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import jav ...

  5. 导航条且手机版.html——仿照官网例子

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. 官网例子,mt-field password获取不到

    新尝试了Mint-UI,在使用表单组件Field时, 直接从demo中拷贝了如下代码: <mt-field label="username" placeholder=&quo ...

  7. three.js的wave特效(ivew官网首页波浪特效实现)

    查看效果请访问:https://521lbx.github.io/Web3D/index.html公司的好几个vue项目都是用ivew作为UI框架,所以ivew官网时不时就得逛一圈.每一次进首页都会被 ...

  8. Java微信扫描支付模式二Demo ,整合官网直接运行版本

    概述 场景介绍 用户使用微信“扫一扫”扫描二维码后,获取商品支付信息,引导用户完成支付. 详细 代码下载:http://www.demodashi.com/demo/13880.html 一.相关配置 ...

  9. 【慕课网实战】Spark Streaming实时流处理项目实战笔记十四之铭文升级版

    铭文一级: 第11章 Spark Streaming整合Flume&Kafka打造通用流处理基础 streaming.conf agent1.sources=avro-sourceagent1 ...

随机推荐

  1. 论文笔记:Deep feature learning with relative distance comparison for person re-identification

    这篇论文是要解决 person re-identification 的问题.所谓 person re-identification,指的是在不同的场景下识别同一个人(如下图所示).这里的难点是,由于不 ...

  2. linux文件系统初始化过程(4)---加载initrd(中)

    一.目的 上文详细介绍了CPIO格式的initrd文件,本文从源代码角度分析加载并解析initrd文件的过程. initrd文件和linux内核一般存储在磁盘空间中,在系统启动阶段由bootload负 ...

  3. GNU MAKE参考文档

    1.GNU MAKE翻译 https://blog.csdn.net/xiejinfeng850414/article/details/8625468 2.Linux Makefile 生成 *.d ...

  4. Laravel 开发环境搭建 - Windows

    Laravel 开发环境搭建 - Windows  :   https://laravel-china.org/docs/laravel-development-environment/5.5/dev ...

  5. linux在telnet情况下root登录提示login incorrect

    root登录时总是提示 login incorrect SSH可以登录 别的用户也可以通过telnet登录 唯独root不可以   解决方法: vi /etc/pam.d/login # auth r ...

  6. Windows安装activemq

    1.Windows下载解压就可以了,官网:http://activemq.apache.org/ 8161查看端口 61616消息服务端口 2.浏览器访问localhost:8161测试 3.可以在c ...

  7. springboot配置详解

    springboot配置详解 Author:SimpleWu properteis文件属性参考大全 springboot默认加载配置 SpringBoot使用两种全局的配置文件,全局配置文件可以对一些 ...

  8. python计算文件的行数的方法

    1.简单方法把文件读入一个大的列表中,然后统计列表的长度.   count = len(open("文件名").readlines()) print count 2.读取文件某一行 ...

  9. 论文阅读笔记四十三:DeeperLab: Single-Shot Image Parser(CVPR2019)

    论文原址:https://arxiv.org/abs/1902.05093 github:https://github.com/lingtengqiu/Deeperlab-pytorch 摘要 本文提 ...

  10. Gerapy框架的使用

    Gerapy 基于Scrapy,Scrapyd,Scrapyd-Client,Scrapyd-API,Django和Vue.js的分布式爬虫管理框架. 支持 Gerapy是在Python 3.x上开发 ...