Specifying total relation match

This is an interesting question! As relations currently go, I think we do something like:
match
$r (role-1: $x, role-2: $y) isa relation;
not { $r ($z); };
match
$r (role-1: $x, role-2: $y) isa relation;
not { $r ($z); };
to specify that we do not want $r to have additional roleplayers. I'm not sure if this is the best way to do things (i.e. relation tuples are treated as partial by default), but it makes sense to me that relations and structs should have the same semantics for partial and total matches.
8 Replies
James Whiteside
James WhitesideOP16mo ago
@Joshua @christoph.dorn Actually, the above query doesn't work because $z can resolve to $x or $y so we need to do something like:
match
$r ($x, $y) isa relation;
not {
$r ($z);
not { $x is $z; };
not { $y is $z; };
};
match
$r ($x, $y) isa relation;
not {
$r ($z);
not { $x is $z; };
not { $y is $z; };
};
But this doesn't work because the inner negations cannot access the outermost variables. I get:
[QRY04] Invalid Query Pattern: Invalid query containing unbounded concept variable '$x'.
[QRY04] Invalid Query Pattern: Invalid query containing unbounded concept variable '$x'.
Joshua
Joshua16mo ago
That's an existing but bug* not sure we'll try to resolve it in 2.x
James Whiteside
James WhitesideOP16mo ago
Yes I feel we discussed it before Do we still think that, pending a fix, it is the best way to handle partial vs total relation matching?
Joshua
Joshua16mo ago
errr probably! yea i think so
James Whiteside
James WhitesideOP16mo ago
Should we then treat structs in the same way?
Joshua
Joshua16mo ago
Im not sure - we wanted to have them 'unambiguous' to start with, so if the user writes:
match
$attr == { a: $a, b: $b, c: $c };
$x has $attr;
match
$attr == { a: $a, b: $b, c: $c };
$x has $attr;
Where we can use the fields to determine the unique struct-value type (we won't allow ambiguity - you cant define two different structs with the same field names) maybe something to revisit
christoph.dorn
christoph.dorn16mo ago
here's a faster way to write this query btw (minus small differences if the same roleplayer appears multiple times) :
match
$r ($x, $y) isa relation;
not { $r ($x, $y, $z); };
match
$r ($x, $y) isa relation;
not { $r ($x, $y, $z); };
note 3.0 syntax would require you to write:
match
$r isa relation, links ($x, $y);
not { $r links ($x, $y, $z); };
match
$r isa relation, links ($x, $y);
not { $r links ($x, $y, $z); };
(which actually reads nicer imo)
James Whiteside
James WhitesideOP16mo ago
Ah good catch!

Did you find this page helpful?