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

Bug with multi-level Upsert Block #4692

Closed
MichelDiz opened this issue Jan 29, 2020 · 4 comments
Closed

Bug with multi-level Upsert Block #4692

MichelDiz opened this issue Jan 29, 2020 · 4 comments
Labels
area/upsert Issues related to upsert operations. kind/bug Something is broken. status/accepted We accept to investigate/work on it.

Comments

@MichelDiz
Copy link
Contributor

What version of Dgraph are you using?

Latest

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).

Mutation Sample

I added "dgraph.type" just to be sure.

{
  "set": [
    {
      "type": "node",
      "dgraph.type": "Node",
      "id": "0",
      "labels": ["Movie"],
      "properties": {
        "tagline": "Welcome to the Real World",
        "title": "The Matrix",
        "released": 1999,
        "dgraph.type": "Properties"
      }
    }
]
}
type Node {
  properties
  type
  id
  labels
  tagline
  title
  released
}

type Properties {
  tagline
  title
  released
}

Query example

{  
  movies(func: has(properties)) @filter(eq(type,"node")){
    type
    id
    labels
    dgraph.type
    properties {
      tagline
      title
      released
    }
      tagline
      title
      released
  }
}

Run the Upsert Block

upsert {
  query {
    movies(func: has(type)) @filter(has(properties)){
      v as uid
      Labels as labels
      properties {
        Title as title
        Released as released
        Tagline as tagline
      }
    }
  }
  mutation {
    set {
      uid(v) <migrationDone> "True" .
      uid(v) <title> val(Title) .
      uid(v) <dgraph.type> val(Labels) .
      uid(v) <released> val(Released) .
      uid(v) <tagline> val(Tagline) .
    }
  }
}

Expected behaviour and actual result.

This operation should be able to copy the values ​​in the variables of the nested block, "properties". Thus allowing a kind of "migration" using Upsert Block. This feature is also equivalent to "merge". Where we collect the values ​​of the nested block, we paste in the target node and delete the nested block right after.

@MichelDiz MichelDiz added area/upsert Issues related to upsert operations. kind/enhancement Something could be better. labels Jan 29, 2020
@MichelDiz
Copy link
Contributor Author

MichelDiz commented Jan 29, 2020

With this "Hack" I was able to make it work

WARNING - This "hack" works mutation by mutation. Not Bulk Upsert. If you try to bulk upsert, it can get crazy results.

upsert {
  query {
    movies(func: has(type)) @filter(has(properties)){
      v as uid
      Labels as labels
      properties {
        Title as title
        Released as released
        Tagline as tagline
      }
    }
 me() {
    TitleMe as sum(val(Title))
    ReleasedMe as sum(val(Released))
    TaglineMe as sum(val(Tagline))
  }
  }
  mutation {
    set {
      uid(v) <migrationDone> "True" .
      uid(v) <title> val(TitleMe) .
      uid(v) <dgraph.type> val(Labels) .
      uid(v) <released> val(ReleasedMe) .
      uid(v) <tagline> val(TaglineMe) .
    }
  }
}

@mangalaman93 mangalaman93 self-assigned this Jan 29, 2020
@mangalaman93 mangalaman93 added the status/accepted We accept to investigate/work on it. label Jan 29, 2020
@mangalaman93
Copy link
Member

Thanks for finding the bug @MichelDiz. val doesn't seem to work when a value variable is defined in a nested block. Let me think about a fix for this.

@MichelDiz MichelDiz added kind/bug Something is broken. and removed kind/enhancement Something could be better. labels Jan 29, 2020
@mangalaman93 mangalaman93 removed their assignment Feb 14, 2020
@MichelDiz
Copy link
Contributor Author

MichelDiz commented Feb 14, 2020

Just an Update

Testing the PR #4767 for this issue - but now creating a new node instead of update it (which is the goal of 4692, to just update instead of creating new ones). It works like that.

pay attention that this would work only with 1 to 1 operation. It won't work in 1 to many (like bulk upsert).

upsert {
  query {
    movies(func: has(type), first:1) @filter(has(properties) AND not has(migrationDone)){
     uid
      qID as id
      Labels as labels
      properties {
        Title as title
        Released as released
        Tagline as tagline
      }
    }
 me() {
    LabelsMe as sum(val(Labels))
    TitleMe as sum(val(Title))
    ReleasedMe as sum(val(Released))
    TaglineMe as sum(val(Tagline))
    qIDMe as sum(val(qID))
  }
  }
  mutation {
    set {
      _:New <migrationDone> "True" .
      _:New <id> val(qIDMe) .
      _:New <title> val(TitleMe) .
      _:New <dgraph.type> val(LabelsMe) .
      _:New <released> val(ReleasedMe) .
      _:New <tagline> val(TaglineMe) .
    }
  }
}

@MichelDiz
Copy link
Contributor Author

MichelDiz commented Feb 14, 2020

closing due to a bug in syncing tickets

new issue #4779

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. kind/bug Something is broken. status/accepted We accept to investigate/work on it.
Development

No branches or pull requests

2 participants