Skip to content

[C++] DECIMAL's precision and scale compute rules in add/substract and divide is different with doc #40123

Closed

Description

@ZhangHuiGui

Describe the bug, including details regarding any error messages, version, and platform.

Our decimal compute rules are compatible with Redshift’s decimal promotion rules.
In doc: https://arrow.apache.org/docs/cpp/compute.html#arithmetic-functions, we have the rules:
image

But during we add the decimal binary kernels, when we compute out_type, the rules are different in add/subtract and divide.

Add/subtract:

        const int32_t scale = s1;
        const int32_t precision = std::max(p1 - s1, p2 - s2) + scale + 1;
        return std::make_pair(precision, scale);

Divide:

        const int32_t scale = s1 - s2;
        const int32_t precision = p1;
        return std::make_pair(precision, scale);

Obviously they are wrong, did i miss some background knowledge?

Component(s)

C++

Activity

  1. ZhangHuiGui commented on Feb 19, 2024

    @ZhangHuiGui
    ContributorAuthor

    Oh, it's not a problem.
    We have done the precision and scale cast in ArithmeticFunction's DispatchBest before execute the kernel and resolve the output type through OutputType's resolver_.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions