Skip to content

Sum should return 0 if no edge exists, also max( <variable>, 0) should work #4158

@omerose

Description

@omerose

What version of Dgraph are you using?

v1.0.17

Have you tried reproducing the issue with the latest release?

On your site. I ran this (and reproduced) on website with the blade runner example

What is the hardware spec (RAM, OS)?

MBP 2017 16GB Ram, running inside docker

Steps to reproduce the issue (command/config used to run Dgraph).

{
  bladerunner(func: eq(name@en, "Blade Runner")) {
    uid
    name@en
    initial_release_date
    netflix_id
    youDontHaveThisEdge {
     B as count(~provideTag)
    }
    mediaCount: sum(val(B))
  }
}

Expected behaviour and actual result.

Expected behaviour:
mediaCount should be 0

actual results:
Notice that mediaCount is absent from the response

{
  "data": {
    "bladerunner": [
      {
        "uid": "0x394c",
        "name@en": "Blade Runner",
        "initial_release_date": "1982-06-25T00:00:00Z",
        "netflix_id": "70083726",
      }
    ]
  }
}

My current workaround:

{
  bladerunner(func: eq(name@en, "Blade Runner")) {
    uid
    name@en
    initial_release_date
    netflix_id
    youDontHaveThisEdge {
     B as count(~provideTag)
    }
    mediaCount as mediaCount: sum(val(B))
    mathZero as math(0)
    mediaCount2: math( max(mediaCount, mathZero) )
  }
}

which returns:

{
  "data": {
    "bladerunner": [
      {
        "uid": "0x394c",
        "name@en": "Blade Runner",
        "initial_release_date": "1982-06-25T00:00:00Z",
        "netflix_id": "70083726",
        "val(mathZero)": 0,
        "mediaCount2": 0
      }
    ]
  }
}

Keep in mind, I also got forced to make a variable 'math(0)' which seems like another bug, I can't put max( , 0), it returns nothing. If this is a different bug you can reproduce it with the above command as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/querylangIssues related to the query language specification and implementation.kind/enhancementSomething could be better.priority/P2Somehow important but would not block a release.status/acceptedWe accept to investigate/work on it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions