Created
October 23, 2015 11:15
-
-
Save losipiuk/cdf89620ac37ef230118 to your computer and use it in GitHub Desktop.
decimal operators annotations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ScalarOperator(ADD) | |
@SqlType("decimal(min(38, p + 1), s)") | |
public static long addShortShortShort(@SqlType("decimal(p,s)") long a, @SqlType("decimal(p,s)") long b) | |
{ | |
return a + b; | |
} | |
@ScalarOperator(ADD) | |
@SqlType("decimal(min(38, p + 1), s)") | |
public static Slice addShortShortLong(@SqlType("decimal(p,s)") long a, @SqlType("decimal(p,s)") long b) | |
{ | |
BigInteger aBigInteger = BigInteger.valueOf(a); | |
BigInteger bBigInteger = BigInteger.valueOf(b); | |
BigInteger result = aBigInteger.add(bBigInteger); | |
return LongDecimalType.unscaledValueToSlice(result); | |
} | |
@ScalarOperator(ADD) | |
@SqlType("decimal(min(38, p + 1), s)") | |
public static Slice addLongLongLong(@SqlType("decimal(p,s)") Slice a, @SqlType("decimal(p,s)") Slice b) | |
{ | |
BigInteger aBigInteger = LongDecimalType.unscaledValueToBigInteger(a); | |
BigInteger bBigInteger = LongDecimalType.unscaledValueToBigInteger(b); | |
BigInteger result = aBigInteger.add(bBigInteger); | |
checkOverflow(result); | |
return LongDecimalType.unscaledValueToSlice(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment