What does "key" actually do?


#1

Still trying to figure out the correct way to use the key keyword. Same question I posed in CSV migration issues but I’ve gotten it down to the absolute bare minimum reproducible example. Hopefully I can get an answer to this as it is one of the last things I need to figure out to release a website powered by Grakn.

The only documentation I can find on the key keyword is this: https://dev.grakn.ai/docs/api-references/ddl#key-type. Doesn’t explain how to use it or show an example of its use.

I’ve created a project: https://github.com/BFergerson/grakn-key-test

In this project the schema is:

define
node sub entity key name;

name sub attribute datatype string;

From my understanding of key this should prevent me from inserting two node entities with the same name. This is not the case as I show in: https://github.com/BFergerson/grakn-key-test/blob/master/src/main/java/GraknKeyTest.java

The script above shows me inserting the following twice:

insert $x isa node has name “brandon”;

With the output of running the script above being:

Ontology setup
Insert first “brandon”: [[$x/V12528]]
Insert duplicate “brandon”: [[$x/V8328]]
“brandon” node count: 2

At this point I’m not sure how I can make my example any more concise. I don’t understand how I’m using the key keyword incorrectly. Can I please get an example of how to use it and how it works? Would also help if the keyword was more documented.


#2

Hi @BFergerson, I’m very sorry for this!

Thank you so much for helping us reproduce the issue in a very concise way. Could not get any clearer.

You’re not using key incorrectly but it seems we have caused a bug in it at some point. I’ll start working on this next week!

Would that be okay?


#3

Sounds perfect. In the mean time I’ve been working on https://github.com/BFergerson/JetBrains-Graql-Plugin. Thanks @haikal!