Correct usage of "val" keyword?


#1

Going through https://dev.grakn.ai/docs/migrating-data/migration-language in order to add further support for the Graql migration language to https://github.com/BFergerson/JetBrains-Graql-Plugin and I found some inconsistencies in the val keyword.

The first is the usage of the val keyword as an identifier in the Graql query:

insert $x
    for (val in @split(<list>, ",")) do {
        has description <val>
    };

but as a keyword here:

insert $x val @long(@split(<list>, ",")[0]);

I get that the val keyword isn’t listed as a keyword for the Graql migration language (https://dev.grakn.ai/docs/migrating-data/migration-language#reserved-keywords) but rather only for the primary Graql language (https://dev.grakn.ai/docs/querying-data/overview#querying-and-query-modifiers) however this does not stop the Graql migration language documentation from using it consistently as if it were a keyword:

match $x isa thing has val @lower(<value>);

Is val a keyword for the Graql migration language as well? If so, shouldn’t it not be possible to use it as an identifier like it’s being used in the for loop query above?

I tried to put this theory to test in the project: https://github.com/BFergerson/grakn-val-test

This only further confused my understanding of what the val keyword actually does (like the key keyword does not seem to be documented in and of itself) as it seems to be used as both an identifier and as a precursor keyword to a macro.

The val keyword is documented as such:

match $x isa thing has val @lower(<value>);

I would think the following would be a valid query:

match
$p isa project
    has name val @lower(<project>);
insert
$f isa file
    has name <filename>
    has qualified_name <qualifiedName>;
    (has_defines: $p, is_defines: $f) isa defines;

Running the –no option on the CSV migrator produces the following query:

match $p0 isa project has name val "bfergerson\/myproject";
insert $f0 isa file has name "kythe:\/\/github?lang=java?com\/gitdetective\/App.java" has qualified_name "kythe:\/\/github?lang=java#App.java";
(has_defines: $p0, is_defines: $f0) isa defines;
match $p0 isa project has name val "bfergerson\/myproject";
insert $f0 isa file has name "kythe:\/\/github?lang=java?com\/gitdetective\/MyClass.java" has qualified_name "kythe:\/\/github?lang=java#MyClass.java";
(has_defines: $p0, is_defines: $f0) isa defines;

While the match query:

match $p0 isa project has name val "bfergerson\/myproject";

is entirely valid and can be used as a get query in the Graql console like so:

match $p0 isa project has name val "bfergerson\/myproject"; offset 0; limit 30; get;

it doesn’t produce any results.

Simply removing the val keyword to produce the query:

match $p0 isa project has name "bfergerson\/myproject"; offset 0; limit 30; get;

does actually produce the correct results.

Modifying the original template query to remove the val keyword entirely like so:

match
$p isa project
    has name @lower(<project>);
insert
$f isa file
    has name <filename>
    has qualified_name <qualifiedName>;
    (has_defines: $p, is_defines: $f) isa defines;

also produces the correct results.

So what’s the correct usage of the val keyword? Again, all the documentation I could find on it is here: https://dev.grakn.ai/docs/migrating-data/migration-language and it seems to regard val as both a keyword and as an identifier. Currently the JetBrains Graql plugin restricts keywords from being used as identifiers. Is there something special with the val keyword?


#2

Which version are you using?

Up to 1.2.0, the pattern:

$p0 isa project has name val "bfergerson\/myproject";

gets parsed to:

$p0 isa project;
$p0 has name $some-generated-var;
$p0 val "bfergerson\/myproject";

while

$p0 isa project has name "bfergerson\/myproject";

parses to:

$p0 isa project;
$p0 has name "bfergerson\/myproject";

hence the result you didn’t expect.

The latest master removes the val keyword entirely as there were some ambiguities when using it as you can see. Hence, to specify a value for an attribute you do:

$att == <value>, where double equals is optional.

Other comparison operators follow analogously.

When specifying attributes you can either do:

$att has some-attribute <value>
or
$att has some-attribute == <value>


#3

@kasper, I’m using Grakn 1.2.0. Didn’t realize the val keyword was deprecated.

Sounds like the val keyword will be removed from the documentation soon, right?


#4

It wasn’t deprecated, it just led to a lot of confusion because of the situations as described above hence the new version simplifies the syntax. Once we release the new version it will be removed.