/** * Put a `HiveDecimalWritable` to a `WritableColumnVector`. */ private static void putDecimalWritable( WritableColumnVector toColumn, int index, int precision, int scale, HiveDecimalWritable decimalWritable) { HiveDecimal decimal = decimalWritable.getHiveDecimal(); Decimal value = Decimal.apply(decimal.bigDecimalValue(), decimal.precision(), decimal.scale()); value.changePrecision(precision, scale); if (precision <= Decimal.MAX_INT_DIGITS()) { toColumn.putInt(index, (int) value.toUnscaledLong()); } else if (precision <= Decimal.MAX_LONG_DIGITS()) { toColumn.putLong(index, value.toUnscaledLong()); } else { byte[] bytes = value.toJavaBigDecimal().unscaledValue().toByteArray(); toColumn.arrayData().putBytes(index * 16, bytes.length, bytes, 0); toColumn.putArray(index, index * 16, bytes.length); } }
/** * Put a `HiveDecimalWritable` to a `WritableColumnVector`. */ private static void putDecimalWritable( WritableColumnVector toColumn, int index, int precision, int scale, HiveDecimalWritable decimalWritable) { HiveDecimal decimal = decimalWritable.getHiveDecimal(); Decimal value = Decimal.apply(decimal.bigDecimalValue(), decimal.precision(), decimal.scale()); value.changePrecision(precision, scale); if (precision <= Decimal.MAX_INT_DIGITS()) { toColumn.putInt(index, (int) value.toUnscaledLong()); } else if (precision <= Decimal.MAX_LONG_DIGITS()) { toColumn.putLong(index, value.toUnscaledLong()); } else { byte[] bytes = value.toJavaBigDecimal().unscaledValue().toByteArray(); toColumn.arrayData().putBytes(index * 16, bytes.length, bytes, 0); toColumn.putArray(index, index * 16, bytes.length); } }
/** * Put `HiveDecimalWritable`s to a `WritableColumnVector`. */ private static void putDecimalWritables( WritableColumnVector toColumn, int size, int precision, int scale, HiveDecimalWritable decimalWritable) { HiveDecimal decimal = decimalWritable.getHiveDecimal(); Decimal value = Decimal.apply(decimal.bigDecimalValue(), decimal.precision(), decimal.scale()); value.changePrecision(precision, scale); if (precision <= Decimal.MAX_INT_DIGITS()) { toColumn.putInts(0, size, (int) value.toUnscaledLong()); } else if (precision <= Decimal.MAX_LONG_DIGITS()) { toColumn.putLongs(0, size, value.toUnscaledLong()); } else { byte[] bytes = value.toJavaBigDecimal().unscaledValue().toByteArray(); toColumn.arrayData().reserve(bytes.length); toColumn.arrayData().putBytes(0, bytes.length, bytes, 0); for (int index = 0; index < size; index++) { toColumn.putArray(index, 0, bytes.length); } } } }
/** * Put `HiveDecimalWritable`s to a `WritableColumnVector`. */ private static void putDecimalWritables( WritableColumnVector toColumn, int size, int precision, int scale, HiveDecimalWritable decimalWritable) { HiveDecimal decimal = decimalWritable.getHiveDecimal(); Decimal value = Decimal.apply(decimal.bigDecimalValue(), decimal.precision(), decimal.scale()); value.changePrecision(precision, scale); if (precision <= Decimal.MAX_INT_DIGITS()) { toColumn.putInts(0, size, (int) value.toUnscaledLong()); } else if (precision <= Decimal.MAX_LONG_DIGITS()) { toColumn.putLongs(0, size, value.toUnscaledLong()); } else { byte[] bytes = value.toJavaBigDecimal().unscaledValue().toByteArray(); toColumn.arrayData().reserve(bytes.length); toColumn.arrayData().putBytes(0, bytes.length, bytes, 0); for (int index = 0; index < size; index++) { toColumn.putArray(index, 0, bytes.length); } } } }