[Solved-1 Solution] Pig referencing ?
- A Pig relation is a bag of tuples. A Pig relation is similar to a table in a relational database, where the tuples in the bag correspond to the rows in a table.
- Unlike a relational table, however, Pig relations don't require that every tuple contain the same number of fields or that the fields in the same position (column) have the same type.
- Also note that relations are unordered which means there is no guarantee that tuples are processed in any particular order. Furthermore, processing may be parallelized in which case tuples are not processed according to any total ordering.
- Relations are referred to by name (or alias). Names are assigned by you as part of the Pig Latin statement. In this example the name (alias) of the relation is A.
- Positional notation is generated by the system. Positional notation is indicated with the dollar sign ($) and begins with zero (0); for example, $0, $1, $2.
- Names are assigned by using schemas (or, in the case of the GROUP operator and some functions, by the system). we can use any name that is not a Pig keyword; for example, f1, f2, f3 or a, b, c or name,
Referencing Fields that are Complex Data Types
The fields in a tuple can be any data type, including the complex data types: bags, tuples, and maps.
- Use the schemas for complex data types to name fields that are complex data types.
- Use the dereference operators to reference and work with fields that are complex data types.
- In this example the data file contains tuples. A schema for complex data types (in this case, tuples) is used to load the data. Then, dereference operators (the dot in t1.t1a and t2.$0) are used to access the fields in the tuples.
The below code using the positional notation
How to reference the elements in apache pig ?
- Let's do a simple Demonstration to understand this problem.
- A file 'a.txt' stored at '/tmp/a.txt'
Folder in HDFS
Now let's group by this Alias 'A' on the basis of some parameter say name and term
Now it has become the problem statement that you have asked. Let me demonstrate you how to access elements of group tuple or element of A tuple or both
So we accessed all elements by this way.