Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

gremlin - Returning multiple values from one step using 'select', 'by' in Gremline

My graph schema looks like this:

(Location)<-[:INVENTOR_LOCATED_IN]-(Inventor)-[:INVENTOR_OF]->(Patent)

I'm trying to return multiple values from each step in the query path. Here's the query I have so far that runs correctly:

g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location','state',textContains('IN'))).as('a').
  bothE().bothV().hasLabel('Inventor').as('b').
  bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
  select('a,', 'b', 'c').
  by('state').by('name_first').by('title').
  fold();

What I would like to do is for each step return two node properties. I tried the following but it returns an error:

g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location', 'state',textContains('IN'))).as('a').
  bothE().bothV().hasLabel('Inventor').as('b').
  bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
  select('a,', 'b', 'c').
  by('city', 'state').by('name_first', 'name_last').by('title', 'abstract').
  fold();

Can anyone suggest syntax that will allow me to return multiple properties from each node in the path?

question from:https://stackoverflow.com/questions/66068669/returning-multiple-values-from-one-step-using-select-by-in-gremline

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The by(key) is meant to be a sort of shorthand for values(key) which means if you have more than one value you could do:

g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location', 'state',textContains('IN'))).as('a').
  bothE().bothV().hasLabel('Inventor').as('b').
  bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
  select('a,', 'b', 'c').
    by(values('city', 'state').fold()).
    by(values('name_first', 'name_last').fold()).
    by(values('title', 'abstract').fold()).
  fold()

You might also consider forms of elementMap(), valueMap(), or project() as alternatives. Since by() takes a Traversal you have a lot of flexibility.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...