0

I'm trying to perform some math on the properties of a Vertex. My solution works in the Gremlin console, but throws an error when run in JavaScript.

gremlin> g.addV("trip").property(single, "trackLength", 100).property(single, "travelDistance", 75).property(single, "carWeight", 10)

==>v[f8b42b9d-9053-2838-808d-ba14606b8390]

gremlin> g.V("f8b42b9d-9053-2838-808d-ba14606b8390").property(single, "carFactor", __.project("trackLength", "travelDistance", "carWeight").by("trackLength").by("travelDistance").by("carWeight").math("(trackLength - travelDistance) * carWeight")).valueMap()

I get the expected result when running in the console:

==>{trackLength=[100], travelDistance=[75], carWeight=[10], carFactor=[250.0]}

However when I run this in JS I get an error:

TypeError: __.project(...).by(...).by(...).by(...).math is not a function

Gremlin version 3.2.10. I've tried upgrading to ^3.4.0 but am encountering a separate issue addressed here.

Fook
  • 5,320
  • 7
  • 35
  • 57

1 Answers1

1

The math() step was only introduced on 3.3.1, so if you're using 3.2.10, that's not going to work. Perhaps try 3.3.5 and see if math() works there.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • 2
    May also be worth noting that for simple arithmetic such as add, multiply, subtract, that a fold() step can be used as in `g.V(1).sack(assign).by('some-property').sack(mult).by(constant(2)).sack()` – Kelvin Lawrence Jan 16 '19 at 19:39