PRINT
Statement (API v2)printExpr
contributes one key-value pair to the PRINT statement's JSON object result. The optional AS clause sets the JSON key for the expression, overriding the default key (explained below).printExpr
expressions can be including in one PRINT statement.PRINT
ExpressionsprintExpr
may be one of the following:VERTEX
and EDGE
variables)+
UNION INTERSECT MINUS
+ - * / . %
Bit: << >> & |
vExprSet
(only available if the output API is set to "v2"
. Vertex expression sets are explained in a separate section below.printExpr
includes the optional AS name clause, then the name sets the key for that expression in the JSON output. Otherwise, the following rules determine the key: If the expression is simply a single variable (local variable, global variable, global accumulator, or vertex set variable), then the key is the variable name. Also, for a vertex expression set, the key is the vertex set variable name. Otherwise, the key is the entire expression, represented as a string.AvgAccum
outputs a DOUBLE
value, and a BitwiseAndAccum
outputs an INT
value. For container accumulators, simply consider whether the output is a list, set, bag, or map.ListAccum
, SetAccum
, BagAccum
, ArrayAccum
: listMapAccum
: mapHeapAccum
, GroupByAccum
: list of tuplesPRINT C[C.country]
prints the vertex set variable C, except that the "attributes" field will contain only "country", instead of 3 fields.PRINT C[[email protected]]
prints the vertex set variable C, except that the "attributes" field will contain only "@count", instead of 3 fields.PRINT C[[email protected] AS company_count]
prints the same as above, except that the "@count" accumulator is is aliased as "company_count".PRINT C[C.id, [email protected]]
prints the vertex set variable C, except that the "attributes" field will contain only "id" and "@count".PRINT C[C.id+"_ex", [email protected]+1]
prints the vertex set variable C, except that the "attributes" field contains the following:TO_CSV
followed by the FILE
object name:PRINT
statement appends one line to the FILE
. If the PRINT
statement includes multiple expressions, then each printed value is separated from its neighbor by a comma. If an expression evaluates to a set or list, then the collection's values are delimited by single spaces. Due to the simpler format of CSV vs. JSON, the TO_CSV
feature only supports data with a simple one- or two-dimension structure.FILE println
statementFILE println
statement writes data to a FILE
object. Unlike the PRINT
statement, which is a query-body level statement, the FILE println
statement can be either a query-body level statement or a DML-sub-statement. println
is a method of a FILE object variable. The println
statement can be used either at the query-body level or a DML-sub-statement, e.g., within the ACCUM clause of a SELECT block. Each time println
is called, it adds one new line of values to the FILE
object, and then to the corresponding file.println
function can print any expression that can be printed by a PRINT
statement with the exception of vertex set variables. Vertex expression sets are also not applicable to the println
function. println
statement has a list of expressions to print, it will produce a comma-separated list of values. If an expression refers to a list or set, then the output will be a list of values separated by spaces.FILE
print statements (either TO_CSV
or println
) will appear in their original order. However, due to the parallel processing of statements in an ACCUM block, the order in which println
statements at the DML-sub-statement level are processed cannot be guaranteed. PRINT
statements in this example use the TO_CSV
option, so there is no JSON output to the console.FILE
object. In the query definition, the line "header"
is printed first, followed by the println
statements in the ACCUM
clause, and "footer"
is printed last. The output in the file follows this order because the order of query-body level statements is maintained in the output. ACCUM
clause itself, the order of the println
statements is not guranteed. LOG
StatementRETURN
StatementRETURN
statement can be any base type or accumulator type, but must be the same type as indicated by the RETURNS
clause of the subquery. HeapAccum
or GroupByAccum
, the accumulators must be defined at the catalog level. See the example below: