Predicate Update from Scalar to Array

Hi,

I have an existing Schema. And will Upgrade this.

From:
<Rating_rates>: UID @reverse .
To:
<Rating_rates>: [UID] @reverse .

How could this be done without losing my data?
I have also the situation that I will do this backward. There is a data issue, I know. But is there a Way how this could be done? For Example, using the latest created edge.

Thx

Try these operations:

upsert {
  query {
    v as var(func: has(Rating_rates)) {
      a as Rating_rates
    }
  }

  mutation {
    # we copy the values from the old predicate
    # Facets will be lost
    set {
      uid(v) <tmp> uid(a) .
    }
  }
}

Now run

curl -X POST localhost:8080/alter -d '{"drop_attr": "Rating_rates"}'

And

$ curl -X POST localhost:8080/alter -d '<Rating_rates>: [uid] @reverse .'

And finally

upsert {
  query {
    v as var(func: has(tmp)) {
      a as tmp
    }
  }

  mutation {
    # we copy the values from the old predicate
    set {
      uid(v) <Rating_rates> uid(a) .
    }

  }
}
curl -X POST localhost:8080/alter -d '{"drop_attr": "tmp"}'

Hi Enrico Hofmann, Welcome to our discuss forum.
You can do without losing any data.

From:
<Rating_rates>: UID @reverse .
To:
<Rating_rates>: [UID] @reverse .
``

But for doing reverse you have you first drop the predicate , which will delete all data.
I guess you want to only keep latest value, let me check if there is way to do that.

Hi Michel ,nice solution. This will convert uid to [uid]. I think we can do same for Rating_rates to [Rating_rates], by changing [uid] to uid in

$ curl -X POST localhost:8080/alter -d '<Rating_rates>: uid @reverse .'

Is that correct ? if yes , i wonder which value of list will be copied to Rating_rates.
But i guess we already have entire array in tmp, we can search for values there and select from there.

Do you mean to do the opposite?

I guess for his case he has only 1 UID per edge. But in the case of opposite, transforming the Rating_rates from many to many in 1:1, I think this will be lost data (not truly sure).

In my opinion, isn’t a good idea to move from [UID] to UID

yeah i mean the opposite. Although it’s not good idea, maybe he want to keep only one value, recently added. By looking at your solution , i guess It can be done similarly. We store Rating_rates list into temp and select one value from there later.

1 Like