GSQL Style Guide
This page details TigerGraph’s style guide for writing GSQL. The purpose of the style guide is to make code easy to read and achieve lower cost of maintenance.
General
-
Always write keywords and reserved words in all caps. You can find a list of keywords and reserved words in Query Language Keywords & Reserved Words and DDL Keywords & Reserved Words.
-
If you are storing GSQL statements in a separate file, use the file extension
.gsql
.
Naming
Identifiers are categorized into two broad classes:
-
Schema object types (graph, vertex, edge, and tuple type).
-
Instances.
Schema types are analogous to classes in an object-oriented language. Schema object types names have their initial letter capitalized, connected by underscore; instances use snake case, with additional specifications for accumulators.
Detailed identifier naming conventions are described in the following table:
Identifier type | Style | Example |
---|---|---|
Instances (This includes any variable one can declare in a loading job or query not otherwise specified in the table) |
Use snake case: lowercase, letters connected by underscore |
|
Non-collection accumulators ( |
|
|
Collection accumulator |
|
|
Vertex type name |
Capitalize initial letters and connect words with underscores. |
|
Edge type name |
Capitalize initial letters and connect words with underscores. |
|
Vertex and edge attribute name |
Use snake case. |
|
Graph name |
Capitalize initial letters and connect words with underscores. |
|
Tuple type name |
Capitalize initial letters and connect words with underscores. |
|
Query and loading job name |
Use snake case. |
|
Spacing
Block indentation
Indent the body of a block by 4 spaces.
A block is a syntactic structure which may contain multiple statements.
This includes queries, SELECT
, IF/ELSE
, CASE WHEN/THEN
, FOREACH
, and WHILE
.
If the body of ACCUM
or POST-ACCUM
contains multiple clauses, then use indentation also.
Use spaces instead of tabs, because tab size can vary.
Recommended |
|
---|---|
Not recommended |
|
Line length
Lines should be short enough so that they display without scrolling and can be printed without anything being cut off. If a line is more than 80 characters, it should be split into multiple lines. The additional lines should be indented, but by 2 spaces only, to show that they are a continuation of the previous line.
Keyword justification
In a SELECT
block, line up the keywords FROM
, SAMPLE
, WHERE
, ACCUM
, POST-ACCUM
, HAVING
, GROUP BY
, ORDER BY
, and LIMIT
.
Recommended |
|
||
---|---|---|---|
Not recommended |
|
Comments
-
Use
//
for single line and inline comments. -
Use
/*
at the start and*/
at the end of multiline comments, with the interior comment lines indented. -
Do not use
#
.
Recommended |
|
||||
---|---|---|---|---|---|
Not recommended |
|
num
to refer to a quantity, always put it at the beginning. For example, use num_students
to refer to the number of students instead of students_num