From 0d89e4175765ebef76b125eedb55f9f541a0b040 Mon Sep 17 00:00:00 2001 From: Alfred Xu Date: Thu, 13 Jan 2022 09:43:29 +0800 Subject: [PATCH] simplified the construction of zero scalar in GpuUnaryMinus (#4482) Signed-off-by: sperlingxx --- .../apache/spark/sql/rapids/arithmetic.scala | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/sql-plugin/src/main/scala/org/apache/spark/sql/rapids/arithmetic.scala b/sql-plugin/src/main/scala/org/apache/spark/sql/rapids/arithmetic.scala index d9555bae37b..faa001918f6 100644 --- a/sql-plugin/src/main/scala/org/apache/spark/sql/rapids/arithmetic.scala +++ b/sql-plugin/src/main/scala/org/apache/spark/sql/rapids/arithmetic.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. + * Copyright (c) 2019-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,19 +73,9 @@ case class GpuUnaryMinus(child: Expression, failOnError: Boolean) extends GpuUna } dataType match { case dt: DecimalType => - val scale = dt.scale - if (DecimalType.is32BitDecimalType(dt)) { - withResource(Scalar.fromDecimal(-scale, 0)) { scalar => - scalar.sub(input.getBase) - } - } else if (DecimalType.is64BitDecimalType(dt)) { - withResource(Scalar.fromDecimal(-scale, 0L)) { scalar => - scalar.sub(input.getBase) - } - } else { // Decimal-128 - withResource(Scalar.fromDecimal(-scale, BigInteger.ZERO)) { scalar => - scalar.sub(input.getBase) - } + val zeroLit = Decimal(0L, dt.precision, dt.scale) + withResource(GpuScalar.from(zeroLit, dt)) { scalar => + scalar.sub(input.getBase) } case _ => withResource(Scalar.fromByte(0.toByte)) { scalar =>