MCPcopy Create free account
hub / github.com/apache/pig / exec

Method exec

src/org/apache/pig/builtin/COR.java:189–243  ·  view source on GitHub ↗
(Tuple input)

Source from the content-addressed store, hash-verified

187 }
188
189 @Override
190 public DataBag exec(Tuple input) throws IOException {
191 if (input == null || input.size() == 0)
192 return null;
193
194 Tuple combined;
195 try{
196 combined = combine((DataBag)input.get(0));
197 }catch(Exception e){
198 throw new IOException("Caught exception in COR.Final", e);
199 }
200 int count = 0;
201 //for each pair of input schema combined contain 2 member. first member
202 //is tuple containing sum_x,sum_y,sum_x_y, sum_x_square, sum_y_square
203 //and second is number of tuples from which it is calculated .
204 //So if arity of combined is n then total number of schemas would be
205 //root of x*x - x - n =0
206 int totalSchemas=2;
207 while(totalSchemas*(totalSchemas-1)<combined.size()){
208 totalSchemas++;
209 }
210
211 DataBag output = DefaultBagFactory.getInstance().newDefaultBag();
212 for(int i=0;i<totalSchemas;i++){
213 for(int j=i+1;j<totalSchemas;j++){
214 Tuple result = TupleFactory.getInstance().newTuple(3);
215 try{
216 if(flag){
217 result.set(0, schemaName.elementAt(i));
218 result.set(1, schemaName.elementAt(j));
219 }
220 else{
221 result.set(0, "var"+i);
222 result.set(1, "var"+j);
223 }
224 Tuple tup = (Tuple)combined.get(count);
225 double tempCount = (Long)combined.get(count+1);
226 double sum_x_y = (Double)tup.get(0);
227 double sum_x = (Double)tup.get(1);
228 double sum_y = (Double)tup.get(2);
229 double sum_x_square = (Double)tup.get(3);
230 double sum_y_square = (Double)tup.get(4);
231 double correl = (tempCount*sum_x_y - sum_x*sum_y)/Math.sqrt((tempCount*sum_x_square-sum_x*sum_x)*(tempCount*sum_y_square-sum_y*sum_y));
232 result.set(2, correl);
233 }catch(Exception e){
234 System.err.println("Failed to process input record; error - " + e.getMessage());
235 return null;
236 }
237 output.add(result);
238 count+=2;
239 }
240 }
241
242 return output;
243 }
244 }
245
246 /**

Callers

nothing calls this directly

Calls 10

sizeMethod · 0.95
getMethod · 0.95
getInstanceMethod · 0.95
setMethod · 0.95
addMethod · 0.95
newTupleMethod · 0.65
combineMethod · 0.45
newDefaultBagMethod · 0.45
getInstanceMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected