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 8140887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:18:54+00:00 2026-06-06T12:18:54+00:00

I wonder if it’s possible to pivot a table in one pass in Apache

  • 0

I wonder if it’s possible to pivot a table in one pass in Apache Pig.

Input:

Id    Column1 Column2 Column3
1      Row11    Row12   Row13
2      Row21    Row22   Row23

Output:

Id    Name     Value
1     Column1  Row11
1     Column2  Row12
1     Column3  Row13
2     Column1  Row21
2     Column2  Row22
2     Column3  Row23

The real data has dozens of columns.

I can do that with awk in one pass then run it with Hadoop Streaming. But majority of my code is is Apache Pig so I wonder if it’s possible to do it in Pig efficiently.

  • 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-06T12:18:55+00:00Added an answer on June 6, 2026 at 12:18 pm

    You can do it in 2 ways:
    1. Write a UDF which returns a bag of tuples. It will be the most flexible solution, but requires Java code;
    2. Write a rigid script like this:

    inpt = load '/pig_fun/input/pivot.txt' as (Id, Column1, Column2, Column3);
    bagged = foreach inpt generate Id, TOBAG(TOTUPLE('Column1', Column1), TOTUPLE('Column2', Column2), TOTUPLE('Column3', Column3)) as toPivot;
    pivoted_1 = foreach bagged generate Id, FLATTEN(toPivot) as t_value;
    pivoted = foreach pivoted_1 generate Id, FLATTEN(t_value);
    dump pivoted;
    

    Running this script got me following results:

    (1,Column1,11)
    (1,Column2,12)
    (1,Column3,13)
    (2,Column1,21)
    (2,Column2,22)
    (2,Column3,23)
    (3,Column1,31)
    (3,Column2,32)
    (3,Column3,33)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

wonder what's wrong <table id=tblDomainVersion> <tr> <td>Version</td> <td>No of sites</td> </tr> <tr> <td class=clsversion>1.25</td>
wonder whether someone can help me with the following one... I have a struct
I wonder if anyone can help - I want to select a table and
I wonder how it would be possible to implement a positional inverted index in
I wonder whether it is possible to change the display server IP of a
I wonder if it is possible to supress errors in PHP like when redeclaring
I wonder about shared preferences security. Is it possible to get access to sharedpreferences,
Wonder if this possible. Saw many posts on adding watermark after the pdf is
I wonder if it is possible to scale text in the x-axis?
I wonder if it is possible, to stop Maven 3.0 downloading old libraries and

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.