阿里云E-MapReduce Pig 作业配置

本文涉及的产品
对象存储 OSS,20GB 3个月
对象存储 OSS,内容安全 1000次 1年
EMR Serverless StarRocks,5000CU*H 48000GB*H
简介:

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.选择执行失败后策略。
相关实践学习
基于EMR Serverless StarRocks一键玩转世界杯
基于StarRocks构建极速统一OLAP平台
快速掌握阿里云 E-MapReduce
E-MapReduce 是构建于阿里云 ECS 弹性虚拟机之上,利用开源大数据生态系统,包括 Hadoop、Spark、HBase,为用户提供集群、作业、数据等管理的一站式大数据处理分析服务。 本课程主要介绍阿里云 E-MapReduce 的使用方法。
相关文章
|
6月前
|
存储 分布式计算 监控
Hadoop【基础知识 01+02】【分布式文件系统HDFS设计原理+特点+存储原理】(部分图片来源于网络)【分布式计算框架MapReduce核心概念+编程模型+combiner&partitioner+词频统计案例解析与进阶+作业的生命周期】(图片来源于网络)
【4月更文挑战第3天】【分布式文件系统HDFS设计原理+特点+存储原理】(部分图片来源于网络)【分布式计算框架MapReduce核心概念+编程模型+combiner&partitioner+词频统计案例解析与进阶+作业的生命周期】(图片来源于网络)
299 2
|
3月前
|
分布式计算 资源调度 监控
MapReduce程序中的主要配置参数详解
【8月更文挑战第31天】
73 0
|
5月前
|
分布式计算 Java Hadoop
实现多文件合并和去重的MapReduce作业
实现多文件合并和去重的MapReduce作业
130 0
|
5月前
|
分布式计算 大数据
mapreduce 实现带有ex前缀的词频统计wordcount 大作业
mapreduce 实现带有ex前缀的词频统计wordcount 大作业
|
6月前
|
数据采集 分布式计算 DataWorks
DataWorks产品使用合集之在DataWorks中,在MapReduce作业中指定两个表的所有分区如何解决
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。
80 0
|
6月前
|
分布式计算 监控 Hadoop
Hadoop【基础知识 02】【分布式计算框架MapReduce核心概念+编程模型+combiner&partitioner+词频统计案例解析与进阶+作业的生命周期】(图片来源于网络)
【4月更文挑战第3天】Hadoop【基础知识 02】【分布式计算框架MapReduce核心概念+编程模型+combiner&partitioner+词频统计案例解析与进阶+作业的生命周期】(图片来源于网络)
263 0
|
SQL 分布式计算 算法
|
机器人 大数据
E-MapReduce工作流配置钉钉群告警
E-MapReduce工作流配置钉钉群告警
E-MapReduce工作流配置钉钉群告警
|
分布式计算 资源调度 Hadoop
Hadoop运行模式(二)、SSH无密登录配置、生成公钥和私钥、集群配置、集群部署规划、默认配置文件、核心配置文件、HDFS配置文件、YARN配置文件、MapReduce配置文件、在集群上分发配置好的
ssh文件夹下(~/.ssh)的文件功能解释、ssh连接时出现Host key verification failed的解决方法、免密登录原理、将公钥拷贝到要免密登录的目标机器上、NameNode和SecondaryNameNode不要安装在同一台服务器、ResourceManager也很消耗内存,不要和NameNode、SecondaryNameNode配置在同一台机器上、Hadoop配置文件分两类:默认配置文件和自定义配置文件,只有用户想修改某一默认配置值时,才需要修改自定义配置文件,更改相应属性值、.
533 1
Hadoop运行模式(二)、SSH无密登录配置、生成公钥和私钥、集群配置、集群部署规划、默认配置文件、核心配置文件、HDFS配置文件、YARN配置文件、MapReduce配置文件、在集群上分发配置好的

热门文章

最新文章