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 |
Why is pig used in hadoop?
Explain different execution modes available in Pig?
What are the different modes in which PIG can run and explain those?
Does Pig differ from MapReduce? If yes, how?
What is the difference between Pig and SQL?
Explain about the scalar datatypes in Apache Pig?
What are the different functions available in pig latin language?
What are the different Eval functions available in Pig?
What are different modes of execution in Apache Pig?
What is Apache Pig?
What are the Optimizations a developer can use during joins?
Pig Features ?
Apache Hadoop (394)
MapReduce (354)
Apache Hive (345)
Apache Pig (225)
Apache Spark (991)
Apache HBase (164)
Apache Flume (95)
Apache Impala (72)
Apache Cassandra (392)
Apache Mahout (35)
Apache Sqoop (82)
Apache ZooKeeper (65)
Apache Ambari (93)
Apache HCatalog (34)
Apache HDFS Hadoop Distributed File System (214)
Apache Kafka (189)
Apache Avro (26)
Apache Presto (15)
Apache Tajo (26)
Hadoop General (407)