Fast decimal based sign()
@@ -47,6 +47,7 @@ import static com.facebook.presto.spi.type.Decimals.longTenToNth;
import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.isNegative;
+import static com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.isZero;
import static com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.negate;
import static com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.unscaledDecimal;
import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
@@ -980,7 +981,15 @@ public final class MathFunctions
@SqlType("decimal(1,0)")
public static long signDecimalLong(@SqlType("decimal(p, s)") Slice num)
{
- return decodeUnscaledValue(num).signum();
+ if (isZero(num)) {
+ return 0;
+ }
+ else if (isNegative(num)) {
+ return -1;
+ }
+ else {
+ return 1;
+ }
}
}
