Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-1864

Decimal conversion should convert values with scale less than intended scale instead of erroring.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Won't Fix
    • 1.7.6
    • None
    • None
    • None

    Description

      Using Sqoop to import data to AVRO can mean that decimal scales in the incoming values do not match the scales expected in AVRO. In this situation AVRO file creation fails. However, in some cases this is not the correct behaviour, given a value of 3.1 and a scale of 3 the value will fit into the scale requirements and so should be adjusted.

      Looking through the code this seems to be enforced here:

      src/main/java/org/apache/avro/Conversions.java
      public ByteBuffer toBytes(BigDecimal value, Schema schema, LogicalType type) {
      int scale = ((LogicalTypes.Decimal) type).getScale();
      if (scale != value.scale()) {
      throw new AvroTypeException("Cannot encode decimal with scale " +
      value.scale() + " as scale " + scale);

      Should this not be:

      if (scale < value.scale()) {

      The same applies in: toFixed()

      Attachments

        Activity

          People

            rdblue Ryan Blue
            tscott@cloudera.com Thomas Scott
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: