Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to install and use the Pig framework

Shulou Source: shulou.com Published: 2022-06-01 02:15:41 11月10日 Update

This article will explain in detail how to install and use the Pig framework. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Pig is a framework for computing using mapreduce. Has its own set of syntax Pig latin, can be very convenient to write calculation code.

1. How to use Pig?

After unzipping, modify the file conf/pig.properties and add two lines, as follows:

Fs.default.name=hdfs://hadoop0:9000

Mapred.job.tracker=hadoop0:9001

After saving and exiting, execute bin/pig on the command line.

2. Use pig to complete telecom mobile phone number traffic statistics example:

# loading data in hdfs

The A here is an alias.

A = LOAD'/ Kpi' AS (f _ 0 _ v _ r _ 1 _ L _ 1 _ L _ 2R _ r _ 3R _ r _ r _ 4R _ array)

DUMP A; / / View result A

# filter useful fields in A

B = FOREACH A GENERATE F1, f2, f3, 4

DUMP B; / / View result B

# grouping records in B according to F1

C = GROUP B BY F1

DUMP C; / / View result C

# accumulate the grouped records according to the grouped field

D = FOREACH C GENERATE group, SUM (B.f1), SUM (B.f2), SUM (B.f3)

DUMP D; / / View result D

# Save the final result to HDFS

STORE D INTO'/ out'

3. The above Pig commands can be put into a file. The contents of the execution file are as follows, and the execution method is pig kpi.pig

The content is the same as above.

This is the end of the article on "how to install and use the Pig Framework". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Results content frames files articles groups commands fields more good practical code examples aliases numbers mobile phones mobile numbers data articles methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Shulou Technology Redmi NVidia