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

Invalid division by zero #2733

Closed
mehdiym opened this issue Nov 7, 2018 · 3 comments
Closed

Invalid division by zero #2733

mehdiym opened this issue Nov 7, 2018 · 3 comments
Assignees
Labels
kind/bug Something is broken.

Comments

@mehdiym
Copy link

mehdiym commented Nov 7, 2018

  • What version of Dgraph are you using?
    1.0.10

  • Have you tried reproducing the issue with latest release?
    It worked with 1.0.9 but bugs with 1.0.10

  • What is the hardware spec (RAM, OS)?
    Linux Debian Testing, 16GoDDR

  • Steps to reproduce the issue (command/config used to run Dgraph).
    In a query, I do a division and protect potential 0 value for the divisor with a 'max' function.
    The error only happens with value variables, it works with numeric values.
    I also tried to protect the division with a 'cond' without success.

Here is my query:

{
var(func: uid("0xea61")) {
	ct_thinks as count(thinks)
	knows {
		ct_knows as math(1)
	}
	sum_knows as sum(val(ct_knows))
}
me(func: uid("0xea61")) {
	avg: math(ct_thinks / max(1, sum_knows))
}
}
  • Expected behaviour and actual result.
    If sum_knows equals to 0 then avg should be 0.
    If I replace ct_thinks with a literal value, then no more bug.
@manishrjain manishrjain added the investigate Requires further investigation label Nov 7, 2018
@mehdiym
Copy link
Author

mehdiym commented Nov 8, 2018

I simplified the query.
The bug disappears if:

  • sum_knows is set to math(1) instead of a sum
  • ct_thinks is replaced with a number

@srfrog srfrog self-assigned this Nov 8, 2018
@srfrog srfrog added kind/bug Something is broken. and removed investigate Requires further investigation labels Nov 14, 2018
@srfrog
Copy link
Contributor

srfrog commented Nov 14, 2018

Thanks for reporting this. The div0 error is correct but appears to be for the wrong reason.

If I understand correctly, ct_thinks evaluates to zero, and sum_knows also evaluates to zero. so avg should be 0 / 1 == 0. Is this correct?

@mehdiym
Copy link
Author

mehdiym commented Nov 15, 2018

Correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something is broken.
Development

No branches or pull requests

3 participants