How can we extract values only

"Latitude", { "@type": "g:Double", "@value": 45.2613104 }, "Longitude", { "@type": "g:Double", "@value": 9.491678060021837 }, In the germlin with AWS neptune am getting like this. but i need to get only values how can we extract only values through query.
Solution:
If I understand this correctly, you are first trying to take the result of a gremlin query that returns Latitude and Longitude (like in the initial post you made), and use those values in the in the math() step that calculates the Haversine formula (your latest post). If that is the case, you have two options. 1. You should combine this into one Gremlin query. You can save the results of the Latitude and Longitude to variables or use them in a by() modulator to the math step. Assuming that those values are properties on a vertex called 'lat' and 'lon' it would look something like g.V().project('Latitude', 'Longitude').by('lat').by('lon').math(...). You would replace the ... in the math() step with the Haversine formula. 2. If you want to keep these as two separate queries, then you should use one of the Gremlin Languages Variants (GLVs) which are essentially drivers that will automatically deserialize the result into the appropriate type so you don't have to deal with the GraphSON (which is what your initial post shows). Read triggan's answer above for more details about that....
Jump to solution
6 Replies
Kennh
Kennh3mo ago
Could you clarify what you mean by "only values". What is the query you are running now? Or are you saying that you don't want the "@type" information and you only want the "@value", in which case you are going to want to use the untyped serializer like "GraphSONUntypedMessageSerializerV1". The HTTP accept header for such a request would be "application/vnd.gremlin-v1.0+json;types=false"
Balan
BalanOP3mo ago
@Kennh Am trying to calculate distance between two latitudes and longitudes by using haversine formula inside the germlin query. One lat and long will get from User and another lat and long need to retrieve from the above . when i try to retrieve it gives like the above @type and @value . But i need only values for latitude and longitude.
triggan
triggan3mo ago
What client are you using? Are you using one of the Gremlin Language Variants (i.e. gremlin-python, Gremlin-Javascript, etc.)? If so, which one? Or are you using the AWS SDK and the NeptuneData execute_gremlin_query API? Each of these have their own method to specify the serialization format. You can choose a serialization format for GraphSON that does not return data types: https://tinkerpop.apache.org/docs/current/reference/#_graphson, as @Kennh mentioned. For example, the gremlin-python client you would use something like:
g = traversal().with_remote(DriverRemoteConnection('ws://localhost:8182/gremlin','g',
message_serializer = gremlin_python.driver.serializer.GraphSONUntypedMessageSerializerV1))
g = traversal().with_remote(DriverRemoteConnection('ws://localhost:8182/gremlin','g',
message_serializer = gremlin_python.driver.serializer.GraphSONUntypedMessageSerializerV1))
With the NeptuneData API call in boto3:
response = client.execute_gremlin_query(
gremlinQuery='g.V().valueMap()',
serializer='GraphSONUntypedMessageSerializerV1'
)
response = client.execute_gremlin_query(
gremlinQuery='g.V().valueMap()',
serializer='GraphSONUntypedMessageSerializerV1'
)
ColeGreer
ColeGreer3mo ago
@Balan Are you trying to calculate the distance between 2 points in gremlin or are you trying to fetch the lat/lon from some point in your graph, and then compute the distance between points in some external language of your choice (python, java, js...)? If you are trying to do the distance calculation in gremlin, could you share an example of your current query? If you are trying to fetch a point and get the results back in some json without the "@type"/"@value" metadata then I believe @Kennh and @triggan's suggestions around using untypped graphson is what you are looking for.
Balan
BalanOP3mo ago
@ColeGreer trying to calculate distance in germlin query itself by using the haversine formula. by( math('(sin((Latitude * rdeg - userLat * rdeg)/2))^2 + cos(Latitude * rdeg) * cos(userLat * rdeg) * (sin((Longitude * rdeg - userLon * rdeg)/2))^2'). math('gcmiles * (2 * asin(sqrt(_)))')
Solution
Kennh
Kennh3mo ago
If I understand this correctly, you are first trying to take the result of a gremlin query that returns Latitude and Longitude (like in the initial post you made), and use those values in the in the math() step that calculates the Haversine formula (your latest post). If that is the case, you have two options. 1. You should combine this into one Gremlin query. You can save the results of the Latitude and Longitude to variables or use them in a by() modulator to the math step. Assuming that those values are properties on a vertex called 'lat' and 'lon' it would look something like g.V().project('Latitude', 'Longitude').by('lat').by('lon').math(...). You would replace the ... in the math() step with the Haversine formula. 2. If you want to keep these as two separate queries, then you should use one of the Gremlin Languages Variants (GLVs) which are essentially drivers that will automatically deserialize the result into the appropriate type so you don't have to deal with the GraphSON (which is what your initial post shows). Read triggan's answer above for more details about that.
Want results from more Discord servers?
Add your server