I would like to print the query being run for debugging.
I can't figure out the best way to do so without repeating the query twice, once as string to be printed, once to actually execute it.
i tried:
add_vertex_query = "g.addV('addvqueryLabel').next()"
print("going to run query: %s"%(add_vertex_query))
add_vertex_query_res = add_vertex_query
print("add_vertex_query result: %s"%(add_vertex_query_res))
but this doesn't work because it is just reassigning the query string and not actually running it, in the 3rd line
btw I am running my graph in Neptune so it'd be nice if the solution is Neptune-compatible
UPDATE
I have found an alternative (though not ideal):
query = g.V().valueMap(True)
print("query: %s"%(query))
result_list = query.toList()
print("result: %s"%(result_list))
this gives
query: [['V'], ['valueMap', True]]
in the printout, which can be understood to be
"g.V().valueMap(True)
"
but ideally best case would be if I can log/print the exact entire query I intended:
g.V().valueMap(True).toList()
without having to duplicate the string in the code like
query_string = "g.V().valueMap(True).toList()"
print("running query: %s"%(query_string))
res = g.V().valueMap(True).toList()
print("results: %s"%(res))
Solved using Python eval
query_string = "g.V().valueMap(True).limit(5).toList()"
print("running query: %s ..."%(query_string))
res_list = eval(query_string)
[print("result %s: %s"%(i, res)) for i, res in enumerate(res_list, 1)]