Search in sources :

Example 36 with ExecException

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++;
    }
}
Also used : DataBag(org.apache.pig.data.DataBag) ExecException(org.apache.pig.backend.executionengine.ExecException) Tuple(org.apache.pig.data.Tuple)

Example 37 with ExecException

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);
    }
}
Also used : ExecException(org.apache.pig.backend.executionengine.ExecException) FrontendException(org.apache.pig.impl.logicalLayer.FrontendException) IOException(java.io.IOException) PigException(org.apache.pig.PigException) ExecException(org.apache.pig.backend.executionengine.ExecException)

Example 38 with ExecException

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;
    }
}
Also used : DataBag(org.apache.pig.data.DataBag) ExecException(org.apache.pig.backend.executionengine.ExecException) Tuple(org.apache.pig.data.Tuple)

Example 39 with ExecException

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;
    }
}
Also used : DataBag(org.apache.pig.data.DataBag) ExecException(org.apache.pig.backend.executionengine.ExecException) Tuple(org.apache.pig.data.Tuple)

Example 40 with ExecException

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);
    }
}
Also used : ExecException(org.apache.pig.backend.executionengine.ExecException) FrontendException(org.apache.pig.impl.logicalLayer.FrontendException) IOException(java.io.IOException) PigException(org.apache.pig.PigException) ExecException(org.apache.pig.backend.executionengine.ExecException)

Aggregations

ExecException (org.apache.pig.backend.executionengine.ExecException)80 Tuple (org.apache.pig.data.Tuple)49 DataBag (org.apache.pig.data.DataBag)31 IOException (java.io.IOException)16 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)13 DataByteArray (org.apache.pig.data.DataByteArray)13 Geometry (org.locationtech.jts.geom.Geometry)9 PigException (org.apache.pig.PigException)8 FrontendException (org.apache.pig.impl.logicalLayer.FrontendException)6 Test (org.testng.annotations.Test)6 Coordinate (org.locationtech.jts.geom.Coordinate)4 Field (com.twitter.elephantbird.thrift.TStructDescriptor.Field)3 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)2 Builder (com.google.protobuf.Message.Builder)2 VarOptItemsSamples (com.yahoo.sketches.sampling.VarOptItemsSamples)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 VarOptItemsSamples (org.apache.datasketches.sampling.VarOptItemsSamples)2 Line (com.esri.core.geometry.Line)1