Skip to content

Instantly share code, notes, and snippets.

@losipiuk
Created October 23, 2015 11:15
Show Gist options
  • Save losipiuk/cdf89620ac37ef230118 to your computer and use it in GitHub Desktop.
Save losipiuk/cdf89620ac37ef230118 to your computer and use it in GitHub Desktop.
decimal operators annotations
@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