@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (delegate == null) { return super.evaluate(tuple, ptr); } delegate.evaluate(tuple, ptr); if (PLong.INSTANCE.compareTo(ptr,ZERO) == 0) { return false; } return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!countFunc.evaluate(tuple, ptr)) { return false; } long count = countFunc.getDataType().getCodec().decodeLong(ptr, SortOrder.getDefault()); if (count == 0) { return false; } // Normal case where a column reference was used as the argument to AVG if (!countFunc.isConstantExpression()) { sumFunc.evaluate(tuple, ptr); BigDecimal sum = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, sumFunc.getDataType()); // For the final column projection, we divide the sum by the count, both coerced to BigDecimal. // TODO: base the precision on column metadata instead of constant BigDecimal avg = sum.divide(BigDecimal.valueOf(count), PDataType.DEFAULT_MATH_CONTEXT); avg = avg.setScale(scale, BigDecimal.ROUND_DOWN); ptr.set(PDecimal.INSTANCE.toBytes(avg)); return true; } BigDecimal value = (BigDecimal) ((LiteralExpression)countFunc.getChildren().get(0)).getValue(); value = value.setScale(scale, BigDecimal.ROUND_DOWN); ptr.set(PDecimal.INSTANCE.toBytes(value)); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (delegate == null) { return super.evaluate(tuple, ptr); } delegate.evaluate(tuple, ptr); if (PLong.INSTANCE.compareTo(ptr,ZERO) == 0) { return false; } return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (delegate == null) { return super.evaluate(tuple, ptr); } delegate.evaluate(tuple, ptr); if (PLong.INSTANCE.compareTo(ptr,ZERO) == 0) { return false; } return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!countFunc.evaluate(tuple, ptr)) { return false; } long count = countFunc.getDataType().getCodec().decodeLong(ptr, SortOrder.getDefault()); if (count == 0) { return false; } // Normal case where a column reference was used as the argument to AVG if (!countFunc.isConstantExpression()) { sumFunc.evaluate(tuple, ptr); BigDecimal sum = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, sumFunc.getDataType()); // For the final column projection, we divide the sum by the count, both coerced to BigDecimal. // TODO: base the precision on column metadata instead of constant BigDecimal avg = sum.divide(BigDecimal.valueOf(count), PDataType.DEFAULT_MATH_CONTEXT); avg = avg.setScale(scale, BigDecimal.ROUND_DOWN); ptr.set(PDecimal.INSTANCE.toBytes(avg)); return true; } BigDecimal value = (BigDecimal) ((LiteralExpression)countFunc.getChildren().get(0)).getValue(); value = value.setScale(scale, BigDecimal.ROUND_DOWN); ptr.set(PDecimal.INSTANCE.toBytes(value)); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!countFunc.evaluate(tuple, ptr)) { return false; } long count = countFunc.getDataType().getCodec().decodeLong(ptr, SortOrder.getDefault()); if (count == 0) { return false; } // Normal case where a column reference was used as the argument to AVG if (!countFunc.isConstantExpression()) { sumFunc.evaluate(tuple, ptr); BigDecimal sum = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, sumFunc.getDataType()); // For the final column projection, we divide the sum by the count, both coerced to BigDecimal. // TODO: base the precision on column metadata instead of constant BigDecimal avg = sum.divide(BigDecimal.valueOf(count), PDataType.DEFAULT_MATH_CONTEXT); avg = avg.setScale(scale, BigDecimal.ROUND_DOWN); ptr.set(PDecimal.INSTANCE.toBytes(avg)); return true; } BigDecimal value = (BigDecimal) ((LiteralExpression)countFunc.getChildren().get(0)).getValue(); value = value.setScale(scale, BigDecimal.ROUND_DOWN); ptr.set(PDecimal.INSTANCE.toBytes(value)); return true; }