Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a column, preserving the existing columns, without listing them all?

Tags:

apache-pig

I want to add a new column to an alias, preserving all the existing ones.

A = foreach A generate
  A.id as id, 
  A.date as date, 
  A.foo as foo, 
  A.bar as bar, 
  A.foo / A.bar as foobar;

Can I do that without listing all of them explicitly?

like image 648
sds Avatar asked Dec 11 '13 19:12

sds


1 Answers

Yes, let's say you have an alias like:

A: {num1:int, num2:int}

and you want to calculate the sum while keeping num1 and num2. You can do this like:

B = FOREACH A GENERATE *, num1 + num2 AS num3:int ;
DESCRIBE B; 
B: {num1:int, num2:int, num3:int}

Used like this, the * operator generates all fields.

like image 96
mr2ert Avatar answered Oct 09 '22 05:10

mr2ert