/** * Returns the given decimal rounded to this rounding expression's scale. * For example, with scale 2 the decimal "2.453" would be rounded to either 2.45 or * 2.46 depending on the rounding mode, while "2.38" and "2.7" would be unchanged. * @param decimal the decimal to round * @return the rounded result decimal */ protected final BigDecimal roundToScale(BigDecimal decimal) { return decimal.setScale(getRoundingScale(), getRoundingMode()); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression childExpr = children.get(0); if(childExpr.evaluate(tuple, ptr)) { if (ptr.getLength()==0) { return true; } BigDecimal value = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childExpr.getDataType(), childExpr.getSortOrder()); BigDecimal scaledValue = value.setScale(scale, getRoundingMode()); ptr.set(PDecimal.INSTANCE.toBytes(scaledValue)); return true; } return false; }
/** * Returns the given decimal rounded to this rounding expression's scale. * For example, with scale 2 the decimal "2.453" would be rounded to either 2.45 or * 2.46 depending on the rounding mode, while "2.38" and "2.7" would be unchanged. * @param decimal the decimal to round * @return the rounded result decimal */ protected final BigDecimal roundToScale(BigDecimal decimal) { return decimal.setScale(getRoundingScale(), getRoundingMode()); }
/** * Returns the given decimal rounded to this rounding expression's scale. * For example, with scale 2 the decimal "2.453" would be rounded to either 2.45 or * 2.46 depending on the rounding mode, while "2.38" and "2.7" would be unchanged. * @param decimal the decimal to round * @return the rounded result decimal */ protected final BigDecimal roundToScale(BigDecimal decimal) { return decimal.setScale(getRoundingScale(), getRoundingMode()); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression childExpr = children.get(0); if(childExpr.evaluate(tuple, ptr)) { if (ptr.getLength()==0) { return true; } BigDecimal value = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childExpr.getDataType(), childExpr.getSortOrder()); BigDecimal scaledValue = value.setScale(scale, getRoundingMode()); ptr.set(PDecimal.INSTANCE.toBytes(scaledValue)); return true; } return false; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression childExpr = children.get(0); if(childExpr.evaluate(tuple, ptr)) { if (ptr.getLength()==0) { return true; } BigDecimal value = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childExpr.getDataType(), childExpr.getSortOrder()); BigDecimal scaledValue = value.setScale(scale, getRoundingMode()); ptr.set(PDecimal.INSTANCE.toBytes(scaledValue)); return true; } return false; }