case SMALLINT:
if (pigObj == null) {
return null;
}
if ((Integer) pigObj < Short.MIN_VALUE || (Integer) pigObj > Short.MAX_VALUE) {
throw new BackendException("Value " + pigObj + " is outside the bounds of column " +
hcatFS.getName() + " with type " + hcatFS.getType(), PigHCatUtil.PIG_EXCEPTION_CODE);
}
return ((Integer) pigObj).shortValue();
case TINYINT:
if (pigObj == null) {
return null;
}
if ((Integer) pigObj < Byte.MIN_VALUE || (Integer) pigObj > Byte.MAX_VALUE) {
throw new BackendException("Value " + pigObj + " is outside the bounds of column " +
hcatFS.getName() + " with type " + hcatFS.getType(), PigHCatUtil.PIG_EXCEPTION_CODE);
}
return ((Integer) pigObj).byteValue();
case BOOLEAN:
if (pigObj == null) {
LOG.debug( "HCatBaseStorer.getJavaObj(BOOLEAN): obj null, bailing early" );
return null;
}
if( pigObj instanceof String ) {
if( ((String)pigObj).trim().compareTo("0") == 0 ) {
return Boolean.FALSE;
}
if( ((String)pigObj).trim().compareTo("1") == 0 ) {
return Boolean.TRUE;
}
throw new BackendException(
"Unexpected type " + type + " for value " + pigObj
+ (pigObj == null ? "" : " of class "
+ pigObj.getClass().getName()), PigHCatUtil.PIG_EXCEPTION_CODE);
}
return Boolean.parseBoolean( pigObj.toString() );
default:
throw new BackendException("Unexpected type " + type + " for value " + pigObj
+ (pigObj == null ? "" : " of class "
+ pigObj.getClass().getName()), PigHCatUtil.PIG_EXCEPTION_CODE);
}
} catch (BackendException e) {
// provide the path to the field in the error message
throw new BackendException(
(hcatFS.getName() == null ? " " : hcatFS.getName() + ".") + e.getMessage(),
e.getCause() == null ? e : e.getCause());
}
}