IF .. THEN
, ELSE
, WHILE ... DO
, FOREACH ... DO
statements create a block. A SELECT
statement also creates a block. A block-scoped variable declared inside a block scope is only accessible inside that scope.SELECT
statement.INT
, UINT
, FLOAT
, DOUBLE
, BOOL
, STRING
, DATETIME
, VERTEX
, EDGE
, JSONOBJECT
and JSONARRAY
are called base type variables. The scope of a base type variable is from the point of declaration until the end of the block where its declaration took place.=
) and the desired value on the right side. You can declare multiple variables of the same type in a single declaration statement. ACCUM
or POST-ACCUM
clause, the change will not take place until exitng the clause. Therefore, if there are multiple assignment statements for the same base type variable in an ACCUM
or POST-ACCUM
clause, only the last one will take effect. ACCUM
clause, but the change will not take place until the clause ends. Therefore, the accumulator will not receive the value and will hold a value of 0 at the end of the query. ACCUM
, POST-ACCUM
, or UPDATE SET
clause, are called local base type variables. SELECT
or UPDATE
statement). The lower declaration takes precedence at the lower level. POST-ACCUM
clause, each local base type variable may only be used in source vertex statements or only in target vertex statements, not both.ACCUM
or POST-ACCUM
clause and the change will take place immediately. SELECT
statements. Therefore, before the first SELECT
statement in a query, a vertex set variable must be declared and initialized. This initial vertex set is called the seed set.SetAccum<VERTEX>
accumulator, untyped or typedANY
, _
(equivalent to ANY), or any explicit vertex type(s). See the EBNF grammar rule vertexEdgeType
.vSetName(type)
This is different than a base type variable declaration, where the type specifier is required and comes before the base variable name: type varName
SELECT
statement) to this vertex set variable must match the type. The following is an example in which we must declare the vertex set variable type. person
vertex. If we declare the vertex set variable S
without explicitly giving a type, because the type of vertex parameter m1
is person
, the GSQL engine will implicitly assign S to be person
type. However, if S
is assigned to person
type, the SELECT
statement inside the WHILE
loop causes a type-checking error, because the SELECT
block will generate all connected vertices, including non-person vertices. Therefore, S
must be declared as an ANY-type vertex set variable.FILE
Object DeclarationFILE
object is a sequential text storage object, associated with a text file on the local machine.FILE
object is declared, associated with a particular text file, any existing content in the text file will be erased. During the execution of the query, content written to or printed to the FILE
object will be appended to the FILE
object. When the query where the FILE
object is declared finishes running, the content of the FILE
object is saved to the text file.ACCUM
or POST-ACCUM
clause of a SELECT
statementSET
clause of an UPDATE
statementFOREACH
statementSELECT
or UPDATE
statementsACCUM
or POST-ACCUM
clauses, but the change in value will not take place until exiting the clause. Therefore, if there are multiple assignment statements for the same variable, only the final one will take effect.ACCUM
clause. However, edge attribute assignment is permitted. This is because the ACCUM
clause iterates over an edge set.FOREACH
loops for the loop variable. See the Data Modification section.LOADACCUM
StatementLOADACCUM()
can initialize a global accumulator by loading data from a file. LOADACCUM()
has 3+n parameters explained in the table below, where n is the number of fields in the accumulator. VERTEX
as an element type cannot be initialized by LOADACCUM()
.filePath
columnId
separator
header
LOADACCUM()
function calls. However, every LOADACCUM()
referring to the same file in the same assignment statement must use the same separator and header parameter values. VOID
) or the return value can be ignored, so the function call can be used as an entire statement. This is a Function Call Statement.ListAccum
, SetAccum
, MapAccum
) grow in size as data is added. Particularly for vertex-attached accumulators, if the number of vertices is large, their memory consumption can be significant. It can improve system performance to clear or reset collection accumulators during a query as soon as their data is no longer needed. Running the reset_collection_accum(accumName)
function resets the collection(s) to be zero-length (empty). If the argument is a vertex-attached accumulator, then the entire set of accumulators is reset. reset_collection_accum
only works in DISTRIBUTED mode queries. If the query is not in distributed mode, the reset does not take place.