/** * Create a decimal writable with no current value (i.e. isSet() will return false). */ @HiveDecimalWritableVersionV1 public HiveDecimalWritable() { super(); isSet = false; internalScratchLongs = null; internalScratchBuffer = null; }
@HiveDecimalWritableVersionV1 public void set(byte[] bytes, int scale) { this.internalStorage = bytes; this.scale = scale; }
@HiveDecimalWritableVersionV1 public int getScale() { return scale; }
/** * Create a decimal writable with an initial value from BigInteger bytes and a specified scale. * <p> * If the conversion to decimal is successful, isSet() will return true. * */ @HiveDecimalWritableVersionV1 public HiveDecimalWritable(byte[] bigIntegerBytes, int scale) { super(); setFromBigIntegerBytesAndScale(bigIntegerBytes, scale); }
/** * Set a decimal writable's value from BigInteger bytes and a specified scale. * <p> * If the conversion to decimal is successful, isSet() will return true. * */ @HiveDecimalWritableVersionV1 public void set(byte[] bigIntegerBytes, int scale) { setFromBigIntegerBytesAndScale(bigIntegerBytes, scale); }
/** * Create a decimal writable with an initial value from a long with scale 0. * <p> * Afterwards, the isSet() method will return true. * */ @HiveDecimalWritableVersionV1 public HiveDecimalWritable(long longValue) { super(); setFromLong(longValue); }
/** * Create a decimal writable with an initial value from another decimal writable. * <p> * If the supplied writable has a value, isSet() will return true. * */ @HiveDecimalWritableVersionV1 public HiveDecimalWritable(HiveDecimalWritable writable) { super(); set(writable); }
/** * Create a decimal writable with an initial value from a HiveDecimal. * <p> * Afterwards, the isSet() method will return true, unless value is null. * */ @HiveDecimalWritableVersionV1 public HiveDecimalWritable(HiveDecimal value) { super(); set(value); }
@HiveDecimalWritableVersionV1 public HiveDecimalWritableV1(HiveDecimalV1 value) { set(value); }
@HiveDecimalWritableVersionV1 public HiveDecimalV1 getHiveDecimal() { return HiveDecimalV1.create(new BigInteger(internalStorage), scale); }
@HiveDecimalWritableVersionV1 @Override public void readFields(DataInput in) throws IOException { scale = WritableUtils.readVInt(in); int byteArrayLen = WritableUtils.readVInt(in); if (internalStorage.length != byteArrayLen) { internalStorage = new byte[byteArrayLen]; } in.readFully(internalStorage); }
@HiveDecimalWritableVersionV1 @Override public int hashCode() { if (!isSet()) { throw new RuntimeException("no value set"); } return fastHashCode(); }
@HiveDecimalWritableVersionV1 public int getScale() { if (!isSet()) { throw new RuntimeException("no value set"); } return fastScale(); }
@HiveDecimalWritableVersionV1 @Override public String toString() { if (!isSet()) { throw new RuntimeException("no value set"); } return fastToString(); }
@HiveDecimalWritableVersionV1 @Override public void write(DataOutput out) throws IOException { WritableUtils.writeVInt(out, scale); WritableUtils.writeVInt(out, internalStorage.length); out.write(internalStorage); }
@HiveDecimalWritableVersionV1 @Override public int hashCode() { return getHiveDecimal().hashCode(); }
@HiveDecimalWritableVersionV1 @Override public String toString() { return getHiveDecimal().toString(); }
@HiveDecimalWritableVersionV1 public HiveDecimalWritableV1(long value) { set((HiveDecimalV1.create(value))); }
@HiveDecimalWritableVersionV1 @Override public int compareTo(HiveDecimalWritable writable) { if (!isSet() || writable == null || !writable.isSet()) { throw new RuntimeException("Invalid comparision operand(s)"); } return fastCompareTo(writable); }
@HiveDecimalWritableVersionV1 @Override public int compareTo(HiveDecimalWritableV1 that) { return getHiveDecimal().compareTo(that.getHiveDecimal()); }