ggangadharan commented on code in PR #6878:
URL: https://github.com/apache/hive/pull/6878#discussion_r4294754924
##########
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/TruncDecimal.java:
##########
@@ -45,26 +45,9 @@ public TruncDecimal(int colNum, int scale, int
outputColumnNum) {
@Override
protected void trunc(ColumnVector inputColVector, ColumnVector
outputColVector, int i) {
- HiveDecimal input = ((DecimalColumnVector)
inputColVector).vector[i].getHiveDecimal();
-
- HiveDecimal output = trunc(input);
- ((DecimalColumnVector) outputColVector).vector[i] = new
HiveDecimalWritable(output);
- }
-
- protected HiveDecimal trunc(HiveDecimal input) {
- HiveDecimal pow = HiveDecimal.create(Math.pow(10, Math.abs(scale)));
-
- if (scale >= 0) {
- if (scale != 0) {
- long longValue = input.multiply(pow).longValue();
- return HiveDecimal.create(longValue).divide(pow);
- } else {
- return HiveDecimal.create(input.longValue());
- }
- } else {
- long longValue2 = input.divide(pow).longValue();
- return HiveDecimal.create(longValue2).multiply(pow);
- }
+ HiveDecimalWritable output = ((DecimalColumnVector)
outputColVector).vector[i];
Review Comment:
Done, went with `trunc(input, scale, output)`.
`TruncUtils.trunc(HiveDecimalWritable input, int scale, HiveDecimalWritable
output)` copies the input into output and truncates it there, so it stays
allocation-free and the input is never mutated, same shape as
`DecimalUtil.round(...)`. `TruncDecimal` and `GenericUDFTrunc` are now single
calls, and the old in-place overload is removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]