Abstract: In the semantic Web isograph model, following the open world assumption, facts that are not included in the data are considered unknown rather than false.

This article is shared by huawei cloud community “Graph Database support for NULL attribute Values”. The original article is written by Hello _TT.

NULL is an indication in the database that a data attribute is unknown or missing and is used to indicate that a data value does not exist in the database. When an attribute value of a node or edge of graph data in a graph database is missing or undefined, the attribute value is NULL.

So why do graph databases need to support NULL values?

In the semantic Web isograph model, following the open world assumption, facts that are not included in the data are considered unknown rather than false. For example, for a graph database containing several students, there are two queries:

Query 1: find the person whose university is in Tsinghua University

Query 2: find out who is not in Tsinghua University

If xiaoming in the graph database does not fill in the school, then xiaoming belongs to the result set of query 1 or query 2. Ming is neither the answer to query one nor the answer to query two, underpinned by the logic of the open-world hypothesis that the data not contained is unknown rather than spurious.

Graph database, with NULL values to implement this logic.

Let’s take a look at the support for NULL attribute values in each graph database.

GDB

For the data type string, an empty string with a length of zero is supported, which is denoted as: “. Blank fields without double quotation marks do not exist, which is nullptr.

NebulaGraph

By default, the value of an attribute can be NULL when a point or edge is inserted. The user can also set the value of an attribute to NOT NULL (NOT NULL). That is, the value of the attribute must be set when a point or edge is inserted unless the default value has been set when the attribute is created.

HugeGraph

You can specify strings that represent NULL values, such as “NULL”, and if the column corresponds to a vertex/edge attribute that is also nullable, the value of that attribute is not set during vertex/edge construction.

Amazon Neptune

Blank fields are allowed, and a blank field is considered a NULL value.

Neo4j

In Cypher, NULL is used to indicate missing or undefined values. Conceptually, NULL means missing unknown values, which are treated slightly differently than other values.

Gremlin

TinkerGraph can be configured to support NULL as an attribute value, but not all graph database products do. So please be sure to check before use supportsNullPropertyValues () function or view the documentation.

TigerGraph

NULL and NOT NULL attributes are NOT supported. The value NULL is not supported in the graph database. If an attribute is not assigned when a vertex or edge instance is created, it is assigned to the default value of that data type, which has been deprecated in the latest version.

Huawei Cloud Image Engine Service GES

NULL attribute values are supported. When a blank field is entered, the value of this attribute is considered NULL.

For example, assume that the schema of the imported data is:

<label name="movie"> <properties> <property name="ChineseName" cardinality="single" dataType="string"/> <property name="Year" cardinality="single" dataType="int"/> </properties> </label> <label name="user"> <properties> <property name="Gender" cardinality="single" dataType="enum" typeNameCount="2" typeName1="F" typeName2="M"/> <property name="School" cardinality="single" dataType="string"/> <property name="Age" cardinality="single" dataType="int"/> </properties> </label> <label name="rate"> <properties> <property name="Datetime" cardinality="single" dataType="date"/>  <property name="Score" cardinality="single" dataType="double" /> </properties> </label>Copy the code

The point data imported is:

Zhang SAN, User M, Tsinghua University, Li Si, User, Peking University,20 xiaoming,user,, 21 Titanic movie, 1997Copy the code

The imported edge data is:

Many years ago, zhang SAN, rate, and 4Copy the code

Call GES native API interface for edge query:

GET http:// {SERVER_URL} / ges/v1.0 / / graphs / {graph_name} {project_id} / edges/detail? Many years ago source = zhang SAN & target =Copy the code

Results obtained:

"Edges" : [{" index ":" 0 "and" source ":" zhang ", "label" : "rate", "properties" : {" Score ": [4.0]," Datetime ": [ null ] }, "target": "Titanic" } ]Copy the code

As you can see, the Datetime attribute value of the queried edge is null because the attribute field was entered as a blank field.

In addition, GES supports two mainstream graph query languages, Gremlin and Cypher.

Perform the following three queries respectively:

Match (n:user) where n.school =' tsinghua university 'return n match (n:user) where n.school <>' Tsinghua university' return n match (n:user) where n.school =' tsinghua University 'return n match (n:user) where n.school <>' Tsinghua University' return n match (n:user) where n.School is null return nCopy the code

The query results are as follows:

"Row" : [{" School ", "tsinghua university", "Gender" : "M", "Age" : null}], "meta" : [{" id ":" zhang ", "type" : "node", "labels" : "Row" (" user ")}] : [{" School ", "Peking University", "Gender" : null, "Age" : 20}], "meta" : [{" id ":" bill ", "type" : "node", "labels": [ "user" ] } ] "row": [ { "School": null, "Gender": null, "Age": 21 } ], "meta": [ { "id": "Type ": "node", "labels": ["user"]}]Copy the code

When n.chool is null, the return values of n.chool <>’ tsinghua University ‘and n.chool =’ Tsinghua University’ are both non-true, so Xiaoming is not in the result set of the first two queries. Behind this lies the three-valued arithmetic logic supported by GES Cypher, which underpins the queries described at the beginning of this article and follows the open-world assumptions of models such as the Semantic Web.

Click to follow, the first time to learn about Huawei cloud fresh technology ~