@UsedByGeneratedCode public static boolean longDecimalToBoolean(Slice decimal, long precision, long scale, BigInteger tenToScale) { return !decodeUnscaledValue(decimal).equals(ZERO); }
@UsedByGeneratedCode public static boolean longDecimalToBoolean(Slice decimal, long precision, long scale, BigInteger tenToScale) { return !decodeUnscaledValue(decimal).equals(ZERO); }
@UsedByGeneratedCode public static long longDecimalToGenericIntegerType(Slice value, int sourceScale, long minValue, long maxValue) { return bigIntegerDecimalToGenericIntegerType(decodeUnscaledValue(value), sourceScale, minValue, maxValue); }
@VisibleForTesting public static BigDecimal average(LongDecimalWithOverflowAndLongState state, DecimalType type) { BigDecimal sum = new BigDecimal(Decimals.decodeUnscaledValue(state.getLongDecimal()), type.getScale()); BigDecimal count = BigDecimal.valueOf(state.getLong()); if (state.getOverflow() != 0) { BigInteger overflowMultiplier = TWO.shiftLeft(UNSCALED_DECIMAL_128_SLICE_LENGTH * 8 - 2); BigInteger overflow = overflowMultiplier.multiply(BigInteger.valueOf(state.getOverflow())); sum = sum.add(new BigDecimal(overflow)); } return sum.divide(count, type.getScale(), ROUND_HALF_UP); }
@UsedByGeneratedCode public static long longDecimalToGenericIntegerType(Slice value, int sourceScale, long minValue, long maxValue) { return bigIntegerDecimalToGenericIntegerType(decodeUnscaledValue(value), sourceScale, minValue, maxValue); }
@UsedByGeneratedCode public static Slice longDecimalToJson(Slice decimal, long precision, long scale, BigInteger tenToScale) { return decimalToJson(new BigDecimal(decodeUnscaledValue(decimal), intScale(scale))); }
@UsedByGeneratedCode public static Slice longDecimalToJson(Slice decimal, long precision, long scale, BigInteger tenToScale) { return decimalToJson(new BigDecimal(decodeUnscaledValue(decimal), intScale(scale))); }
@UsedByGeneratedCode public static long longDecimalToShortDecimal(Slice value, int sourcePrecision, int sourceScale, int resultPrecision, int resultScale) { return bigintToBigintFloorSaturatedCast(decodeUnscaledValue(value), sourceScale, resultPrecision, resultScale).longValueExact(); }
@UsedByGeneratedCode public static long longDecimalToShortDecimal(Slice value, int sourcePrecision, int sourceScale, int resultPrecision, int resultScale) { return bigintToBigintFloorSaturatedCast(decodeUnscaledValue(value), sourceScale, resultPrecision, resultScale).longValueExact(); }
@UsedByGeneratedCode public static Slice longDecimalToLongDecimal(Slice value, int sourcePrecision, int sourceScale, int resultPrecision, int resultScale) { return encodeUnscaledValue(bigintToBigintFloorSaturatedCast(decodeUnscaledValue(value), sourceScale, resultPrecision, resultScale)); }
@UsedByGeneratedCode public static Slice longDecimalToLongDecimal(Slice value, int sourcePrecision, int sourceScale, int resultPrecision, int resultScale) { return encodeUnscaledValue(bigintToBigintFloorSaturatedCast(decodeUnscaledValue(value), sourceScale, resultPrecision, resultScale)); }
@LiteralParameters({"p", "s"}) @SqlType("decimal(p, s)") public static Slice negate(@SqlType("decimal(p, s)") Slice arg) { BigInteger argBigInteger = Decimals.decodeUnscaledValue(arg); return encodeUnscaledValue(argBigInteger.negate()); } }
@Override public void addBlock(Type type, Block block) { int scale = ((DecimalType) type).getScale(); for (int position = 0; position < block.getPositionCount(); position++) { if (!block.isNull(position)) { Slice value = type.getSlice(block, position); addValue(new BigDecimal(Decimals.decodeUnscaledValue(value), scale)); } } }
private void assertShiftLeft(BigInteger value, int leftShifts) { Slice decimal = unscaledDecimal(value); BigInteger expectedResult = value.multiply(TWO.pow(leftShifts)); shiftLeftDestructive(decimal, leftShifts); assertEquals(decodeUnscaledValue(decimal), expectedResult); }
@Override public void addBlock(Type type, Block block) { int scale = ((DecimalType) type).getScale(); for (int position = 0; position < block.getPositionCount(); position++) { if (!block.isNull(position)) { Slice value = type.getSlice(block, position); addValue(new BigDecimal(Decimals.decodeUnscaledValue(value), scale)); } } }
private void assertShiftRightArray8(BigInteger value, int rightShifts, boolean roundUp) { BigInteger expectedResult = value.shiftRight(rightShifts); if (roundUp) { expectedResult = expectedResult.add(BigInteger.ONE); } int[] ints = toInt8Array(value); Slice result = unscaledDecimal(); shiftRightArray8(ints, rightShifts, result); assertEquals(decodeUnscaledValue(result), expectedResult); }
private void assertShiftRightArray8(BigInteger value, int rightShifts, boolean roundUp) { BigInteger expectedResult = value.shiftRight(rightShifts); if (roundUp) { expectedResult = expectedResult.add(BigInteger.ONE); } int[] ints = toInt8Array(value); Slice result = unscaledDecimal(); shiftRightArray8(ints, rightShifts, result); assertEquals(decodeUnscaledValue(result), expectedResult); }
@Override public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } Slice slice = block.getSlice(position, 0, getFixedSize()); return new SqlDecimal(decodeUnscaledValue(slice), getPrecision(), getScale()); }
protected static SqlDecimal decimal(String decimalString) { DecimalParseResult parseResult = Decimals.parseIncludeLeadingZerosInPrecision(decimalString); BigInteger unscaledValue; if (parseResult.getType().isShort()) { unscaledValue = BigInteger.valueOf((Long) parseResult.getObject()); } else { unscaledValue = Decimals.decodeUnscaledValue((Slice) parseResult.getObject()); } return new SqlDecimal(unscaledValue, parseResult.getType().getPrecision(), parseResult.getType().getScale()); }
protected static SqlDecimal decimal(String decimalString) { DecimalParseResult parseResult = Decimals.parseIncludeLeadingZerosInPrecision(decimalString); BigInteger unscaledValue; if (parseResult.getType().isShort()) { unscaledValue = BigInteger.valueOf((Long) parseResult.getObject()); } else { unscaledValue = Decimals.decodeUnscaledValue((Slice) parseResult.getObject()); } return new SqlDecimal(unscaledValue, parseResult.getType().getPrecision(), parseResult.getType().getScale()); }