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

Divide by 0 error #189

Open
nikhilnanivadekar opened this issue Jan 2, 2019 · 5 comments
Open

Divide by 0 error #189

nikhilnanivadekar opened this issue Jan 2, 2019 · 5 comments

Comments

@nikhilnanivadekar
Copy link
Contributor

In an Operation due to the non-existent NULLIF clause if there is a division then the query throws a divide by 0 error.
For Example:
PersonFinder.age().dividedBy(PersonFinder.daysLived()).greaterThan(365.0) can throw a divide by zero error even if daysLived().notEq(0.0) condition is added.

https://stackoverflow.com/questions/861778/how-to-avoid-the-divide-by-zero-error-in-sql

@mohrezaei
Copy link
Collaborator

I can see more than one way to handle this. My preference would be to implement filterGreaterThan because dividedBy can always be re-written as a multiply, which is also faster:

PersonFinder.age().filterGreaterThan(PersonFinder.daysLived().times(365.0))

filter methods also have a wider use case applicability than division. Multiply, however, may run into overflow issues (highly unlikely with a floating point calculation).

Alternatively, another method like dividedByIgnoreZero or dividedByNullIfZero could be added.

@nikhilnanivadekar
Copy link
Contributor Author

I like filterGreaterThan() because it also solves the problem which is what I was essentially trying to by-pass. Currently, I cannot do greaterThan() as combination of attribute and computation.
For Example: when we need to do percentage computations like daysLived > 0.3*age.

@nikhilnanivadekar
Copy link
Contributor Author

It will also provide functionality to do PersonFinder.age().greaterThan(PersonFinder.daysLived())

@nikhilnanivadekar
Copy link
Contributor Author

Is it possible to get this enhancement?

@mohrezaei
Copy link
Collaborator

Not likely for the next release (17.1.0, next week). Are you working on this?

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

No branches or pull requests

2 participants