TypeQL works perfectly, when my schema is consistently filled with data, but there is an issue when some data and roles are optional (i.e. some values are null). In this case, with optional data, then queries will not work properly as one must know which values are null in order to properly query them.
This is particularly a problem with intricate schemas, such as Stix2.1, where there are many optional properties and optional roles. The question is, how to best manage a domain like Stix2.1 that contains optional data and optional roles.
As an example of this behaviour, consider the schema below with 3 optional values, 2 attributes and 1 role:
define name sub attribute, value string; # required value optional1 sub attribute, value string; # optional value 1 optional2 sub attribute, value string; # optional value 2 address sub attribute, value string, plays person:lives; # required data optional3 sub attribute, value double, plays person:number; # optional value 3 person sub relation, owns name, owns optional1, owns optional2, relates lives, relates number;
Then lets assume we have four data records to load into this schema:
- one record with values for everything,
- one record where 1 optional value is null
- one record where 2 optional values are null, and
- one record where 2 optional values are null, and one optional role is null
This data may look like the table below
If I then load and query for this data, then i need to know whcih values are null in order to retrieve them. If I use a query like
match $x isa thing;
Then I will retrieve all of the values. But if i use a query naming each of the values, like
match $peeps (lives: $live, number: $num) isa person, has name $name, has optional1 $opt1, has optional2 $opt2;
Then i will only get one record back.
Question, in a much more complex and intricate scenario (e.g. Stix 2.1), how can i query for all of the data without knowing in advance which attributes and which roles are null?
Note that a full example including schema, data and upload code is attached below
optional.zip (8.1 KB)
- Download and unzip
- CD into directory and type
Note that it assumes you are using localserver, if you are not, then just edit the url in clean_load.py