heavydb icon indicating copy to clipboard operation
heavydb copied to clipboard

Implement ROUND function

Open asuhan opened this issue 9 years ago • 10 comments

We have ROUND_TO_DIGIT which is meant to serve the same purpose, but it isn't precise (converts the first argument to double) and its return type is always DOUBLE.

asuhan avatar Sep 18 '17 21:09 asuhan

Hi, is it OK if I try to close this issue?

pressenna avatar Dec 15 '17 15:12 pressenna

Sure, go ahead and assign yourself.

billmaimone avatar Dec 15 '17 17:12 billmaimone

I have been going through the comments in #72 According to @asuhan the ROUND function shall be implemented in a similar fashion to FLOOR in that it does retain the typeinfo of the first operand. Will this be a reasonable path to a solution?

pressenna avatar Dec 15 '17 20:12 pressenna

Yes, noting also commonly-adopted semantics of the optional second argument.

billmaimone avatar Dec 15 '17 22:12 billmaimone

managed to get the round function working. Was wondering about following use-case:

create table table_a (
  val1 DECIMAL(10,5),
  val2 INT
)

SELECT ROUND(val1, val2) FROM table_a;

Is this a valid use case? Such a query is currently possible.

pressenna avatar Dec 17 '17 20:12 pressenna

Useful bonus points to accept an integer column also for the second column, but uncommon in practical usage. For the implementation did you consider using an existing library function for the implementation?

billmaimone avatar Dec 18 '17 00:12 billmaimone

Yes, I looked at the cmath functions, but none of them allowed me to round a value according to the requirements. I will keep an open eye on this as I am pretty sure this has most likely already been done.

pressenna avatar Dec 18 '17 07:12 pressenna

been thinking about the column as 2nd parameter use case. If this is practically never used, I would prefer to disable it. The rational is: how should it behave if one of the entries in the column is NULL ? Before going into length to address this allowing only constants / literals seems rather straight forward.

pressenna avatar Dec 18 '17 11:12 pressenna

Tried it out after looking a bit at #2 . It actually already behaves correctly in that for NULL 2nd operand a NULL is returned. But this is not the case for DECIMALs and NUMERICS. I will need to fix that.

pressenna avatar Dec 19 '17 08:12 pressenna

This issue has been inactive for a while, and the project has changed substantially. If this still occurs on the latest release, please add reproduction steps and environment details.

psilvest avatar Sep 16 '26 18:09 psilvest