use of org.apache.phoenix.exception.DataExceedsCapacityException in project phoenix by apache.
the class DecimalDivideExpression method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
BigDecimal result = null;
for (int i = 0; i < children.size(); i++) {
Expression childExpr = children.get(i);
if (!childExpr.evaluate(tuple, ptr)) {
return false;
}
if (ptr.getLength() == 0) {
return true;
}
PDataType childType = childExpr.getDataType();
SortOrder childSortOrder = childExpr.getSortOrder();
BigDecimal bd = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childType, childSortOrder);
if (result == null) {
result = bd;
} else {
result = result.divide(bd, PDataType.DEFAULT_MATH_CONTEXT);
}
}
if (getMaxLength() != null || getScale() != null) {
result = NumberUtil.setDecimalWidthAndScale(result, getMaxLength(), getScale());
}
if (result == null) {
throw new DataExceedsCapacityException(PDecimal.INSTANCE, getMaxLength(), getScale());
}
ptr.set(PDecimal.INSTANCE.toBytes(result));
return true;
}
use of org.apache.phoenix.exception.DataExceedsCapacityException in project phoenix by apache.
the class SchemaUtil method padData.
/**
* Pads the data in ptr by the required amount for fixed width data types
*/
public static void padData(String tableName, PColumn column, ImmutableBytesWritable ptr) {
PDataType type = column.getDataType();
byte[] byteValue = ptr.get();
boolean isNull = type.isNull(byteValue);
Integer maxLength = column.getMaxLength();
if (!isNull && type.isFixedWidth() && maxLength != null) {
if (ptr.getLength() < maxLength) {
type.pad(ptr, maxLength, column.getSortOrder());
} else if (ptr.getLength() > maxLength) {
throw new DataExceedsCapacityException(tableName + "." + column.getName().getString() + " may not exceed " + maxLength + " bytes (" + type.toObject(byteValue) + ")");
}
}
}
Aggregations