Search in sources :

Example 1 with ExecException

use of org.apache.pig.backend.executionengine.ExecException in project phoenix by apache.

the class PhoenixHBaseLoader method getNext.

@Override
public Tuple getNext() throws IOException {
    try {
        if (!reader.nextKeyValue()) {
            return null;
        }
        final PhoenixRecordWritable record = reader.getCurrentValue();
        if (record == null) {
            return null;
        }
        final Tuple tuple = TypeUtil.transformToTuple(record, schema.getFields());
        return tuple;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        int errCode = 6018;
        final String errMsg = "Error while reading input";
        throw new ExecException(errMsg, errCode, PigException.REMOTE_ENVIRONMENT, e);
    }
}
Also used : PhoenixRecordWritable(org.apache.phoenix.mapreduce.PhoenixRecordWritable) ExecException(org.apache.pig.backend.executionengine.ExecException) Tuple(org.apache.pig.data.Tuple)

Example 2 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 3 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 4 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 5 with ExecException

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

the class LzoBaseRegexLoader method getNext.

/**
 * Read the file line by line, returning lines the match the regex in Tuples
 * based on the regex match groups.
 */
@Override
public Tuple getNext() throws IOException {
    if (reader == null) {
        return null;
    }
    Pattern pattern = getPattern();
    Matcher matcher = pattern.matcher("");
    Object lineObj;
    String line;
    Tuple t = null;
    // end of the assigned byte range.
    try {
        while (reader.nextKeyValue()) {
            lineObj = reader.getCurrentValue();
            if (lineObj == null) {
                break;
            }
            line = lineObj.toString();
            matcher = matcher.reset(line);
            // Increment counters for the number of matched and unmatched lines.
            if (matcher.find()) {
                incrCounter(LzoBaseRegexLoaderCounters.MatchedRegexLines, 1L);
                t = tupleFactory_.newTuple(matcher.groupCount());
                for (int i = 1; i <= matcher.groupCount(); i++) {
                    if (matcher.group(i) != null) {
                        t.set(i - 1, matcher.group(i));
                    } else {
                        t.set(i - 1, "");
                    }
                }
                break;
            } else {
                incrCounter(LzoBaseRegexLoaderCounters.UnmatchedRegexLines, 1L);
                // TODO: stop doing this, as it can slow down the job.
                LOG.debug("No match for line " + line);
            }
        // If the read has walked beyond the end of the split, move on.
        }
    } catch (InterruptedException e) {
        int errCode = 6018;
        String errMsg = "Error while reading input";
        throw new ExecException(errMsg, errCode, PigException.REMOTE_ENVIRONMENT, e);
    }
    return t;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ExecException(org.apache.pig.backend.executionengine.ExecException) Tuple(org.apache.pig.data.Tuple)

Aggregations

ExecException (org.apache.pig.backend.executionengine.ExecException)48 Tuple (org.apache.pig.data.Tuple)24 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)13 DataBag (org.apache.pig.data.DataBag)11 Geometry (com.vividsolutions.jts.geom.Geometry)9 DataByteArray (org.apache.pig.data.DataByteArray)9 IOException (java.io.IOException)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5 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 Test (org.testng.annotations.Test)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 Polyline (com.esri.core.geometry.Polyline)1