tell me writing query this pattern
vartex(orange): question: {code:string, type: string }
vartex(purple):LeaningElement
What I want to do is
Get the Vartex:Question with code 0001 and search for LearningElements associated with it.
I want to search for Questions related to LearningElement in the search results other than code 0001 and with the same type as the question with code 0001.
The query I wrote is below.
I don't know how to filter the last in('has').
14 Replies
It's just a little while...
can someone tell me...
when you ask questions about Gremlin, pictures are nice, but it's always best to supply a small script to produce some sample data like:
If i understand your question properly, I think you just needed an additional
where()
:
(psst:there's an export as query feature on the graph view in gdotv that should help with that)
thank you!
I was able to do what I want to do!
We will also learn about the by step. Thanks for the nice tip!
I'll attach the script next time!
thank you!
I always use it conveniently!
Thank you during this period.
let me ask you one more question.
Can the where in this query be a little simpler?
■query
attach the data
i guess it depends on what you mean by "simpler". you could start to combine
P
values if you think that makes it more readable:
i did have trouble combining all three predicates. i expected this to work:
but it returned no results for some reason. that is maybe "simpler", but the more complex the predicate i think the harder it gets to read. if i could get it work, i think the best readable version might be some combination of the two like this:
That one seems about as clear and uncluttered as you could get as it drops the empty by()
and seeing where('b', neq('a')).
is such a common pattern in Gremlin it immediately pops out as to what's being done there. Anyway, created: https://issues.apache.org/jira/browse/TINKERPOP-2923
@Kelvin Lawrence i think this is an example where using and()
and or()
of P
is pretty useful (when it's working right). I don't get if I'm missing something? we actually have tests that validate this functionality so I'm not sure what's going on.Thanks for answering.
I was able to retrieve the desired data with the first query you wrote.
But one question remains. It is that the behavior of by step cannot be understood intuitively.
Is my by step understanding below correct?
so,
by()
typically applies to a step in a round-robin fashion. so if you have two items it is apply to it will use a single by()
for both:
In your case you have 5 items where by()
is applicable and the 4 by()
you supplied apply in the order they are encountered for the first three items and a single by()
round-robin for the last two items. That said, if you're referring to this traversal:
I'm not sure I understand the mapping you define. I would say:
* first by('pattern')
applies to "b"
* second by('pattern')
applies to eq('a')
* the by()
without an argument applies to the neq('a')
where it's comparing a Vertex
object (not its T.id
, but that's essentially the same thing from an equality perspective)
* the by('difficultyInPattern')
applies round-robin to both "b" and gt('a')
items.thanks so much.
I understood very well!
By what you mean by item is the number of elements in the step that applies by, right?
It would be even better if the following query you showed me before works, because the comparison conditions can be arranged simply.
yes...it would be nice if the
by()
could all apply to a single predicate and i'm not sure why that doesn't work. possibly a bug.I'm a little confused by the by step way of thinking that I was taught before.
I would like to make the following comparisons:
Step X also seems to require a by without an argument, but I have no choice but to understand this as a specification. I can't understand it intuitively.
(sorry for my poor english...)
i'm sorry - i think i made a mistake. i think that mistake is why i thought there was a bug. i think your original revision with a few minor changes was the best way to write this:
sorry for the confusion. i think you understand the
by()
pattern just fine. <:gremlin_smile:1091719089807958067>thanks so much. Great tip by me as a Gremlin newbie.
If I can learn a little more deeply, I would like to contribute to the project by adding documentation for beginners.