Updated documentation of round function return type by matthewryanwells · Pull Request #1725 · opensearch-project/sql · GitHub
Skip to content

Updated documentation of round function return type#1725

Merged
Yury-Fridlyand merged 3 commits into
opensearch-project:mainfrom
Bit-Quill:round-return-documentation
Jun 22, 2023
Merged

Updated documentation of round function return type#1725
Yury-Fridlyand merged 3 commits into
opensearch-project:mainfrom
Bit-Quill:round-return-documentation

Conversation

@matthewryanwells

@matthewryanwells matthewryanwells commented Jun 8, 2023

Copy link
Copy Markdown
Contributor

Description

Small fix to incorrect return type in the round function documentation, below in the function implementation in org/opensearch/sql/expression/operator/arthmetic/MathematicalFunction.java that it should be either returning long or double depending if the first variable was either integer/long or float/double respectively.

private static DefaultFunctionResolver round() {
    return define(BuiltinFunctionName.ROUND.getName(),
        // rand(x)
        impl(nullMissingHandling(v -> new ExprLongValue((long) Math.round(v.integerValue()))),
            LONG, INTEGER),
        impl(nullMissingHandling(v -> new ExprLongValue((long) Math.round(v.longValue()))),
            LONG, LONG),
        impl(nullMissingHandling(v -> new ExprDoubleValue((double) Math.round(v.floatValue()))),
            DOUBLE, FLOAT),
        impl(nullMissingHandling(v -> new ExprDoubleValue(new BigDecimal(v.doubleValue())
                .setScale(0, RoundingMode.HALF_UP).doubleValue())),
            DOUBLE, DOUBLE),

        // rand(x, d)
        impl(nullMissingHandling((x, d) -> new ExprLongValue(new BigDecimal(x.integerValue())
                .setScale(d.integerValue(), RoundingMode.HALF_UP).longValue())),
            LONG, INTEGER, INTEGER),
        impl(nullMissingHandling((x, d) -> new ExprLongValue(new BigDecimal(x.longValue())
                .setScale(d.integerValue(), RoundingMode.HALF_UP).longValue())),
            LONG, LONG, INTEGER),
        impl(nullMissingHandling((x, d) -> new ExprDoubleValue(new BigDecimal(x.floatValue())
                .setScale(d.integerValue(), RoundingMode.HALF_UP).doubleValue())),
            DOUBLE, FLOAT, INTEGER),
        impl(nullMissingHandling((x, d) -> new ExprDoubleValue(new BigDecimal(x.doubleValue())
                .setScale(d.integerValue(), RoundingMode.HALF_UP).doubleValue())),
            DOUBLE, DOUBLE, INTEGER));
  }

Issues Resolved

No connected issue

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Matthew Wells <matthew.wells@improving.com>
@codecov

codecov Bot commented Jun 8, 2023

Copy link
Copy Markdown

@Yury-Fridlyand

Copy link
Copy Markdown
Collaborator

Is it related to #1138?

@Yury-Fridlyand Yury-Fridlyand left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing changed in docs, but I think you can fix #1138 as far as you're here. It returns DOUBLE in some cases.

Signed-off-by: Matthew Wells <matthew.wells@improving.com>
@matthewryanwells

Copy link
Copy Markdown
Contributor Author

Signed-off-by: Matthew Wells <matthew.wells@improving.com>
@Yury-Fridlyand Yury-Fridlyand merged commit 34cad6e into opensearch-project:main Jun 22, 2023
@Yury-Fridlyand Yury-Fridlyand deleted the round-return-documentation branch June 22, 2023 19:39
opensearch-trigger-bot Bot pushed a commit that referenced this pull request Jun 22, 2023
* fixed round documentation

Signed-off-by: Matthew Wells <matthew.wells@improving.com>
(cherry picked from commit 34cad6e)
acarbonetto pushed a commit to Bit-Quill/opensearch-project-sql that referenced this pull request Jun 22, 2023
…ct#1725)

* fixed round documentation

Signed-off-by: Matthew Wells <matthew.wells@improving.com>
Yury-Fridlyand pushed a commit that referenced this pull request Jun 22, 2023
* fixed round documentation

Signed-off-by: Matthew Wells <matthew.wells@improving.com>
(cherry picked from commit 34cad6e)

Co-authored-by: Matthew Wells <matthew.wells@improving.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants