阿里云E-MapReduce Pig 作业配置

本文涉及的产品
对象存储 OSS,20GB 3个月
对象存储 OSS,恶意文件检测 1000次 1年
对象存储 OSS,内容安全 1000次 1年
简介:

E-MapReduce 中,用户申请集群的时候,默认为用户提供了 Pig 环境,用户可以直接使用 Pig 来创建和操作自己的表和数据。操作步骤如下。

1.用户需要提前准备好 Pig 的脚本,例如:

/*

  • Licensed to the Apache Software Foundation (ASF) under one
  • or more contributor license agreements. See the NOTICE file
  • distributed with this work for additional information
  • regarding copyright ownership. The ASF licenses this file
  • to you under the Apache License, Version 2.0 (the
  • "License"); you may not use this file except in compliance
  • with the License. You may obtain a copy of the License at
    *
  • http://www.apache.org/licenses/LICENSE-2.0
    *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */

-- Query Phrase Popularity (Hadoop cluster)
-- This script processes a search query log file from the Excite search engine and finds search phrases that occur with particular high frequency during certain times of the day.
-- Register the tutorial JAR file so that the included UDFs can be called in the script.
REGISTER oss://emr/checklist/jars/chengtao/pig/tutorial.jar;
-- Use the PigStorage function to load the excite log file into the “raw” bag as an array of records.
-- Input: (user,time,query)
raw = LOAD 'oss://emr/checklist/data/chengtao/pig/excite.log.bz2' USING PigStorage('t') AS (user, time, query);
-- Call the NonURLDetector UDF to remove records if the query field is empty or a URL.
clean1 = FILTER raw BY org.apache.pig.tutorial.NonURLDetector(query);
-- Call the ToLower UDF to change the query field to lowercase.
clean2 = FOREACH clean1 GENERATE user, time, org.apache.pig.tutorial.ToLower(query) as query;
-- Because the log file only contains queries for a single day, we are only interested in the hour.
-- The excite query log timestamp format is YYMMDDHHMMSS.
-- Call the ExtractHour UDF to extract the hour (HH) from the time field.
houred = FOREACH clean2 GENERATE user, org.apache.pig.tutorial.ExtractHour(time) as hour, query;
-- Call the NGramGenerator UDF to compose the n-grams of the query.
ngramed1 = FOREACH houred GENERATE user, hour, flatten(org.apache.pig.tutorial.NGramGenerator(query)) as ngram;
-- Use the DISTINCT command to get the unique n-grams for all records.
ngramed2 = DISTINCT ngramed1;
-- Use the GROUP command to group records by n-gram and hour.
hour_frequency1 = GROUP ngramed2 BY (ngram, hour);
-- Use the COUNT function to get the count (occurrences) of each n-gram.
hour_frequency2 = FOREACH hour_frequency1 GENERATE flatten($0), COUNT($1) as count;
-- Use the GROUP command to group records by n-gram only.
-- Each group now corresponds to a distinct n-gram and has the count for each hour.
uniq_frequency1 = GROUP hour_frequency2 BY group::ngram;
-- For each group, identify the hour in which this n-gram is used with a particularly high frequency.
-- Call the ScoreGenerator UDF to calculate a "popularity" score for the n-gram.
uniq_frequency2 = FOREACH uniq_frequency1 GENERATE flatten($0), flatten(org.apache.pig.tutorial.ScoreGenerator($1));
-- Use the FOREACH-GENERATE command to assign names to the fields.
uniq_frequency3 = FOREACH uniq_frequency2 GENERATE $1 as hour, $0 as ngram, $2 as score, $3 as count, $4 as mean;
-- Use the FILTER command to move all records with a score less than or equal to 2.0.
filtered_uniq_frequency = FILTER uniq_frequency3 BY score > 2.0;
-- Use the ORDER command to sort the remaining records by hour and score.
ordered_uniq_frequency = ORDER filtered_uniq_frequency BY hour, score;
-- Use the PigStorage function to store the results.
-- Output: (hour, n-gram, score, count, average_counts_among_all_hours)
STORE ordered_uniq_frequency INTO 'oss://emr/checklist/data/chengtao/pig/script1-hadoop-results' USING PigStorage();

2.将该脚本保存到一个脚本文件中,例如叫 script1-hadoop-oss.pig,然后将该脚本上传到 OSS 的某个目录中(例如:oss://path/to/script1-hadoop-oss.pig)。

3.进入阿里云 E-MapReduce 控制台作业列表。

4.单击该页右上角的创建作业,进入创建作业页面。

5.填写作业名称。

6.选择 Pig 作业类型,表示创建的作业是一个 Pig 作业。这种类型的作业,其后台实际上是通过以下的方式提交。

`pig [user provided parameters]`
7.在应用参数选项框中填入 Pig 命令后续的参数。例如,如果需要使用刚刚上传到 OSS 的 Pig 脚本,则填写如下:

`-x mapreduce ossref://emr/checklist/jars/chengtao/pig/script1-hadoop-oss.pig`
您也可以单击选择 OSS 路径,从 OSS 中进行浏览和选择,系统会自动补齐 OSS 上 Pig 脚本的绝对路径。请务必将 Pig 脚本的前缀修改为 ossref(单击切换资源类型),以保证 E-MapReduce 可以正确下载该文件。

8.选择执行失败后策略。
相关实践学习
数据湖构建DLF快速入门
本教程通过使⽤数据湖构建DLF产品对于淘宝用户行为样例数据的分析,介绍数据湖构建DLF产品的数据发现和数据探索功能。
快速掌握阿里云 E-MapReduce
E-MapReduce 是构建于阿里云 ECS 弹性虚拟机之上,利用开源大数据生态系统,包括 Hadoop、Spark、HBase,为用户提供集群、作业、数据等管理的一站式大数据处理分析服务。 本课程主要介绍阿里云 E-MapReduce 的使用方法。
相关文章
|
21天前
|
编解码 对象存储
阿里云视频转码转码模板-配置工作流
阿里云视频转码转码模板-配置工作流
14 0
|
1月前
|
SQL 分布式计算 关系型数据库
阿里云E-MapReduce Trino专属集群外连引擎及权限控制踩坑实践
本文以云厂商售后技术支持的角度,从客户的需求出发,对于阿里云EMR-Trino集群的选型,外连多引擎的场景、Ldap以及Kerberos鉴权等问题进行了简要的实践和记录,模拟客户已有的业务场景,满足客户需求的同时对过程中的问题点进行解决、记录和分析,包括但不限于Mysql、ODPS、Hive connector的配置,Hive、Delta及Hudi等不同表格式读取的兼容,aws s3、阿里云 oss协议访问异常的解决等。
|
20天前
|
弹性计算
2024年阿里云服务器不同实例规格与配置实时优惠价格整理与分享
2024年阿里云服务器的优惠价格新鲜出炉,有特惠云服务器也有普通优惠价格,本文为大家整理汇总了2024年阿里云服务器的优惠价格,包含特惠云服务器和其他配置云服务器的优惠价格。以便大家了解自己想购买的云服务器选择不同实例规格和带宽情况下的价格,仅供参考。
2024年阿里云服务器不同实例规格与配置实时优惠价格整理与分享
|
21天前
阿里云配置dcoker镜像仓库
阿里云配置dcoker镜像仓库
70 0
|
1月前
|
弹性计算 缓存 数据库
阿里云服务器2核4G多少钱?阿里云服务器2核4G配置优惠价格
阿里云服务器2核4G多少钱?阿里云服务器2核4G配置优惠价格表,2核4G配置1个月多少钱?2核4G服务器30元3个月、轻量应用服务器2核4G4M带宽165元一年、企业用户2核4G5M带宽199元一年
|
2天前
|
存储 弹性计算 安全
阿里云服务器2核2G、2核4G配置最新租用收费标准及活动价格参考
2核2G、2核4G配置是很多个人和企业建站以及部署中小型的web应用等场景时首选的云服务器配置,这些配置的租用价格也是用户非常关心的问题,本文为大家整理汇总了2024年阿里云服务器2核2G、2核4G配置不同实例规格及地域之间的收费标准,同时整理了这些配置最新活动价格,以供大家参考和选择。
阿里云服务器2核2G、2核4G配置最新租用收费标准及活动价格参考
|
5天前
|
域名解析 网络协议 应用服务中间件
阿里云服务器配置免费https服务
阿里云服务器配置免费https服务
|
25天前
|
弹性计算 固态存储 调度
2024年阿里云服务器配置选择指南,新手整理
阿里云服务器配置选择指南:个人用户推荐轻量应用服务器或ECS通用算力型u1,适合小型网站和轻量应用。企业用户应选择企业级独享型如ECS计算型c7、通用型g7,保证高性能计算需求。配置选择要考虑CPU内存比例、公网带宽和系统盘。轻量服务器提供2核2G3M和2核4G4M选项,ECS实例则有多种规格以适应不同业务场景。公网带宽建议至少5M,系统盘可选高效云盘、SSD或ESSD。详细信息见[阿里云服务器产品页](https://www.aliyun.com/product/ecs)。
60 3
|
29天前
|
存储 弹性计算 运维
阿里云轻量应用服务器与标准型阿里云服务器ECS全面对比(配置、价格)
随着云计算技术的蓬勃发展,阿里云作为业界的佼佼者,推出了多样化的云服务器产品以满足不同用户群体的需求。在这些产品中,阿里云轻量应用服务器与标准云服务器(ECS)因其各自的特点而备受关注。下面,我们将从多个角度对这两款产品进行深入剖析,以帮助您更好地选择适合自身需求的云服务器。
644 2
|
29天前
|
存储 弹性计算 安全
阿里云2核8G配置服务器租用价格多少?
随着云计算技术的飞速发展,越来越多的企业和个人开始青睐云服务器,将其视为数据存储和运算的理想平台。而在这其中,阿里云作为国内领先的云服务提供商,其ECS云服务器以其卓越的性能和稳定的服务,赢得了广大用户的信赖与喜爱。那么,对于许多用户来说,他们可能好奇的是,阿里云2核8G服务器一年的费用究竟是多少呢?
97 1