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