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  

proplistingid
 
Suburbid
 
proptype
 
propsellertype
 
 propprice
 
postedon
   
10100
 
2130
 
Land
 
Contact Owner
   
....
 
10101
 
1231
 
House
 
Contact Builder
   ...  
10102
 
2130
 
Land
 
Contact Agent
     ..  
2341
 
House
 .. t-size:8px;"> 
 
 ..  
2341
Contact Builder
   
 ..  
2456
 
Land
 
Contact Owner
   
 ..  
2130
 
Land
 
Contact Agent
   
                                            

 
 Task 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()
   

References