Search code examples
gremlintinkerpop3amazon-neptune

Sack Sum By operation causes AWS Neptune error


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?


Solution

  • 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.