use of org.apache.pig.backend.executionengine.ExecException in project datafu by apache.
the class CondEntropy method accumulate.
/*
* Accumulate occurrence frequency of <x,y> and x
* as we stream through the input bag
*/
@Override
public void accumulate(Tuple input) throws IOException {
for (Tuple t : (DataBag) input.get(0)) {
if (this.xy != null) {
int cmp = t.compareTo(this.xy);
// check if the comparison result is different from previous compare result
if ((cmp < 0 && this.lastCmp > 0) || (cmp > 0 && this.lastCmp < 0)) {
throw new ExecException("Out of order! previous tuple: " + this.xy + ", present tuple: " + t + ", comparsion: " + cmp + ", previous comparsion: " + this.lastCmp);
}
if (cmp != 0) {
// different <x,y>
this.combEstimator.accumulate(this.cxy);
this.cxy = 0;
this.lastCmp = cmp;
if (DataType.compare(this.xy.get(0), t.get(0)) != 0) {
// different x
this.condXEstimator.accumulate(this.cx);
this.cx = 0;
}
}
}
// set tuple t as the next tuple for comparison
this.xy = t;
// accumulate cx
this.cx++;
// accumulate cxy
this.cxy++;
}
}
use of org.apache.pig.backend.executionengine.ExecException in project datafu by apache.
the class DoubleVAR method accumulate.
@Override
public void accumulate(Tuple b) throws IOException {
try {
Double sum = sum(b);
if (sum == null) {
return;
}
Double sumSquare = sumSquare(b);
if (sumSquare == null) {
return;
}
// set default values
if (intermediateSum == null || intermediateCount == null) {
intermediateSumSquare = 0.0;
intermediateSum = 0.0;
intermediateCount = (long) 0;
}
long count = (Long) count(b);
if (count > 0) {
intermediateCount += count;
intermediateSum += sum;
intermediateSumSquare += sumSquare;
}
} catch (ExecException ee) {
throw ee;
} catch (Exception e) {
int errCode = 2106;
String msg = "Error while computing variance in " + this.getClass().getSimpleName();
throw new ExecException(msg, errCode, PigException.BUG, e);
}
}
use of org.apache.pig.backend.executionengine.ExecException in project datafu by apache.
the class DoubleVAR method sumSquare.
protected static Double sumSquare(Tuple input) throws ExecException, IOException {
DataBag values = (DataBag) input.get(0);
// if we were handed an empty bag, return NULL
if (values.size() == 0) {
return null;
}
double sumSquare = 0;
boolean sawNonNull = false;
for (Iterator<Tuple> it = values.iterator(); it.hasNext(); ) {
Tuple t = it.next();
try {
Double d = (Double) t.get(0);
if (d == null)
continue;
sawNonNull = true;
sumSquare += d * d;
} catch (RuntimeException exp) {
int errCode = 2103;
String msg = "Problem while computing sum of squared values.";
throw new ExecException(msg, errCode, PigException.BUG, exp);
}
}
if (sawNonNull) {
return new Double(sumSquare);
} else {
return null;
}
}
use of org.apache.pig.backend.executionengine.ExecException in project datafu by apache.
the class FloatVAR method sum.
protected static Double sum(Tuple input) throws ExecException, IOException {
DataBag values = (DataBag) input.get(0);
// if we were handed an empty bag, return NULL
if (values.size() == 0) {
return null;
}
double sum = 0;
boolean sawNonNull = false;
for (Iterator<Tuple> it = values.iterator(); it.hasNext(); ) {
Tuple t = it.next();
try {
Float f = (Float) t.get(0);
if (f == null)
continue;
sawNonNull = true;
sum += f;
} catch (RuntimeException exp) {
int errCode = 2103;
String msg = "Problem while computing sum of values.";
throw new ExecException(msg, errCode, PigException.BUG, exp);
}
}
if (sawNonNull) {
return new Double(sum);
} else {
return null;
}
}
use of org.apache.pig.backend.executionengine.ExecException in project datafu by apache.
the class FloatVAR method accumulate.
@Override
public void accumulate(Tuple b) throws IOException {
try {
Double sum = sum(b);
if (sum == null) {
return;
}
Double sumSquare = sumSquare(b);
if (sumSquare == null) {
return;
}
// set default values
if (intermediateSum == null || intermediateCount == null) {
intermediateSumSquare = 0.0;
intermediateSum = 0.0;
intermediateCount = (long) 0;
}
long count = (Long) count(b);
if (count > 0) {
intermediateCount += count;
intermediateSum += sum;
intermediateSumSquare += sumSquare;
}
} catch (ExecException ee) {
throw ee;
} catch (Exception e) {
int errCode = 2106;
String msg = "Error while computing variance in " + this.getClass().getSimpleName();
throw new ExecException(msg, errCode, PigException.BUG, e);
}
}
Aggregations