Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

result convert to float automatically #3963

Closed
wjcnoob opened this issue Mar 2, 2022 · 7 comments
Closed

result convert to float automatically #3963

wjcnoob opened this issue Mar 2, 2022 · 7 comments
Labels
type/enhancement Type: make the code neat or more efficient

Comments

@wjcnoob
Copy link

wjcnoob commented Mar 2, 2022

Introduction

return 24/48
output: 0

Contents

It would be great if the result could be automatically converted to float instead of adding toFloat() every time

Related work

@wjcnoob wjcnoob added the type/enhancement Type: make the code neat or more efficient label Mar 2, 2022
@Shylock-Hg
Copy link
Contributor

I don't think it's reasonable, not all users want float instead of integer in any scenes.

@wjcnoob
Copy link
Author

wjcnoob commented Mar 2, 2022

But a indicator caculated like that is just wrong.

@wey-gu
Copy link
Contributor

wey-gu commented Mar 2, 2022

But an indicator calculated like that is just wrong.

/ in int stands for the mod(取模) and in float, it stands for division(除法).

You could check this in SQL:

SELECT 1/2,1.0/2

And the result will be:
Screen Shot 2022-03-02 at 6 32 43 PM

You could play with it from here: https://sqliteonline.com/

@wjcnoob
Copy link
Author

wjcnoob commented Mar 2, 2022

But an indicator calculated like that is just wrong.

/ in int stands for the mod(取模) and in float, it stands for division(除法).

You could check this in SQL:

SELECT 1/2,1.0/2

And the result will be: Screen Shot 2022-03-02 at 6 32 43 PM

You could play with it from here: https://sqliteonline.com/

Well, I'm using hive, and hive returns 0.5.
OK , it doesn't really matter.

@wey-gu
Copy link
Contributor

wey-gu commented Mar 3, 2022

Aha, thanks @wjcnoob for letting me know it's actually quite normal to treat / as division and another expression for the mod, which(like it was done in HIVE), I think is better than the current implicit approach in nGQL/SQL, but this behavior seems to be not possible to change due to it's correct(not the best way though) and will be a breaking change.

Could you please add toFloat() to one of the int values only(not as painful as toFloat() for all of them)? (sorry for this)

(root@nebula) [basketballplayer]> RETURN toFloat(24)/48
+------------------+
| (toFloat(24)/48) |
+------------------+
| 0.5              |
+------------------+
Got 1 rows (time spent 905/23873 us)

Thu, 03 Mar 2022 09:42:09 CST

Thanks again!!!

@wjcnoob
Copy link
Author

wjcnoob commented Mar 3, 2022

Aha, thanks @wjcnoob for letting me know it's actually quite normal to treat / as division and another expression for the mod, which(like it was done in HIVE), I think is better than the current implicit approach in nGQL/SQL, but this behavior seems to be not possible to change due to it's correct(not the best way though) and will be a breaking change.

Could you please add toFloat() to one of the int values only(not as painful as toFloat() for all of them)? (sorry for this)

(root@nebula) [basketballplayer]> RETURN toFloat(24)/48
+------------------+
| (toFloat(24)/48) |
+------------------+
| 0.5              |
+------------------+
Got 1 rows (time spent 905/23873 us)

Thu, 03 Mar 2022 09:42:09 CST

Thanks again!!!

Of course, it's understandable

@wey-gu
Copy link
Contributor

wey-gu commented Mar 3, 2022

Thank you @wjcnoob !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Type: make the code neat or more efficient
Projects
None yet
Development

No branches or pull requests

3 participants