return res;
}
@Override
public Result getNext(Long l) throws ExecException {
PhysicalOperator in = inputs.get(0);
Byte resultType = in.getResultType();
switch (resultType) {
case DataType.BAG: {
Result res = new Result();
res.returnStatus = POStatus.STATUS_ERR;
return res;
}
case DataType.TUPLE: {
Result res = new Result();
res.returnStatus = POStatus.STATUS_ERR;
return res;
}
case DataType.MAP: {
Result res = new Result();
res.returnStatus = POStatus.STATUS_ERR;
return res;
}
case DataType.BYTEARRAY: {
DataByteArray dba = null;
Result res = in.getNext(dba);
if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
try {
dba = (DataByteArray) res.result;
} catch (ClassCastException e) {
// res.result is not of type ByteArray. But it can be one of the types from which cast is still possible.
if (realType == null)
// Find the type in first call and cache it.
realType = DataType.findType(res.result);
try {
res.result = DataType.toLong(res.result, realType);
} catch (ClassCastException cce) {
// Type has changed. Need to find type again and try casting it again.
realType = DataType.findType(res.result);
res.result = DataType.toLong(res.result, realType);
}
return res;
}
try {
if (null != caster) {
res.result = caster.bytesToLong(dba.get());
} else {
int errCode = 1075;
String msg = "Received a bytearray from the UDF. Cannot determine how to convert the bytearray to long.";
throw new ExecException(msg, errCode, PigException.INPUT);
}
} catch (ExecException ee) {
throw ee;
} catch (IOException e) {
log.error("Error while casting from ByteArray to Long");
}
}
return res;
}
case DataType.BOOLEAN: {
Boolean b = null;
Result res = in.getNext(b);
if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
if (((Boolean) res.result) == true)
res.result = Long.valueOf(1);
else
res.result = Long.valueOf(0);
}
return res;
}
case DataType.INTEGER: {
Integer dummyI = null;
Result res = in.getNext(dummyI);
if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
res.result = Long.valueOf(((Integer) res.result).longValue());
}
return res;
}
case DataType.DOUBLE: {
Double d = null;
Result res = in.getNext(d);
if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
// res.result = DataType.toInteger(res.result);
res.result = Long.valueOf(((Double) res.result).longValue());
}
return res;
}
case DataType.LONG: {
Result res = in.getNext(l);
return res;
}
case DataType.FLOAT: {
Float f = null;
Result res = in.getNext(f);
if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
res.result = Long.valueOf(((Float) res.result).longValue());
}
return res;
}
case DataType.CHARARRAY: {
String str = null;
Result res = in.getNext(str);
if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
res.result = CastUtils.stringToLong((String)res.result);
}
return res;
}