@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); }
@Override public void writeJsonValue(JsonGenerator jsonGenerator, Block block, int position, ConnectorSession session) throws IOException { if (block.isNull(position)) { jsonGenerator.writeNull(); } else { BigDecimal value = new BigDecimal( decodeUnscaledValue(type.getSlice(block, position)), type.getScale()); jsonGenerator.writeNumber(value); } } }
@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); }
public static BigDecimal readBigDecimal(DecimalType type, Block block, int position) { BigInteger unscaledValue = type.isShort() ? BigInteger.valueOf(type.getLong(block, position)) : decodeUnscaledValue(type.getSlice(block, position)); return new BigDecimal(unscaledValue, type.getScale(), new MathContext(type.getPrecision())); }
@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 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 static HiveDecimal getHiveDecimal(DecimalType decimalType, Block block, int position) { BigInteger unscaledValue; if (decimalType.isShort()) { unscaledValue = BigInteger.valueOf(decimalType.getLong(block, position)); } else { unscaledValue = Decimals.decodeUnscaledValue(decimalType.getSlice(block, position)); } return HiveDecimal.create(unscaledValue, decimalType.getScale()); }
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); }
private void writeSlice(SliceOutput output, Block block, int position) { // first vint is scale writeVInt(output, type.getScale()); // second vint is length // todo get rid of BigInteger BigInteger decimal = Decimals.decodeUnscaledValue(block.getSlice(position, 0, BYTES_IN_LONG_DECIMAL)); byte[] decimalBytes = decimal.toByteArray(); writeVInt(output, decimalBytes.length); // write value (big endian) // NOTE: long decimals are stored in a slice in big endian encoding for (byte decimalByte : decimalBytes) { output.write(decimalByte); } } }
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()); }
private static void assertDivide(Slice dividend, int dividendRescaleFactor, Slice divisor, int divisorRescaleFactor) BigInteger dividendBigInteger = decodeUnscaledValue(dividend); BigInteger divisorBigInteger = decodeUnscaledValue(divisor); BigInteger rescaledDividend = dividendBigInteger.multiply(bigIntegerTenToNth(dividendRescaleFactor)); BigInteger rescaledDivisor = divisorBigInteger.multiply(bigIntegerTenToNth(divisorRescaleFactor)); BigInteger actualQuotient = decodeUnscaledValue(quotient); BigInteger actualRemainder = decodeUnscaledValue(remainder);
decodeUnscaledValue(type.getSlice(block, position)), decimalType.getScale());
dataStream.writeUnscaledValue(value); longDecimalStatisticsBuilder.addValue(new BigDecimal(Decimals.decodeUnscaledValue(value), type.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()); }
return Decimals.decodeUnscaledValue(cursor.getSlice(field));