ggangadharan commented on code in PR #6878:
URL: https://github.com/apache/hive/pull/6878#discussion_r4294453672
##########
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:
Thanks. I took the TruncFloat change. For decimals I kept the in-place
mutateSetScale on purpose:
- It doesn't allocate anything per row. getHiveDecimal() creates a new
HiveDecimal (createFromFast), and setScale() creates another one unless the
scale is unchanged. So the suggested version allocates two objects per row
inside the vectorized loop.
- It's the same pattern DecimalUtil.round/bround/floor/ceiling already use
for vectorized decimals (decWritable.set(input);
decWritable.mutateSetScale(...)).
Also, HiveDecimal has no ROUND_DOWN constant (only FLOOR, CEILING, HALF_UP
and HALF_EVEN). That's why TruncUtils keeps a private alias of
BigDecimal.ROUND_DOWN.
The in-place path is also why the FastHiveDecimalImpl fix is in this PR (see
my reply on TestHiveDecimal). If you'd still prefer the HiveDecimal-based
version, I'm happy to switch and move the fastRoundIntegerDown fix to its own
JIRA.
--
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]