Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/appendix/pages/keywords-and-reserved-words.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ The compiler will reject the use of a reserved word as well as any word beginnin
* NOT
* NOW
* NULL
* NULLABLE
* OFFSET
* ON
* OPENCYPHER
Expand Down
15 changes: 15 additions & 0 deletions modules/ddl-and-loading/pages/attribute-data-types.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ Existing schemas that are using `STRING COMPRESS` can continue to function norma
If you need reference for `STRING COMPRESS`, please refer to GSQL Language Reference version 3.5 or older.
====

[NOTE]
====
Primitive data types used as attributes of a vertex or edge, can be set to `NULL`.
====
Comment on lines +123 to +126
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this a new (brief) section on Null Values, not a Note.

  • If an attribute is defined as NULLABLE, then its value can be NULL, in addition to its characteristic values
  • explain what it means if an attribute is null
  • explain how to format null in as an input

Additionally, GSQL also supports the following complex data types:

== Collection types
Expand All @@ -143,6 +147,17 @@ Due to multithreaded GSQL loading, the initial order of elements loaded into a l
** Supported value types: `INT`, `DOUBLE`, `STRING`, `DATETIME`, and `UDT`.
** To declare a map type, use `<>` to enclose the types, with a comma to separate the key and value types, e.g., `MAP<INT, DOUBLE>`.

[NOTE]
====
* `LIST`, `SET`, `MAP` can be assigned `NULL` as an attribute.
* For `LIST` or `SET`:
** `NULL` is different from [NULL, NULL] or {NULL}.
** Elements inside `LIST` or `SET` cannot be `NULL`.
* For `MAP`:
** Keys and Values cannot be `NULL`.

====

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all of this belongs in a special note:

  • LIST, SET, MAP can be assigned NULL as an attribute

This is just following the standard rule that any attribute that is NULLABLE can have null. No special treatment.

** Elements inside LIST or SET cannot be NULL.

This does deserve being in a NOTE because this is where TigerGraph's support is not as complete as it is in some other products.

  • For MAP:
    ** Keys and Values cannot be NULL

I would just lump this together with LIST and SET.

** NULL is different from [NULL, NULL] or {NULL}.

From a technical standpoint, this is not saying anything that isn't already said in the preceding rules. It's usefulness is as an example, not an additional rule.

MyList = NULL // This is setting the entire list to null. Supported.
MyList = [NULL] // This is creating a list with one element whose value is null. Not supported.

== User-defined tuples

A *User-Defined Tuple (UDT)* represents an ordered structure of several fields of the same or different types.
Expand Down
66 changes: 66 additions & 0 deletions modules/ddl-and-loading/pages/creating-a-loading-job.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,72 @@ RUN LOADING JOB job1 USING file1="m1:/data/v1_1.csv", file2="m2:/data/e2.csv" <2
<1> File path specified at compile time.
<2> Run-time specification will override path specified at compile time.

=== Loading NULL Values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have sections that talk about how to load each type of data. It is called "Attributes and attribute expressions", with a subsection for each data type.
I would move this section there, and follow the format used there.

`NULL` values can be loaded to vertex/edge attributes using a loading job either by parsing from source file or during creation of loading job.

==== Loading NULL from source file
If an attribute is defined as *nullable* in the schema, any of the following in a CSV or JSON file are treated as `NULL`:

* The value `NULL` or `null`
* A missing value (empty field)

.Example: CSV file containing NULL values
[source,csv]
----
id,att
1,null // valid null and will be parsed to storage
2,NULL // valid null and will be parsed to storage
3, // missing value and will be parsed as null to storage
4,Null // invalid attribute
----

.Example: JSON file containing NULL values
[source,json]
----
{"id":1,"att":null} // valid null and will be parsed to storage
{"id":2,"att":NULL} // valid null and will be parsed to storage
{"id":3,"att":Null} // invalid like Null except for string
{"id":4,"att":} // invalid JSON
----

Sample Output
[source,json]
----
"results": [
{ "1,null": null },
{ "2,NULL": null },
{ "3,": null },
{ "4,Null": "Null" }
]
----

==== Loading NULL during creation of loading job
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would modify and reduce the scope of this section.
There are basically 3 ways to end up with NULL in the loaded data:

  1. Because NULL (including empty fields) was in the input data.

That is already covered in the section above.

  1. Because the loading job has an explicit value (NULL) instead of making a reference (e.g. $1) to a source file.

This can happen with any data type (explicit INT, explicit BOOLEAN, ...), so there does not seem to be a reason to make an exception for NULL.

  1. Because the loading job uses an underscore "_" to skip an attribute.

This is discussed but not that clearly, and NULL changes the odd behavior, so we should write about this.

We might want a section called "Omitted Fields and Default Values".
Here we would:

  • Talk about omitted fields in CSV, JSON, and loading job "destination clauses": if they are legal and how they are interpreted. If legal, then the default value is used.
  • Explain the rules for default values.
    ** Depends if the particular vertex or edge type defined a custom default value for that attribute
    ** Depends on whether the attribute is NULLABLE or not


`NULL` can be stored in the following situations:

* When the attribute is nullable and the vertex or edge does not exist:
** The default value for that attribute in the schema is `NULL`, or
** No default value is defined in the schema.
* If the attribute is nullable, NULL will be stored for this attribute for all vertices/edges loaded in this job.
* If the attribute is not nullable, the GSQL shell shows a *semantic error*.

For example:
[source,gsql]
----
CREATE LOADING JOB load_nullable FOR GRAPH g {
DEFINE FILENAME f;

// Implicit NULL using underscore
LOAD f TO VERTEX v0 VALUES($0, _);
LOAD f TO EDGE e0 VALUES ($0, $1, _);

// Explicit NULL using NULL keyword
LOAD f TO VERTEX v1 VALUES ($0, NULL);
LOAD f TO EDGE e1 VALUES ($0, $1, NULL);
}
----


== `DROP JOB` statement

To drop (remove) a job, run `DROP JOB job_name`. The job will be removed from GSQL.
Expand Down
36 changes: 34 additions & 2 deletions modules/ddl-and-loading/pages/modifying-a-graph-schema.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ ADD VERTEX::
--
----
ADD VERTEX Vertex_Type_Name ( PRIMARY_ID id_name id_type
[, attribute_name type [DEFAULT default_value] ]* )
[, attribute_name type [NULLABLE][DEFAULT default_value] ]* )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax detail is correct, but there is another section on the page that needs to same treatment.
Besides the ADD VERTEX/EDGE section, there is an analogous
ADD VERTEX/EDGE (global) section.
https://docs.tigergraph.com/gsql-ref/4.2/ddl-and-loading/modifying-a-graph-schema#_add_vertex_edge_global

[WITH [STATS="none"|"outdegree_by_edgetype"][primary_id_as_attribute="true"]]
----
--
Expand All @@ -179,7 +179,7 @@ ADD UNDIRECTED EDGE Edge_Type_Name (
FROM Vertex_Type_Name "," TO Vertex_Type_Name
[ "|" FROM Vertex_Type_Name "," TO Vertex_Type_Name]*
[ "," DISCRIMINATOR "(" attribute_name type ["," attribute_name type]* ")" ]
[ "," attribute_name type [DEFAULT default_value]]*
[ "," attribute_name type [NULLABLE][DEFAULT default_value]]*
)
----
--
Expand All @@ -192,7 +192,39 @@ For example, the following statement in a schema change job adds a directed edge
ADD DIRECTED EDGE Study_At (From Person, To University,
DISCRIMINATOR(class_year INT, class_month INT));
----
Starting in 4.3, vertex/edge attributes can be defined as `NULLABLE` to accept `NULL` values.

For example:
[tabs]
====
ADD VERTEX::
+
--
----
ADD VERTEX Student (
PRIMARY_ID id INT,
name STRING NULLABLE,
age INT NULLABLE
);
----
--
ADD EDGE::
+
--
----
ADD DIRECTED EDGE Enrolled_In (
FROM Student,
TO Course,
grade STRING NULLABLE
);
----
--
====

[NOTE]
====
Attributes used for `PRIMARY_KEY` or `COMPOSITE_KEY` or `DISCRIMINATOR` cannot be declared `NULLABLE`.
====

== `ALTER VERTEX | EDGE`

Expand Down
17 changes: 17 additions & 0 deletions modules/querying/pages/data-modification-statements.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,23 @@ VALUES (value_for_from_vertex, value_for_to_vertex, <1>
For each attribute value, provide either an expression _expr_ or `_`, which means the default value for that attribute type.
The optional _name_ which follows the first two (id) values is to specify the source vertex type and target vertex type, if the edge type had been defined with wildcard vertex types.

+
.NULL Value Ingestion
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section does not seem to be in the right place on this page.
You have it as a continuation of the section on " two options for specifying the attributes of the vertex or edge type for the values provided:" But NULLABLE is about the command in general, not about these two options.

I have more to say on this, which I will write in a separate note.

+
The `INSERT INTO` statement supports inserting `NULL` values for attributes defined as `NULLABLE` in the schema.
* `NULL` or `null` can be used in the `VALUES` clause to insert a NULL value.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `NULL` or `null` can be used in the `VALUES` clause to insert a NULL value.
* Either `NULL` or `null` can be used in the `VALUES` clause to represent a NULL value.


.Example
[source,gsql]
----
CREATE VERTEX Student (
PRIMARY_ID id INT,
name STRING NULLABLE,
age INT NULLABLE
);
INSERT INTO Student VALUES (1001, "Alice", NULL);
----

=== Query-Body INSERT

The following query illustrates query-body level `INSERT` statements: insert new `Company` vertices and `Works_For` edges into the `Works_Net` graph.
Expand Down