Configure a Pig job
Updated at:
This topic describes how to configure a Pig job.
Prerequisites
- You have created a project. For more information, see Project Management.
- You have a Pig script ready. The following code is an example:
/* * 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 high frequency during certain times of the day. -- Register the tutorial JAR file to use the included UDFs. 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 generate 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 the n-gram is used with a 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 remove 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 count across all hours) STORE ordered_uniq_frequency INTO 'oss://emr/checklist/data/chengtao/pig/script1-hadoop-results' USING PigStorage(); - You have saved the script as script1-hadoop-oss.pig and uploaded it to an OSS directory, such as oss://path/to/script1-hadoop-oss.pig.
Procedure
-
Go to the Projects page in Data Platform.
-
Log in to the E-MapReduce console with your Alibaba Cloud account.
-
In the top navigation bar, select the region and resource group.
-
Click the Data Development tab.
-
-
In the row of the project you want to edit, click Edit Job.
- Create a Pig job.
- On the left side of the page, right-click the target folder and select Create Job.
- In the Create Job dialog box, enter a Job Name and Description. From the Job Type drop-down list, select Pig.
The job is submitted using the following command:
pig [user provided parameters] - Click OK.
- Edit the job content.
- In the Content field, enter the required command line parameters.
For example, to run a Pig script from OSS, enter the following:
-x mapreduce ossref://emr/checklist/jars/chengtao/pig/script1-hadoop-oss.pigNote You can also click + Insert an OSS path below the field. Set File Prefix to OSSREF and select your script from the File Path list. The system automatically fills in the Pig script's OSS path. - Click Save.
- In the Content field, enter the required command line parameters.
Is this page helpful?