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

uid function not working in upsert for variables with values #4424

Closed
campoy opened this issue Dec 16, 2019 · 0 comments · Fixed by #4425
Closed

uid function not working in upsert for variables with values #4424

campoy opened this issue Dec 16, 2019 · 0 comments · Fixed by #4425
Assignees
Labels
area/data-loss Issues related to loss of data. area/upsert Issues related to upsert operations. priority/P0 Critical issue that requires immediate attention.

Comments

@campoy
Copy link
Contributor

campoy commented Dec 16, 2019

What version of Dgraph are you using?

master

Have you tried reproducing the issue with the latest release?

yes

What is the hardware spec (RAM, OS)?

n/a

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

Create a counter value with the following mutation:

{
  set {
    _:p <value> "0"^^<xs:int> .
  }
}

Then increment its value with the given upsert block:

upsert {
  query {
    q(func: has(value)) {
      value as value
      inc as math(value+1)
    }
  }
  
  mutation {
    set {
      uid(inc) <value> val(inc) .
    }
  }
}

Expected behaviour and actual result.

The upsert above should return the previous counter value (0) and the value of inc (1), as follows:

{
  "data": {
    "code": "Success",
    "message": "Done",
    "queries": {
      "q": [
        {
          "value": 0,
          "val(inc)": 1
        }
      ]
    },
    "uids": {}
  },
  [...]
}

And a query should return the new value is 1.

 {
    q(func: has(value)) {
      value
    }
}
{
  "data": {
    "q": [
      {
        "value": 1
      }
    ]
  },
  [...]
}

Encountered behavior

The upsert returns the same value in this case, but no operation is actually performed.
We can see this using the previous query:

 {
    q(func: has(value)) {
      value
    }
}
{
  "data": {
    "q": [
      {
        "value": 0
      }
    ]
  },
  [...]
}

Even worse, if we change the upsert to set the value of value to 42 instead of using val(inc) a new UID will be created.

Running this upsert:

upsert {
  query {
    q(func: has(value)) {
      value as value
      inc as math(value+1)
    }
  }
  
  mutation {
    set {
      uid(inc) <value> "42" .
    }
  }
}
{
  "data": {
    "code": "Success",
    "message": "Done",
    "queries": {
      "q": [
        {
          "value": 0,
          "val(inc)": 1
        }
      ]
    },
    "uids": {
      "uid(inc)": "0x2"
    }
  },
  [...]
}

Instead of updating the previous value it created a new UID, as shown in the query below.

 {
    q(func: has(value)) {
      value
    }
}
{
  "data": {
    "q": [
      {
        "value": 0
      },
      {
        "value": 42
      }
    ]
  },
  [...]
}
@campoy campoy added priority/P0 Critical issue that requires immediate attention. area/data-loss Issues related to loss of data. area/upsert Issues related to upsert operations. labels Dec 16, 2019
@campoy campoy self-assigned this Dec 16, 2019
campoy added a commit that referenced this issue Dec 16, 2019
Currently, only variables containing UIDs (e.g. `uid as uid`) work correctly
when used in upsert blocks with the `uid` function.

With this fix, all variables (e.g. `value as value`) work appropriately, as we
fetch the list of UIDs from the keys in the value map when needed.

Fixes #4424
campoy pushed a commit that referenced this issue Dec 17, 2019
* Make uid function work with value variables in upsert blocks

Currently, only variables containing UIDs (e.g. `uid as uid`) work correctly
when used in upsert blocks with the `uid` function.

With this fix, all variables (e.g. `value as value`) work appropriately, as we
fetch the list of UIDs from the keys in the value map when needed.

Fixes #4424

* added tests for upsert with value variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/data-loss Issues related to loss of data. area/upsert Issues related to upsert operations. priority/P0 Critical issue that requires immediate attention.
Development

Successfully merging a pull request may close this issue.

1 participant