@Override public Decimal getDecimal(int rowId, int precision, int scale) { if (isNullAt(rowId)) return null; BigDecimal data = decimalData.vector[getRowIndex(rowId)].getHiveDecimal().bigDecimalValue(); return Decimal.apply(data, precision, scale); }
/** * 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); } }
@Override protected WritableComparable convert(Object value) { return new HiveDecimalWritable(HiveDecimal.create(((Decimal) value).toBigDecimal())); } }
/** * 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); } }
@Override public Decimal getDecimal(int rowId, int precision, int scale) { if (isNullAt(rowId)) return null; BigDecimal data = decimalData.vector[getRowIndex(rowId)].getHiveDecimal().bigDecimalValue(); return Decimal.apply(data, precision, scale); }
public void addValue(int rowId, int column, SpecializedGetters data, ColumnVector output) { if (data.isNullAt(column)) { output.noNulls = false; output.isNull[rowId] = true; } else { output.isNull[rowId] = false; ((DecimalColumnVector) output).vector[rowId].set( HiveDecimal.create(data.getDecimal(column, precision, scale) .toJavaBigDecimal())); } } }
/** * 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); } } } }
@Override public Decimal getDecimal(int rowId, int precision, int scala) { if (baseData.isRepeating) { rowId = 0; } HiveDecimalWritable[] data = decimalData.vector; return Decimal.fromBigDecimal(data[rowId].getHiveDecimal().bigDecimalValue(), precision, scala); }
/** * 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); } } } }
@Override protected Object convert(WritableComparable value) { Preconditions.checkArgument(value instanceof HiveDecimalWritable); HiveDecimal decimal = ((HiveDecimalWritable) value).getHiveDecimal(); int precision = ((DecimalType) fieldType).precision(); int scale = ((DecimalType) fieldType).scale(); return Decimal.fromBigDecimal(decimal.bigDecimalValue(), precision, scale).toBigDecimal(); } }
private void putDecimalWritables( ColumnVector toColumn, int batchSize, int precision, int scale, HiveDecimalWritable decimalWritable) { HiveDecimal decimal = decimalWritable.getHiveDecimal(); Decimal value = Decimal.fromBigDecimal(decimal.bigDecimalValue(), precision, scale); if (Decimal.is32BitDecimal(precision)) { Arrays.fill( ((IntegerColumnVector) toColumn).vector, (int) value.toUnscaledLong()); } else if (Decimal.is64BitDecimal(precision)) { Arrays.fill( ((LongColumnVector) toColumn).vector, value.toUnscaledLong()); } else { byte[] bytes = value.toUnscaledBytes(); for (int i = 0; i < batchSize; i++) { ((BytesColumnVector) toColumn).setVal(i, bytes); } } }
@Override public void convert(UnsafeRowWriter writer, int column, ColumnVector vector, int row) { if (vector.isRepeating) { row = 0; } if (!vector.noNulls && vector.isNull[row]) { writer.setNullAt(column); } else { BigDecimal v = ((DecimalColumnVector) vector).vector[row] .getHiveDecimal().bigDecimalValue(); writer.write(column, new Decimal().set(new scala.math.BigDecimal(v), precision, scale), precision, scale); } }
@Override public void convert(UnsafeArrayWriter writer, int element, ColumnVector vector, int row) { if (vector.isRepeating) { row = 0; } if (!vector.noNulls && vector.isNull[row]) { writer.setNull(element); } else { BigDecimal v = ((DecimalColumnVector) vector).vector[row] .getHiveDecimal().bigDecimalValue(); writer.write(element, new Decimal().set(new scala.math.BigDecimal(v), precision, scale), precision, scale); } } }
private void putDecimalWritable( ColumnVector toColumn, int index, int precision, int scale, HiveDecimalWritable decimalWritable) { HiveDecimal decimal = decimalWritable.getHiveDecimal(); Decimal value = Decimal.fromBigDecimal(decimal.bigDecimalValue(), precision, scale); if (Decimal.is32BitDecimal(precision)) { ((IntegerColumnVector) toColumn).vector[index] = (int) value.toUnscaledLong(); } else if (Decimal.is64BitDecimal(precision)) { ((LongColumnVector) toColumn).vector[index] = value.toUnscaledLong(); } else { byte[] bytes = value.toUnscaledBytes(); ((BytesColumnVector) toColumn).setVal(index, bytes); } } }
int precision = ((DecimalType) fieldType).precision(); int scala = ((DecimalType) fieldType).scale(); Decimal decimal = Decimal.fromBigDecimal(data[index].getHiveDecimal().bigDecimalValue(), precision, scala); if (Decimal.is32BitDecimal(precision)) { return (int) (decimal.toUnscaledLong());