GeezerVison is showing github.com — Support validation with Gremlin "addVertex" through Postgres driver · Issue #690 · ArcadeData/arcadedb
Support validation with Gremlin "addVertex" through Postgres driver #690DescriptionArcadeDB Version: 22.12.1-SNAPSHOT
JDK Version: openjdk version "11.0.17" 2022-10-18
OS: Ubuntu 22.04.1 LTS
Expected behavior
I have created a vertex type with 2 properties with the following SQL commands:
chicken@asteroid:~$ psql --host=localhost testdatabase root
Password for user root:
psql (14.5 (Ubuntu 14.5-0ubuntu0.22.04.1), server 10.5)
Type "help" for help.
testdatabase=> CREATE VERTEX TYPE ChipID;
operation | typeName
--------------------+----------
create vertex type | ChipID
(1 row)
INSERT 0 1
testdatabase=> CREATE PROPERTY ChipID.name STRING (mandatory true, notnull true, readonly true);
operation | typeName | propertyName | mandatory | notnull | readonly
-----------------+----------+--------------+-----------+---------+----------
create property | ChipID | name | \x01 | \x01 | \x01
(1 row)
testdatabase=> CREATE PROPERTY ChipID.uid STRING (mandatory true, notnull true, readonly true);
operation | typeName | propertyName | mandatory | notnull | readonly
-----------------+----------+--------------+-----------+---------+----------
create property | ChipID | uid | \x01 | \x01 | \x01
(1 row)
Both name and uid are "readonly", which means they have to be present at creation time. It is expected that the following command fails:
testdatabase=> {gremlin} g.addV('ChipID').property('name', 'a').property('uid', 'b');
ERROR: Error on executing query: The property 'name' is mandatory, but not found on document: @ChipID[uid=b]
I'm looking for a way to create a ChipID vertex through the Postgres Driver in Gremlin.
A Gremlin graph has an "addVertex" method which looks like the right choice, but I have no idea how to access it.
Both graph and testdatabase (the name of my database) did not work:
testdatabase=> {gremlin} graph.addVertex('ChipID', 'name', 'a', 'uid', 'b');
ERROR: Syntax error on executing query: groovy.lang.MissingPropertyException: No such property: graph for class: Script23
testdatabase=> {gremlin} testdatabase.addVertex('ChipID', 'name', 'a', 'uid', 'b');
ERROR: Syntax error on executing query: groovy.lang.MissingPropertyException: No such property: testdatabase for class: Script24
Activitylvca commented on Dec 19, 2022 The issue with the Gremlin API is that properties are added after the first save() that caused the validation exception.
You can use the SQL CREATE VERTEX statement: https://docs.arcadedb.com/#SQL-Create-Vertex.
Example:
CREATE VERTEX ChipID SET name = 'a', uid = 'b'
lvca commented on Dec 19, 2022 Alternatively you could try Gremlin addV() by setting properties immediately (the trick is passing the vertex type as label):
g.addV('label', 'ChipID', 'name', 'a', 'uid', 'b');
I've not tested it, but it's available in the Java API, so if the Gremlin driver is able to map that call, it should work. docbacardi commented on Dec 20, 2022 ContributorAuthor More actions The SQL CREATE VERTEX command works, thank you.
testdatabase=> CREATE VERTEX ChipID SET name = 'a', uid = 'b';
name | uid
------+-----
a | b
(1 row)
INSERT 0 1
The Gremlin command does not work:
testdatabase=> {gremlin} g.addV('label', 'ChipID', 'name', 'a', 'uid', 'b');
ERROR: Syntax error on executing query: groovy.lang.MissingMethodException: No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource.addV() is applicable for argument types: (String, String, String, String, String, String) values: [label, ChipID, name, a, uid, b]
Possible solutions: addV(), any(), wait(), call(), tx(), grep()
It would be great to have a Gremlin solution for this. lvca commented on Dec 20, 2022 That's Gremlin standard and it's out of our scope. I'm going to try to ask in the Gremlin Discord channel if this is an option. If yes, I could quickly submit a PR for that. lvca commented on Dec 21, 2022 Gremlin team wrote back:
"When you have the pattern of addV().property().property()... TinkerPop attempts to fold those property() calls back into addV() or more specifically into the AddVertexStep or AddVertexStartStep so that Graph.addVertex(...) can be called with all the property keys at once with the label. That addV().property(Map) overload kelvin was mentioning should behave in the same fashion. The vertex/edge will not be created all at once if there were some intermediate step between the addV() and the property()"
Please let me know if the suggested way works for you, and I'll add it to the documentation. docbacardi commented on Dec 22, 2022 ContributorAuthor More actions I have to admit that I am not sure how to test this. Maybe you can give me a hint.
While plain SQL works, Gremlin in studio, console and through Postgres does not work.
The Gremlin team mentions tinkerpop, so I tried gremlin-cli, gdotv and gremlin-python. I failed to open a connection in gremlin-cli, most likely because I'm a complete beginner. gdotv and gremlin-python worked and I was able to access the database "graph". Unfortunately I did not manage to run SQL commands like "create property" on the "graph" database. Maybe this is issue #662 .
I'm still working on connecting to other databases with gdotv and gremlin-python. docbacardi commented on Dec 22, 2022 ContributorAuthor More actions I just managed to connect to my testdatabase with gdotv and gremlin-python. Same result for both.
Python:
>>> g.addV('ChipID').property('name', 'x').property('uid', 'y').iterate()
Received error message '{'requestId': 'f0138397-64d1-45f6-94e8-b8b8e6561c69', 'status': {'code': 500, 'message': "The property 'name' is mandatory, but not found on document: @ChipID[uid=y]", 'attributes': {'stackTrace': "com.arcadedb.exception.ValidationException: The property 'name' is mandatory, but not found on document: @ChipID[uid=y]\n\tat com.arcadedb.database.DocumentValidator.throwValidationExc...
gdotv:
g.addV('ChipID').property('name', 'x').property('uid', 'y').iterate()
javax.script.ScriptException: java.util.concurrent.CompletionException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: The property 'name' is mandatory, but not found on document: @ChipID[uid=y]
lvca commented on Dec 22, 2022 Ok, I was able to intercept the API and override the set of properties with a call to .save() only after all properties are set. The fix should be pushed in <1h. lvca commented on Dec 22, 2022 Ok, this is done. Thanks @docbacardi now constraints work with Gremlin too :-) Please let me know if you're able to run your queries now against latest snapshot taken from the main branch. We should release tomorrow 22.12.1... docbacardi commented on Dec 23, 2022 ContributorAuthor More actions Everything is working as expected, thank you very much for the fast help. Reacted by Luca Garulli Reacted by Luca Garulli changed the title [-]Run gremlin graph methods like "addVertex" through Postgres driver[/-] [+]Support validation with Gremlin "addVertex" through Postgres driver[/+] on Dec 23, 2022
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|