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

Closed
MichelDiz opened this issue Feb 2, 2020 · 0 comments · Fixed by #4767
Closed

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

MichelDiz opened this issue Feb 2, 2020 · 0 comments · Fixed by #4767
Labels
area/upsert Issues related to upsert operations. exp/intermediate Fixing this requires some experience with the project. kind/bug Something is broken. status/accepted We accept to investigate/work on it.

Comments

@MichelDiz
Copy link
Contributor

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 kind/feature Something completely new we should consider. exp/intermediate Fixing this requires some experience with the project. area/upsert Issues related to upsert operations. labels Feb 2, 2020
@MichelDiz MichelDiz added the status/accepted We accept to investigate/work on it. label Feb 12, 2020
@danielmai danielmai added kind/bug Something is broken. and removed kind/feature Something completely new we should consider. labels Mar 20, 2020
dgraph-bot pushed a commit that referenced this issue Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/upsert Issues related to upsert operations. exp/intermediate Fixing this requires some experience with the project. kind/bug Something is broken. status/accepted We accept to investigate/work on it.
Development

Successfully merging a pull request may close this issue.

2 participants