[Solved-2 Solutions] How to “update” a column using pig latin ?



Problem:

How to “update” a column using pig latin ?

Solution 1:

The following solution helps to update the columns

  • We can select columns by column number, but that can easily become a nightmare if we change anything at all. we have found column names to be much more stable, and therefore we recommend the following solution:

Update mycol when it is between two known columns

  • We can use .. to indicate leading, or trailing columns (or inbetween columns). Here is how that would work out if we want to change the value of 'MyCol' to 'updatedvalue'.
aliasAfter = FOREACH aliasBefore GENERATE 
             .. colBeforeMyCol, updatedvalue, colAfterMyCol ..;

Solution 2:

A feature to facilitate to added in Pig 0.9. The new project-range operator (..) allows us to express a range of fields by indicating the starting and/or ending field names.

Example:

result = FOREACH someInput GENERATE field1, field2, null as field3, field4 .. ;
  • In the example above field1/2/3/4 are actual field names. One of the fields is set to null while the other fields are kept intact.

Related Searches to How to “update” a column using pig latin