-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add support for datas UNWIND #5165
Comments
This is a kind of duplicated of #4615 However, I didn't understand how it is related to UNWIND Neo4J's. There seems to be something else entirely. Also, Internally I had proposed a "custom block". {
var() {
# This is a "custom var block" all values here doesn't show up in the query result.
ST as string("Alice") # We could use it in any query help to avoid repetition.
T1 as string($a) # This is getting a value from DQL variable.
Users as uidAt(Var1, var2) # converts UID to hex number to be used in a query, also to work with uid_in function.
Users2 as uidAt("0x1, 0x2") # Just holds UIDs to be used in a query.
DP as math(4) # hold a number or do a math, as we do in our examples in docs
T2 as math($b + 33) # This is getting a value from DQL variable and summing.
DP2 as int(1) #just hold a number
DP3 as float(1.01111) # just hold a float number
DT as dateTime(2006-01-02T15:04:05) # just hold dateTime
}
} The custom block could be used instead of directly inserting DQL Variable into the mutation block.
btw, I think the order in Dgraph syntax would be
It is important to note that Upsert Block does not yet support DQL Variables (Also known as Query Variables). We need to support this before doing anything else related. |
Hum I didn't even noticed that Regarding the
with this we have the variable If one wants to upsert an array of users based on their name, the upsert {
// not sure where you put the bloc (your forum link is broken)
// so let's say we put it there
var() {
user_data AS UNWIND [{name: 'Alice', age: 20}, {name: 'Bob', age: 25}]
}
query {
user as var(func: eq(name, user_data.name))
}
mutation {
set {
uid(user) <age> val(user_data.age) .
}
}
}
// the above would set both Alice and Bob with their respective ages without unwind you actually have to do the following upsert {
query($alice: string, $bob: string) {
alice as var(func: eq(name, $alice))
bob as var(func: eq(name, $bob))
}
mutation($alice_age: int, $bob_age: int) {
set {
uid(alice) <age> val($alice_age) .
uid(bob) <age> val($bob_age) .
}
}
}
// it works but in case you have 100 users your generated query is a bit insane |
The link is an internal discuss.
I don't think that would work. The parser result would look like this:
Because the mutation block is not able to iterate over objects. We need to implement another solution (like "foreach user_data create a mutation block") before that be possible. There is still the fact of "dot notation". This is not supported in |
hum i don't understand how it could result in
executing upsert {
query {
var(func: has(name)) {
name as name
}
// in the first sequence we find Alice's name
// in the second sequence we find Bob's name
}
mutation {
set {
// so here we have 2 parallel sequence
// one for Alice and one for Bob
uid(name) <surname> val(name) .
}
}
} would give
I used Objects in my exemple because it would be pretty handy but we can simplify by using simple valid types like
if the nodes already exist this unwind would give the exact same representation as
exept we couldn't call |
This is different, this is a bulk upsert. It is a set of multiple mutations aligned. That is, for each node found it will perform that mutation block as a "template". See, Dgraph iterates over its own Entities. But not in nested or even multiple values. And there is nothing that can dynamically generate multiple lines of RDF in the mutation block, or even create multiple mutation blocks based on the value/map (for example "user_data AS UNWIND"). This type of interaction does not exist in Dgraph. Take for example issue #4712 and #4779. In them I had to use an intermediate block so that I could pass a value from one node to the other. Without this block (me), the operation would not work. And if I do a Bulk upsert, the values will get messed up. This problem with aggregations also occurs in Queries of Facets (see #4160). Where to get accurate values I have to limit the query to 1 result at a time. This problem happens with aggregations and also nested blocks. The nested block is the key point to explain why it doesn't work. In issue #4779 - without the intermediate block, I can't get the values "title, released, tagline" (see the example in 4779 issue). And if I don't limit it to 1 to 1 operation, the values get messed up, get mixed up and it will mess up with the DB. That's why I find your UNWIND proposal complicated. We need to solve other design problems first. These uses cases were never foreseen and Upsert Block is only a few months old. As I said before, to start thinking about UNWIND. Some problems will need to be resolved: 1 - Support DQL Variables in Upsert Block. |
Github issues have been deprecated. |
What you wanted to do
Dynamically use external datas inside queries by unwinding arrays
with unwind:
This would map each value in the array
names
andages
to the current Dgraph map index so that the first founduser
receiveuser_name
fromnames[0]
and so on.It would be even better to support
$users: [user]
to be able to shorthand towithout unwind: (current behavior)
What you actually did
Thinking about manually unwinding my datas by interpolating as many query lines as needed and propagating variables with dynamic aliases like in the without unwind exemple
Why that wasn't great
That makes the query extra heavy and insanely verbose for big arrays of nodes
Any external references to support your case
UNWIND in Cypher
The text was updated successfully, but these errors were encountered: