Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-1945

Allow custom return types for AVG/VARIANCE/STDDEV/COVAR

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.14.0
    • Component/s: None
    • Labels:
      None

      Description

      For example, return types of AVG() is the input type. So, if the input is INT/BIGINT type, AVG() is always truncated. Depending on the database, some database follow this behavior while others (e.g. Oracle/MySQL/etc.) do not and return floating point values for AVG().

      Similar for other functions mentioned here.

        Activity

        Hide
        michaelmior Michael Mior added a comment -

        Resolved in release 1.14.0 (2017-10-01)

        Show
        michaelmior Michael Mior added a comment - Resolved in release 1.14.0 (2017-10-01)
        Show
        julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/4208d802 .
        Hide
        minjikim MinJi Kim added a comment -

        Thank you for the review, Julian Hyde! I am sorry for the delay in getting back with an updated patch. I am still traveling, but now do have some time to get back to this. I have updated the PR, and addressed the comments you gave. RexBuilder.ensureType() really do make the code nicer. Thanks for the pointer!

        https://github.com/apache/calcite/pull/518

        Show
        minjikim MinJi Kim added a comment - Thank you for the review, Julian Hyde ! I am sorry for the delay in getting back with an updated patch. I am still traveling, but now do have some time to get back to this. I have updated the PR, and addressed the comments you gave. RexBuilder.ensureType() really do make the code nicer. Thanks for the pointer! https://github.com/apache/calcite/pull/518
        Hide
        julianhyde Julian Hyde added a comment -

        Review comments for https://github.com/apache/calcite/pull/518/commits/d92bd5f5a73a3a355251221fedcaf95062ea447a:

        • When comparing enums (SqlKind in this case) try to use switch.
        • Consider moving SqlAvgAggFunction.AVG_AGG_FUNCTIONS into SqlKind. SqlKind already has several composites.
        • Instead of "if ... RexBuilder.makeAbstractCast", use RexBuilder.ensureType where possible
        Show
        julianhyde Julian Hyde added a comment - Review comments for https://github.com/apache/calcite/pull/518/commits/d92bd5f5a73a3a355251221fedcaf95062ea447a: When comparing enums (SqlKind in this case) try to use switch. Consider moving SqlAvgAggFunction.AVG_AGG_FUNCTIONS into SqlKind. SqlKind already has several composites. Instead of "if ... RexBuilder.makeAbstractCast", use RexBuilder.ensureType where possible
        Hide
        minjikim MinJi Kim added a comment -

        I have a first draft of this patch here. I would like to make sure that this is a proper approach. Since we always expand AVG/VAR/STDDEV functions, so I am adding casts before we dividing the numerator and denominator. Let me know if it should be done in another way. Thanks!

        https://github.com/apache/calcite/pull/518

        Show
        minjikim MinJi Kim added a comment - I have a first draft of this patch here. I would like to make sure that this is a proper approach. Since we always expand AVG/VAR/STDDEV functions, so I am adding casts before we dividing the numerator and denominator. Let me know if it should be done in another way. Thanks! https://github.com/apache/calcite/pull/518

          People

          • Assignee:
            julianhyde Julian Hyde
            Reporter:
            minjikim MinJi Kim
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development