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);
}
}
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;
}
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();
}
}
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);
}
}
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;
}
Aggregations