Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:23:37+00:00 2026-06-09T07:23:37+00:00

In the following code, how much does renaming fields after a join hurt the

  • 0

In the following code, how much does renaming fields after a join hurt the computation time of the script? Is it optimized in Pig? Or does it really go through every record?

-- tables A: (f1, f2, id)  and B: (g1, g2, id) to be joined by id
C = JOIN A BY id, B by id;
C = FOREACH C GENERATE A::f1 AS f1, A::f2 AS f2, B::id AS id, B::g1 AS g1, B::g2 AS g2;

Does the FOREACH command go through every record of C? If yes, is there a way to optimize?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:23:39+00:00Added an answer on June 9, 2026 at 7:23 am

    Don’t worry about optimizing this, there may be a slight overhead in renaming the fields, but it won’t trigger an addition Map/Reduce job. The field projection will occur in the reducer after your JOIN.

    Consider the two pieces of code and the Map Reduce plans given by explain below.

    Without Renaming

    A = load 'first' using PigStorage() as (f1, f2, id);
    B = load 'second' using PigStorage() as (g1, g2, id);
    
    C = join A by id, B by id;
    
    store C into 'output';
    
    #--------------------------------------------------
    # Map Reduce Plan                                  
    #--------------------------------------------------
    MapReduce node scope-30
    Map Plan
    Union[tuple] - scope-31
    |
    |---C: Local Rearrange[tuple]{bytearray}(false) - scope-20
    |   |   |
    |   |   Project[bytearray][2] - scope-21
    |   |
    |   |---A: New For Each(false,false,false)[bag] - scope-7
    |       |   |
    |       |   Project[bytearray][0] - scope-1
    |       |   |
    |       |   Project[bytearray][1] - scope-3
    |       |   |
    |       |   Project[bytearray][2] - scope-5
    |       |
    |       |---A: Load(hdfs://location/first:PigStorage) - scope-0
    |
    |---C: Local Rearrange[tuple]{bytearray}(false) - scope-22
        |   |
        |   Project[bytearray][2] - scope-23
        |
        |---B: New For Each(false,false,false)[bag] - scope-15
            |   |
            |   Project[bytearray][0] - scope-9
            |   |
            |   Project[bytearray][1] - scope-11
            |   |
            |   Project[bytearray][2] - scope-13
            |
            |---B: Load(hdfs://location/second:PigStorage) - scope-8--------
    Reduce Plan
    C: Store(hdfs://location/output:org.apache.pig.builtin.PigStorage) - scope-27
    |
    |---POJoinPackage(true,true)[tuple] - scope-32--------
    Global sort: false
    ----------------
    

    With Renaming

    A = load 'first' using PigStorage() as (f1, f2, id);
    B = load 'second' using PigStorage() as (g1, g2, id);
    
    C = join A by id, B by id;
    C = foreach C generate A::f1 as f1,  -- This
                           A::f2 as f2,  -- section
                           B::id as id,  -- is
                           B::g1 as g1,  -- different
                           B::g2 as g2;  --
    
    store C into 'output';
    
    #--------------------------------------------------
    # Map Reduce Plan                                  
    #--------------------------------------------------
    MapReduce node scope-41
    Map Plan
    Union[tuple] - scope-42
    |
    |---C: Local Rearrange[tuple]{bytearray}(false) - scope-20
    |   |   |
    |   |   Project[bytearray][2] - scope-21
    |   |
    |   |---A: New For Each(false,false,false)[bag] - scope-7
    |       |   |
    |       |   Project[bytearray][0] - scope-1
    |       |   |
    |       |   Project[bytearray][1] - scope-3
    |       |   |
    |       |   Project[bytearray][2] - scope-5
    |       |
    |       |---A: Load(hdfs://location/first:PigStorage) - scope-0
    |
    |---C: Local Rearrange[tuple]{bytearray}(false) - scope-22
        |   |
        |   Project[bytearray][2] - scope-23
        |
        |---B: New For Each(false,false,false)[bag] - scope-15
            |   |
            |   Project[bytearray][0] - scope-9
            |   |
            |   Project[bytearray][1] - scope-11
            |   |
            |   Project[bytearray][2] - scope-13
            |
            |---B: Load(hdfs://location/second:PigStorage) - scope-8--------
    Reduce Plan
    C: Store(hdfs://location/output:org.apache.pig.builtin.PigStorage) - scope-38
    |
    |---C: New For Each(false,false,false,false,false)[bag] - scope-37
        |   |
        |   Project[bytearray][0] - scope-27
        |   |
        |   Project[bytearray][1] - scope-29
        |   |
        |   Project[bytearray][5] - scope-31
        |   |
        |   Project[bytearray][3] - scope-33
        |   |
        |   Project[bytearray][4] - scope-35
        |
        |---POJoinPackage(true,true)[tuple] - scope-43--------
    Global sort: false
    ----------------
    

    The difference is in the Reduce plans. Without renaming:

    Reduce Plan
    C: Store(hdfs://location/output:org.apache.pig.builtin.PigStorage) - scope-27
    |
    |---POJoinPackage(true,true)[tuple] - scope-32--------
    Global sort: false
    

    versus with renaming:

    Reduce Plan
    C: Store(hdfs://location/output:org.apache.pig.builtin.PigStorage) - scope-38
    |
    |---C: New For Each(false,false,false,false,false)[bag] - scope-37
        |   |
        |   Project[bytearray][0] - scope-27
        |   |
        |   Project[bytearray][1] - scope-29
        |   |
        |   Project[bytearray][5] - scope-31
        |   |
        |   Project[bytearray][3] - scope-33
        |   |
        |   Project[bytearray][4] - scope-35
        |
        |---POJoinPackage(true,true)[tuple] - scope-43--------
    Global sort: false
    

    In short, there will be other things you can optimize in your script before worrying about renaming. Since you’ll be going through every record anyway because of the join, renaming will just be a cheap extra step.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found the following code in SO. Does this really work? String xml =
The following code seems to be just too much, for getting a single count
I have written a code and i'm pretty much stuck. In the following code,
Despite being a Project Euler program, the following code doesn't actually concern it much.
The following linq2sql code is causing me much headache and I was hoping someone
How much faster is the following assembler code: shl ax, 1 Versus the following
The following code is supposed to perform an AJAX request after the page loads,
I have the following code: Note: I simplified the code as much as possible
I have spent the last few hours putting togeather the following code after reading
So I have the following code which I pretty much copied from here .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.