0

I have this Database:

Clients => Incident => File => Filename

  • Clients have an ID
  • Incidents have an ID and a reportedOn property
  • Files have an ID and a fileSize, mimeType, malware property
  • Filenames have an ID

Client have a outgoing Edge to Incidents (reported), incident have a outgoing Edge to file (containsFile), file have a outgoing Edge to filename (hasName).

What Query I have to execute in gremlin to get the filename-ID, the file-ID, the file-fileSize and the incident-reportedOn values in one result?

Here is some sample DATA:

g.addV('client').property('id','1')
  addV('incident').property('id','11').property('reportedON'2/15/2019 8:01:19 AM')
  addV('file').property('id','100').property('fileSize', '432534')
  addV('fileName').property('id','file.pdf')
  addE('reported').from('1').to('11').
  addE('containsFile').from('11').to('100').
  addE('hasName').from('100').to('file.pdf').iterate()
  • Could you please provide a Gremlin script that creates some sample data - here is an example https://stackoverflow.com/questions/51388315/gremlin-choose-one-item-at-random then it's much easier to provide you with a fully tested traversal that gives you the exact result that you are asking for. – stephen mallette Mar 22 '19 at 13:35
  • g.addV('client').property('id','1') addV('incident').property('id','11').property('reportedON'2/15/2019 8:01:19 AM') addV('file').property('id','100').property('fileSize', '432534') addV('fileName').property('id','file.pdf') addE('reported').from('1').to('11'). addE('containsFile').from('11').to('100'). addE('hasName').from('100').to('file.pdf').iterate() – Christopher H. Mar 22 '19 at 14:31

1 Answers1

0

The traversal you've posted to create the sample data contains dozens of errors. Don't be a pain in the ass, double-check what you post.

Anyway, here's a fixed version of your query:

g.addV('client').property('id','1').as('1').
  addV('incident').property('id','11').property('reportedON', '2/15/2019 8:01:19 AM').as('11').
  addV('file').property('id','100').property('fileSize', '432534').as('100').
  addV('fileName').property('id','file.pdf').as('file.pdf').
  addE('reported').from('1').to('11').
  addE('containsFile').from('11').to('100').
  addE('hasName').from('100').to('file.pdf').iterate()

get the filename-ID, the file-ID, the file-fileSize and the incident-reportedOn values

gremlin> g.V().has('client','id','1').
......1>   out('reported').as('incident').
......2>   out('containsFile').
......3>   out('hasName').
......4>   path().
......5>     from('incident').
......6>     by(union(group().
......7>                by(label).
......8>                by('id'),
......9>              valueMap()).
.....10>     unfold().
.....11>   filter(select(keys).is(neq('id'))).
.....12>   group().
.....13>     by(keys).
.....14>     by(select(values).unfold())).
.....15>   unfold().unfold().
.....16>   group().
.....17>     by(keys).
.....18>     by(select(values).unfold())
==>[fileName:file.pdf,file:100,reportedON:2/15/2019 8:01:19 AM,fileSize:432534,incident:11]

Only getting the path().from('incident').by(valueMap()) alone would already give you everything you need. However, I added a bit of re-grouping to get a nicer formatted result.

Daniel Kuppitz
  • 10,846
  • 1
  • 25
  • 34