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

1

6

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?

Whistle answered 11/12, 2013 at 19:42 Comment(0)
G
10

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.

Guayule answered 11/12, 2013 at 20:41 Comment(1)
for more info: pig.apache.org/docs/r0.11.1/basic.html#expressions search for "Project-Range Expressions"Hoxie

© 2022 - 2024 — McMap. All rights reserved.