How to write 'foreach' statement for tuple datatype in pig scripts?



How to write 'foreach' statement for tuple datatype in pig scripts?..

Answer / Shailendra Sharma

In Pig, you cannot directly use a 'foreach' loop on tuples like you would in some other programming languages. Instead, you can use the 'FOREACH ... GENERATE' construct to extract individual fields from a tuple one by one. Here's an example:

```pig
my_tuple = (field1, field2, field3);
FOREACH my_tuple GENERATE field1 AS field1, field2 AS field2, field3 AS field3;
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Apache Pig Interview Questions

Why is pig used in hadoop?

1 Answers  


Explain different execution modes available in Pig?

1 Answers  


What are the different modes in which PIG can run and explain those?

1 Answers  


Does Pig differ from MapReduce? If yes, how?

1 Answers  


What is the difference between Pig and SQL?

1 Answers  


Explain about the scalar datatypes in Apache Pig?

1 Answers  


What are the different functions available in pig latin language?

1 Answers  


What are the different Eval functions available in Pig?

1 Answers  


What are different modes of execution in Apache Pig?

1 Answers  


What is Apache Pig?

1 Answers  


What are the Optimizations a developer can use during joins?

1 Answers  


Pig Features ?

1 Answers  


Categories