Search in sources :

Example 6 with ExecException

use of org.apache.pig.backend.executionengine.ExecException in project elephant-bird by twitter.

the class PigToThrift method toThrift.

/**
 * Construct a Thrift object from the tuple.
 */
@SuppressWarnings("unchecked")
private static TBase<?, ?> toThrift(TStructDescriptor tDesc, Tuple tuple) {
    int size = tDesc.getFields().size();
    int tupleSize = tuple.size();
    @SuppressWarnings("rawtypes") TBase tObj = newTInstance(tDesc.getThriftClass());
    for (int i = 0; i < size && i < tupleSize; i++) {
        Object pObj;
        try {
            pObj = tuple.get(i);
        } catch (ExecException e) {
            throw new RuntimeException(e);
        }
        if (pObj != null) {
            Field field = tDesc.getFieldAt(i);
            try {
                tObj.setFieldValue(field.getFieldIdEnum(), toThriftValue(field, pObj));
            } catch (Exception e) {
                String value = String.valueOf(tObj);
                final int max_length = 100;
                if (max_length < value.length()) {
                    value = value.substring(0, max_length - 3) + "...";
                }
                String type = tObj == null ? "unknown" : tObj.getClass().getName();
                throw new RuntimeException(String.format("Failed to set field '%s' using tuple value '%s' of type '%s' at index %d", field.getName(), value, type, i), e);
            }
        }
    // if tDesc is a union, at least one field needs to be non-null.
    // user is responsible for ensuring that.
    }
    return tObj;
}
Also used : Field(com.twitter.elephantbird.thrift.TStructDescriptor.Field) ExecException(org.apache.pig.backend.executionengine.ExecException) TBase(org.apache.thrift.TBase) ExecException(org.apache.pig.backend.executionengine.ExecException)

Example 7 with ExecException

use of org.apache.pig.backend.executionengine.ExecException in project elephant-bird by twitter.

the class JsonLoader method getNext.

/**
 * Return every non-null line as a single-element tuple to Pig.
 */
@Override
public Tuple getNext() throws IOException {
    if (reader == null) {
        return null;
    }
    // nested load can be enabled through a pig property
    if ("true".equals(jobConf.get(NESTED_LOAD_KEY)))
        isNestedLoadEnabled = true;
    try {
        while (reader.nextKeyValue()) {
            Text value = (Text) reader.getCurrentValue();
            incrCounter(JsonLoaderCounters.LinesRead, 1L);
            Tuple t = parseStringToTuple(value.toString());
            if (t != null) {
                incrCounter(JsonLoaderCounters.LinesJsonDecoded, 1L);
                return t;
            }
        }
        return null;
    } catch (InterruptedException e) {
        int errCode = 6018;
        String errMsg = "Error while reading input";
        throw new ExecException(errMsg, errCode, PigException.REMOTE_ENVIRONMENT, e);
    }
}
Also used : ExecException(org.apache.pig.backend.executionengine.ExecException) Text(org.apache.hadoop.io.Text) Tuple(org.apache.pig.data.Tuple)

Example 8 with ExecException

use of org.apache.pig.backend.executionengine.ExecException in project elephant-bird by twitter.

the class TestW3CLogParser method verify.

private void verify(String fileName, boolean expected) throws IOException, ExecException, Exception {
    InputStream inputs = getClass().getClassLoader().getResourceAsStream(fileName);
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputs, "UTF-8"));
    String line = null;
    Map<String, String> map = null;
    Boolean results = true;
    try {
        while ((line = reader.readLine()) != null) {
            try {
                map = parser_.parse(line);
                System.out.print(map.get("hostname"));
            } catch (Exception e) {
                results = false;
            }
            assertEquals(results, expected);
        }
    } finally {
        inputs.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ExecException(org.apache.pig.backend.executionengine.ExecException)

Example 9 with ExecException

use of org.apache.pig.backend.executionengine.ExecException in project sketches-pig by DataSketches.

the class ReservoirSamplingTest method generateDataBag.

static DataBag generateDataBag(final long numItems, final int startIdx) {
    final DataBag output = BagFactory.getInstance().newDefaultBag();
    try {
        for (int i = 0; i < numItems; ++i) {
            final Tuple t = TupleFactory.getInstance().newTuple(2);
            final int val = startIdx + i;
            t.set(0, val);
            t.set(1, Integer.toString(-val));
            output.add(t);
        }
    } catch (final ExecException e) {
        fail(e.getMessage());
    }
    return output;
}
Also used : DataBag(org.apache.pig.data.DataBag) ExecException(org.apache.pig.backend.executionengine.ExecException) Tuple(org.apache.pig.data.Tuple)

Example 10 with ExecException

use of org.apache.pig.backend.executionengine.ExecException in project sketches-pig by DataSketches.

the class ReservoirUnionTest method checkDegenerateInput.

@Test
public void checkDegenerateInput() {
    // using default max k value
    final ReservoirUnion ru = new ReservoirUnion();
    Tuple inputTuple;
    try {
        // input == null
        assertNull(ru.exec(null));
        // input.size() < 1
        inputTuple = TupleFactory.getInstance().newTuple(0);
        assertNull(ru.exec(inputTuple));
        // input.isNull(0);
        inputTuple = TupleFactory.getInstance().newTuple(1);
        inputTuple.set(0, null);
        assertNull(ru.exec(inputTuple));
    } catch (final IOException e) {
        fail("Unexpected exception");
    }
    try {
        // reservoir tuple with only 2 entries
        final Tuple reservoir = TupleFactory.getInstance().newTuple(2);
        reservoir.set(0, 256L);
        reservoir.set(1, 256);
        final DataBag reservoirBag = BagFactory.getInstance().newDefaultBag();
        reservoirBag.add(reservoir);
        inputTuple = TupleFactory.getInstance().newTuple(reservoirBag);
        ru.exec(inputTuple);
        fail("Did not catch expected ExecException");
    } catch (final ExecException e) {
    // expected
    } catch (final IOException e) {
        fail("Unexpected exception");
    }
}
Also used : DataBag(org.apache.pig.data.DataBag) ExecException(org.apache.pig.backend.executionengine.ExecException) IOException(java.io.IOException) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Aggregations

ExecException (org.apache.pig.backend.executionengine.ExecException)57 Tuple (org.apache.pig.data.Tuple)32 DataBag (org.apache.pig.data.DataBag)17 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)13 DataByteArray (org.apache.pig.data.DataByteArray)11 IOException (java.io.IOException)9 Geometry (org.locationtech.jts.geom.Geometry)9 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 VarOptItemsSamples (org.apache.datasketches.sampling.VarOptItemsSamples)2 Line (com.esri.core.geometry.Line)1 MultiPath (com.esri.core.geometry.MultiPath)1 Point (com.esri.core.geometry.Point)1 Polygon (com.esri.core.geometry.Polygon)1