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

Method exec

src/org/apache/pig/builtin/COV.java:190–236  ·  view source on GitHub ↗
(Tuple input)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected