Friday, August 4, 2017

Pivot columns to rows in Apache Pig

Pivot columns to rows in Pig (Apache pig)
==============================

Transposing columns to rows in pig

Data input
id1, col1,col2,col3
id2,col1,col2,col3

Expected o/p
id1 col1 col3
id1 col2 col3
id2 col1 col3
id2 col2 col3


A = LOAD '/home/hadoop/work/surjan/pivotData.txt' using PigStorage(',','-noschema') as (ID: chararray, col2: chararray, col3: chararray,col4:chararray);
B = foreach A generate ID,CONCAT(CONCAT(col2,'#'),col3),col4;
C = foreach B generate ID, FLATTEN(TOKENIZE($1,'#')),col4;
dump C;

2 comments:

  1. It's very useful blog post with inforamtive and insightful content and i had good experience with this information.I have gone through CRS Info Solutions Home which really nice. Learn more details About Us of CRS info solutions. Here you can see the Courses CRS Info Solutions full list. Find Student Registration page and register now. Go through Blog post of crs info solutions. I just read these Reviews of crs really great. You can now Contact Us of crs info solutions. You enroll for Pega Training at crs info solutions.

    ReplyDelete
  2. Big data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. big data projects for students But it’s not the amount of data that’s important. Project Center in Chennai It’s what organizations do with the data that matters. Big data can be analyzed for insights that lead to better decisions and strategic business moves.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Corporate TRaining Spring Framework the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai


    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete