Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-21617

HBase Bytes.putBigDecimal error

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0, 2.0.0, 2.1.1
    • Fix Version/s: 2.0.0
    • Component/s: util
    • Labels:
      None
    • Environment:

      JDK 1.8

    • Release Note:
      The patch affects only the Bytes.putBigDecimal() method.

      Description

      hbase-common/

      org.apache.hadoop.hbase.util.Bytes:

      public static int putBigDecimal(byte[] bytes, int offset, BigDecimal val) {
        if (bytes == null)

      {     return offset;   }

        byte[] valueBytes = val.unscaledValue().toByteArray();
        byte[] result = new byte[valueBytes.length + SIZEOF_INT];
        offset = putInt(result, offset, val.scale());
      return putBytes(result, offset, valueBytes, 0, valueBytes.length); // this one, bytes is not used
      }

      Test:
      byte[] bytes = new byte[64];
      BigDecimal bigDecimal = new BigDecimal("100.10");
      Bytes.putBigDecimal(bytes, 4, bigDecimal);
      System.out.println(Arrays.toString(bytes)); // invalid

      Suggest:
      public static int putBigDecimal(byte[] bytes, int offset, BigDecimal val)

      {   byte[] valueBytes = toBytes(val);   return putBytes(bytes, offset, valueBytes, 0, valueBytes.length); }

        Attachments

        1. HBASE-21617.master.v2.patch
          2 kB
          apcahephoenix

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              apcahephoenix apcahephoenix
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: