How To
Write simple Interactive JavaScript statements
Lets HD-IN Interactive JavaScript
Interactive Javascript console is a handy tool to execute pig parsing, upload files, run C# streaming Map/Reduce jobs,
Here are some basic commands to get going with interactive Javascripts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
... |
|
|
|
|
|
|
.. |
|
|
..
- Simple Interactive JavaScript statements
Assigning value to variable
|
inputfilelocation = "./input/RealEstate.txt" |
Schema definition:
Pig datatype can be inferred for
schema definition (chararray, bytearray)
If unknown, can be left blank |
schema = "Suburbid:int,proptype:chararray,propsellertype:chararray" |
Filter (Where statement)
|
pig.from(inputfilelocation, schema).where("Suburbid == '2130'").select("Suburbid,proptype,propsellertype") |
Grouping statement
group -> Suburbid
q0 -> output of grouping statement is
always a bag { tuple {}} (refer to Pig output)
Sample output:
2130, {(Contact Owner), (Contact Agent)
, (Contact Agent)}
1231, {(Contact Builder)}
|
output = pig.from(inputfilelocation, schema).groupBy
("Suburbid").select("group , q0.propsellertype").run() |
Group by two columns
Note : SUM can be applied
Sample Output
Contact Agent 2130
2.0
Contact Builder 1231
1.0
|
output = pig.from(inputfilelocation, schema).groupBy
(function() { return [propsellertype, Suburbid ]; }).select
("group.$0, group.$1,SUM(q0.$0)").run() |
Sample Join statement
Note, same input file will not be accepted
|
pig.from("inputfile1", "o1:chararray, o2:chararray, o3:chararray").join
(pig.from("inputfile2","b1:chararray,b2:chararray,b3:chararray"), "$0","$0").select
("*").run() |
- Part 2 will contd soon...
References
- http://social.technet.microsoft.com/wiki/contents/articles/13831.working-with-data-in-windows-azure-hdinsight-service.aspx
- http://social.technet.microsoft.com/wiki/contents/articles/7180.data-visualization-on-the-interactive-javascript-console.aspx.
|