0

Problem up-front: AWS Neptune seems to break when using a .sack(__.sum).by() operation.

Background:

Conditions

  • Data store: AWS Neptune
  • Querying from / runtime: AWS Lambda running Node.js

Given the above, this query will execute:

return await g.withSack(120)
 .V(fromPortId)
 .repeat(
     (__.outE().hasLabel('VOYAGES_TO'))
     .inV()
     .simplePath()
 )
 .until(
     __.has('code', toPortId).and()
     .sack().is(lte(travelTimeBudget))
 )
 .order().by(__.sack(), __.desc)
 .local(
     __.union(__.path().by('code')
     .by('duration'), __.sack()).fold()
 )
 .local(
     __.unfold().unfold().fold()
 )
 .toList()
 .then(data => {
     return data
 })
 .catch(error => {
     console.log('ERROR', error);
 });

... but this query will not:

return await g.withSack(120)
 .V(fromPortId)
 .repeat(
     (__.outE().hasLabel('VOYAGES_TO').sack(__.sum).by('duration'))
     .sack(__.sum).by(__.constant(45))
     .inV()
     .simplePath()
 )
 .until(
     __.has('code', toPortId).and()
     .sack().is(lte(travelTimeBudget))
 )
 .order().by(__.sack(), __.desc)
 .local(
     __.union(__.path().by('code')
     .by('duration'), __.sack()).fold()
 )
 .local(
     __.unfold().unfold().fold()
 )
 .toList()
 .then(data => {
     return data
 })
 .catch(error => {
     console.log('ERROR', error);
 });

... and the only difference between the two is the presence of the .sack(__.sum).by() operators.

Any thoughts or suggestions?

Dan
  • 4,197
  • 6
  • 34
  • 52
  • Are you getting an error or just not the expected result? Also what values should be used for `fromPortId` and `travelTimeBudget` in order to reproduce the results? – Kelvin Lawrence May 15 '22 at 21:38
  • Also, your should not use `__.sum` inside `sack` as that is the actual `sum()` step and not the operator `sum`. You should ideally include those at the top of your code. Alternatively us `Operator.sum`. I'll add this as an answer below with an example. – Kelvin Lawrence May 15 '22 at 21:40
  • You were correct -- `operator.sum` was needed. For anyone using the Javascript gremlin SDK, use `const { operator } = gremlin.process;` to bring it in – Dan May 15 '22 at 22:01

1 Answers1

1

You should not use __.sum inside a sack step, as that is the actual sum() step (from the anonymous traversal __.) and not the Operator.sum enum. You should ideally include those at the top of your code, alternatively use:

     (__.outE().hasLabel('VOYAGES_TO').sack(operator.sum).by('duration'))
     .sack(operator.sum).by(__.constant(45))

The additional parentheses around this block of code should also not be needed.

Dan
  • 4,197
  • 6
  • 34
  • 52
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • Continued thanks, @Kelvin -- I did find that the wrapping parentheses are needed, otherwise I get an error about the repeat() not being complete. Also (minor), in the Javascript gremlin SDK, it's a lowercase `operator` – Dan May 15 '22 at 21:59