Skip to content

[transform][decimal] Add a function to down scale decimal #75

Description

@aymkhalil

In order to deal to support use cases where a decimal value has to be downscaled to fit into existing decimal schema with a certain scale, it is useful to allow users to downscale there decimals. The propose is to add a function with the following signature:

decimalFromNumberWithScale(decimal, scale)

For more context about why such method is needed, check the example below:
Given the following schema

{
        "name": "v2",
        "type": [
          "null",
          {
            "type": "bytes",
            "logicalType": "decimal",
            "precision": 4,
            "scale": 3
          }
        ]
}

The user can send a deceased scale value like 1.3, however increasing the scale by sending a value like 1.33499 would fail with

org.apache.avro.AvroTypeException: Cannot encode decimal with scale 5 as scale 3 without rounding in field v2

(for more details, check: #69 (comment))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions