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

It is not possible to create a new node from another using Upsert Block #4712

Open
MichelDiz opened this issue Feb 2, 2020 · 0 comments · May be fixed by #4767
Open

It is not possible to create a new node from another using Upsert Block #4712

MichelDiz opened this issue Feb 2, 2020 · 0 comments · May be fixed by #4767

Comments

@MichelDiz
Copy link
Member

@MichelDiz MichelDiz commented Feb 2, 2020

Experience Report

What you wanted to do

Create a simple way of "versioning nodes" using Upsert Block.
It is something that is very popular in the community.

One important thing to note is that Upsert is not fundamentally created for this (creating new nodes). It is designed to update existing nodes. That is, this would be another feature, which might have another name.

What you actually did

Set my original node (that will keep on the DB)

{
   "set": [
      {
         "dgraph.type": "testNode",
         "title": "Just a test",
         "version": 1
      }
   ]
}
type testNode {
  title
  version
}
upsert {
  query {
    q(func: type(testNode)){
      T as title
      Ver as version
      VerIncr as math(Ver + 1)
    }
  }
  mutation {
    set {
      _:newNode <title> val(T) .
      _:newNode <version> val(VerIncr) .
      _:newNode <dgraph.type> "testNode" .
    }
  }
}

I also tried

upsert {
  query {
    q(func: type(testNode), first:1){
      T as title
      Ver as version
      VerIncr as math(Ver + 1)
    }
  me(){
   sT as sum(val(T))
   sVerIncr as sum(val(VerIncr))
  }
  }
  mutation {
    set {
      _:newNode <title> val(sT) .
      _:newNode <version> val(sVerIncr) .
      _:newNode <dgraph.type> "testNode" .
    }
  }
}

If you run the query below, you gonna see that it creates new nodes indeed, but with no data. Which could be related to #4692 (feels like)

{
  q(func: type(testNode)){
    uid
    title
    version
    dgraph.type
    count(uid)
    count2: count(uid) @filter(has(title))
  }
}

This is a potential duplicated of #4692, but as it has another intention. It feels like a new feature. This could even be used for data migrations. Data treatments from other databases that export in different structures that Dgraph supports.

@MichelDiz MichelDiz added this to Acceptability Decision in Tickets Review Feb 2, 2020
@MichelDiz MichelDiz moved this from Acceptability Decision to Reviewed in Tickets Review Feb 12, 2020
mangalaman93 added a commit that referenced this issue Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Tickets Review
  
Reviewed
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.