Closed juhasev closed 6 years ago
Yes its not a bug as they are different.
addVertex() operations are done on the graph object such as
graph = TinkerGraph.open();
graph.addVertex(T.label, "person", T.id, 1, "name", "marko", "age", 29);
Whereas addV() operations are done on the traversal object such as
g=graph.traversal()
g.addVertex('user').property('name', 'Juha Vehnia').property('joined', '2018-04-10 10:10:00')
Ok makes sense. So why would addV() magically turn into addVertex() though?
$command = $traversalBuilder
->g()
->addV("'user'")
->property("'name'", "'Juha Vehnia'")
->next()
->getTraversal();
echo $command;
And you get
g.addVertex('user').property('name', 'Juha Vehnia').property('joined', '2018-04-10 10:10:00').next()
You know, I totally forgot I did that, while the meanings of addV() and addVertex() are different, the implementation is definitely off, my apologies for closing. I'll reopen :) I believe, at the time, I must have been tired of confusing the two so aliased it since almost always one will be using the traversal, let me look into it and remember the exact reasons I did it. Again a great spot @juhasev
I have locate the error,
should be
$addV = new AddVStep($args);
just as it is with
and
.
A fix is on the way. Thanks for spotting it.
Awesome! Currently there is no way to add new vertices using traversal which is what you probably do all the time.
Actually there is, I almost always mutate the graph using the GraphSerializer Because it handles all the goodies for you, DateTime to Java's timestamp (i.e SdateTime->getTimestamp() * 1000), it handles complex GeoShape and more. For your specific example, try
$graph_serializer = new GraphSerializer();
$user_array = array(
'name' => 'Juha Vehnia'
);
// if user fetched from DB or in object form
// $user_array = $graph_serializer->toArray($user);
$vertex_label = 'user';
$gremlin_command = $graph_serializer->toVertex(
array(
$vertex_label => $user_array
)
);
The irony is that GraphSerializer uses addV() internally hence why I never spotted this. https://github.com/The-Don-Himself/gremlin-ogm/blob/0db8c65a80fb3d1768121dbb7935a6af25a0c641/src/Serializer/GraphSerializer.php#L495-L514
Nice. I will check it out. You already merged the fix so closing this issue for now. Thanks for quick response!
This might not be a bug but rather some kind of configuration issue. When I execute the following traversal:
You actually get command:
Which throws an error in JanusGraph
However when I change g.addVertex() to g.addV() everything works as expected. Aren't these two equivalent or aliased steps which means both should work just fine?