본문 바로가기

Data Analytics

gsql> help basic and help query

 

GSQL > help basic

Summary of TigerGraph GSQL data definition (DDL) and loading commands.

Please check the GSQL Language Reference, Part 1 for more details.

 

Attribute Types

 INT     FLOAT     STRING             FIXED_BINARY(n)    LIST<elementType>

 UINT    DOUBLE    STRING COMPRESS    UDT                SET<elementType>

 BOOL              DATETIME                              MAP<keyType, valueType>    

 

########################################

##### Schema Definition and Update #####

 

CREATE VERTEX vType (PRIMARY_ID id type,

  attributeName type [DEFAULT default_value]... )

  [WITH STATS=["none"|"outdegree_by_e_type"]

    ### Create a vertex type

 

CREATE DIRECTED EDGE eType (FROM vType, TO vType,

  attributeName type [DEFAULT default_value]... )

  [WITH REVERSE_EDGE="xxx"]

    ### Create a directed edge type.

 

CREATE UNDIRECTED EDGE name (FROM vType, TO vType,

  attributeName type [DEFAULT default_value]... ) 

    ### Create an undirected edge type. 

 

CREATE GRAPH gName (vType..., eType...) ### Create graph schema. 

       or

CREATE GRAPH gName (*) ### Create graph schema with all vertex and edge types.

 

USE GRAPH gName        ### Set gName to be the active graph.

USE GLOBAL             ### No active graph, but global vertex & edge types can be edited.

 

DROP VERTEX vType1,vType2...           ### Drop specified vertex types. 

DROP EDGE   eType1,eType2... [CASCADE] ### Drop specified edge types. 

DROP GRAPH  gName1,gName2... [CASCADE] ### Drop specified graph types.

DROP JOB    jName1,jName2...           ### Drop specified jobs.

DROP JOB ALL                             ### Drop all jobs.

DROP ALL ### Drop all definitions (graph,vertex,edge,job,query). Clear the graph store.

 

 

CLEAR GRAPH STORE [-HARD]

    ### Clear the graph storage.

 

 

CREATE SCHEMA_CHANGE JOB FOR GRAPH gName {

  ### Examples of schema change statements: 

    ADD VERTEX vType (see syntax for CREATE EDGE);

    ADD [UN]DIRECTED EDGE eType (see syntax for CREATE EDGE);

    DROP VERTEX vType;

    DROP EDGE eType;

    ALTER VERTEX vType ADD  ATTRIBUTE (attributeName type [DEFAULT default_value]...);

    ALTER VERTEX vType DROP ATTRIBUTE (attributeName...);

    ALTER EDGE eType ADD  ATTRIBUTE (attributeName [DEFAULT default_value]...);

    ALTER EDGE eType DROP ATTRIBUTE (attributeName...);

}

 

  CREATE GLOBAL SCHEMA_CHANGE JOB {

    ## Examples of global schema change statements:

    ADD VERTEX vType TO GRAPH gName;

    ADD EDGE eType TO GRAPH gName;

    DROP VERTEX vType FROM GRAPH gName;

    DROP EDGE eType FROM GRAPH gName;

    ALTER VERTEX vType ADD  ATTRIBUTE (attributeName type [DEFAULT default_value]...);

    ALTER VERTEX vType DROP ATTRIBUTE (attributeName...);

    ALTER EDGE eType ADD  ATTRIBUTE (attributeName [DEFAULT default_value]...);

    ALTER EDGE eType DROP ATTRIBUTE (attributeName...);

}

    

 

#######################################

##### LOADING JOB - General form  #####

 

 

CREATE LOADING JOB jobName FOR GRAPH graphName {

    [zero or more DEFINE statements]

    (zero or more ONLINE LOAD_statements)

    [zero or more DELETE statements]

}

  ### Create a loading job, to load data and/or delete data.

  ### The three types of constituent statements are defined below:

  

  ### DEFINE_statements

    DEFINE FILENAME fileVar [= filePath];

    DEFINE HEADER headerName = "columnName"[,"columnName"...]; 

    DEFINE INPUT_LINE_FILTER filterName = boolean_expression_using_column_variables;

 

  ### LOAD_statement

    LOAD filePath|fileVar TO Destination_Clause [, TO Destination_Clause...] [USING clause];

  

    # where a Destination_Clause is either for a vertex:

      VERTEX vType VALUES (idExpr[, attrExpr...) [WHERE conditions]

  

    # or for an edge:

      EDGE eType VALUES (sourceIdExpr, targetIdExpr [, attrExpr...])

        [WHERE conditions] [OPTION (options)]

        

    ### Attribute and Id Expressions attrExpr and idExpr ###

    # Attribute expressions can refer to input columns by place, $0 = leftmost column,

    # or by name, $"colName", where colName appears in the header.

    # The value _ loads the default value (or retains the previous value).

        

    ### USING options:

      HEADER = "true"|"false"     ### Whether to treat the first data line as column labels

      SEPARATOR = "sChar"         ### character to treat as column separator in the data file

      EOL = "eChar"               ### The char(s) which mark the end of a data line

      QUOTE = "single"|"double"   ### single|double quotes mark explicit string boundaries

      JSON_FILE = "true"|"false"  ### input file is|isn't in JSON format

      USER_DEFINED_HEADER = headerName  ### Use the defined column names

      REJECT_LIST_RULE = filterName     ### When filter expr is true, don't use this line

 

  ### Online DELETE statements (different than Query DELETE)

    # 1. Delete each vertex which has the given vertex type and primary id.

      DELETE VERTEX vType (PRIMARY_ID idExpr) FROM fileVar [WHERE condition];

 

    # 2. Delete each edge which has the given edge type, source id, and target id.

      DELETE EDGE   eType (FROM idExpr, TO idExpr) FROM fileVar [WHERE condition];

 

    # 3. Delete all edges which have the given edge type and source id.

      DELETE EDGE   eType (FROM idExpr) FROM fileVar [WHERE condition];

 

    # 4. Delete all edges which have the given source id.

      DELETE EDGE * (FROM idExpr vType) FROM fileVar [WHERE condition];

  

########################################################

### Attribute and Id Expressions attrExpr and idExpr ###

# Attribute expressions can refer to input columns by location, $1 = leftmost column,

# or by name, $"colName", where colName appears in the header.

# An attribute value of _ loads the default value.

 

 

### Example: ###

CREATE LOADING JOB load_simprod FOR GRAPH gsql_demo {

  DEFINE HEADER head1 = "id","hash","words";

  DEFILE FILENAME f;

  LOAD f

    TO VERTEX Product values ($"id", $"hash"),

    TO TEMP_TABLE t (pid, description) VALUES ($"id", flatten($"words", ",", 1))

    USING QUOTE="double", USER_DEFINED_HEADER="head1";

  LOAD TEMP_TABLE t

    TO VERTEX DescWord VALUES ($"description"),

    TO EDGE Has_desc VALUES ($"pid", $"description");

}

 

 

RUN LOADING JOB [-n [ firstLineNum,] lastLineNum] [-dryrun] [-noprint] jobName

    USING fileVar="filePath" [,fileVar="filePath"...]

  ### Run a loading job on a complete file (or on a specific range of lines)

 

SHOW LOADING STATUS jobId|ALL

ABORT LOADING JOB  jobId|ALL

RESUME LOADING JOB jobId

 

####### Built-in DML Commands ################################

# To make full use of the data-explore-compute power of the GSQL language, you

# need to create and install a QUERY. The following simple operations are built in

# to the GSQL shell and do not have to be compiled.

##############################################################

 

 

SELECT *|attributeName      ### Select a set of vertices.

    FROM vType

    [WHERE conditions]

    [ORDER BY attribute1,attribute2...]

    [LIMIT k]

  ### To specify a primary id, use primary_id=="xxx" (lowercase) in the WHERE clause.

  ### NOTE: Either the WHERE or LIMIT clause must be used, to prevent the output

  ###       from being too large.

     

SELECT *|attributeName      ### Select a set of edges.

    FROM from_vType -(eType)-> to_vType

    WHERE from_id=="xxx" [AND conditions]

    [ORDER BY attribute1, attribute2...]

    [LIMIT k]

  # To avoid excessive output size, a source vertex id (from_id) is required.

  # To specify the target vertex id, use to_id="xxx" (lowercase) in WHERE clause.

  # To allow any eType or or to_vType, use the keyword ANY.

     

SELECT count()           ### Report how many vertices or edges are in the selected set.

    FROM vType | from_vType -(eType)-> to_vType

 

DELETE                       ### Delete selected vertices or edges.

    FROM vType | from_vType -(eType)-> to_vType

    [where conditions]

 

UPSERT vType VALUES (id,attrVal1, ...)

  ### Insert or update one vertex.

 

UPSERT from_vType -(eType)-> to_vType VALUES (fromId, toId, attrVal1...)

  ### Insert or update on edge.

 

 

GSQL > help query

GSQL Help Query: Outline of TigerGraph GSQL Query language

 

This page describes how to create/install/run user-designed query-and-compute

procedures.  For help with the built-in query commands, see the end of the

GSQL Help Basic page.

 

See the GSQL Language Reference, Part 2 or the GSQL Query Language Reference Card

for more details about GSQL Queries.

 

 

### Define and compile a GSQL Query (that is, a graph data explore-compute procedure)

### See details about the query body in the next section.

 

CREATE [OR REPLACE] QUERY query_name (parameters...) FOR GRAPH graphname

  [RETURNS return_type] [API("vnum")]

{

    [typedefStmts]

    [accumDeclarations]

    [otherDeclarations]

    [exceptionDeclarations]

    [queryBodyStatements]

}

 

 

INSTALL QUERY query_name1, query_name2, ...

INSTALL QUERY ALL

    ### Install the given query(ies)

    

 

INSTALL QUERY -OPTIMIZE

    ### Re-install, with static linking for faster performance, all of the

    ### already-installed queries.

 

RUN QUERY query_name (param1,param2,...)

    ### Run the given query, using these parameter values

 

DROP QUERY query_name1, query_name2, ...

DROP QUERY ALL

    ### Drop the given query(ies)

 

SHOW QUERY query_name

    ### Display the given query 

    

###############################################

###### Details about a CREATE QUERY body ######

###############################################

 

typeDefStmts    ### Define a user-defined tuple. ###

    TYPEDEF TUPLE < baseType name [,baseType name]* > tuple_name

  

accumDeclarations  ### 2 types: vertex-attached accumulators and global accumulators ###

  

  ### global ###

    [STATIC] accumType @@name [= constant] [, @@name [= constant] ]*

  ### vertex-attached ###

            accumType @name [= constant] [, @name [= constant] ]*

 

exceptionDeclarations 

### Declare an exception type

EXCEPTION exceptVarName "("errorInt")";  // errorInt > 40000

 

otherDeclarations

  ### Declare a vertex set variable ###

    vSetVar = {vertex_param}

           | vertex_set_param

           | SetAccum_vertex_var

           | ANY

           | _

           | vSetVar2

           | {vSetVar1, vSetVar2, ...}

           | vSetVar1 UNION vSetVar2

           

  ### Declare a base type variable ###

    baseType varName

 

queryBodyStatements and DMLSubStatements 

################################################

# Each queryBodyStatement ends with a semicolon.

# DMLSubStatements are sub-statements within a SELECT or UPDATE statement.

# A sequence of DMLSubStatements is comma-separated (no semi-colon at end).

### Below are the major statement categories ###

 

 

  ### SELECT statement: basic graph traversal (queryBody Level only) ###

    vSetVar = SELECT sAlias|tAlias

        FROM  vSetVar:sAlias -(eType:eAlias)-> vType:tAlias

        [WHERE condition]

        [SAMPLE expr EDGE|TARGET WHEN condition]

        [ACCUM DMLSubStatements]

        [POST-ACCUM DMLSubStatements]

        [HAVING condition]

        [ORDER BY expr ASC|DESC [, expr ASC|DESC]*

        [LIMIT expr [OFFSET expr]]

 

 

  ### Control Flow ###

    IF condition THEN statements

    [ELSE IF condition THEN statements]*

    ELSE statements END

    

    CASE      (WHEN condition THEN statements)+ [ELSE statements] END

 

    CASE expr (WHEN constant THEN statements)+ [ELSE statements] END

    

    WHILE condition [LIMIT intExpr] DO statements END

    

    FOREACH var IN setBagExpr DO statements END

    

    FOREACH var IN RANGE "["expr, expr"]"[.STEP"("expr")"] DO statements END

    

    

  ### Data Modification (DML) Statements ###

      INSERT INTO eType (FROM, TO, attr_list) VALUES (fromId, toId, attrValues)

    

    ### UPDATE (only at the DMLSub level) ###

      UPDATE alias FROM vSetVar:s_alias

        SET DMLSubStatements [WHERE condition]

    

      UPDATE alias FROM vSetVar:sAlias -(eType:eAlias)-> vType:tAlias

        SET DMLSubStatements [WHERE condition]

        

    ### Query-body level DELETE ###

      DELETE alias FROM vSetVar:s_alias [WHERE condition]

    

      DELETE alias FROM vSetVar:sAlias -(eType:eAlias)-> vType:tAlias [WHERE condition]  

    

    ### DMLSub-level DELETE (within ACCUM or POST-ACCUM clause) ###

      DELETE (alias)

    

    

  ### Accumulator Assignment ###

    alias.@accumName = expr    # set

    alias.@accumName += expr   # accumulate

    @@accumName = expr         # set. Forbidden at the DMLSub-level

    @@accumName += expr        # accumulate

    

    

  ### Output statements ###

  

    PRINT expr [AS name][, expr [AS name]]* [WHERE condition] [ TO_CSV filename]

        ### Evaluate and output the expressions to the console in JSON format,

        ### or to a file in CSV format. Only allowed as a queryBodyStatement.

    

    LOG (condition, expression)

        ### Print the expression to the GPE log if condition is true.

    

    RETURN returnVar   ### To end a subquery, which began CREATE QUERY ... RETURNS...

    

  ### Exception statements ###

  

RAISE exceptVarName [errorMsg]

 

### Try Block ###

TRY

queryBodyStmts # contains at least one RAISE statement

EXCEPTION

[WHEN exceptVarName THEN queryBodyStmts ]+

[ELSE queryBodyStmts]

END;

       

 

 

 

 
 
Best,
조 현 기 기술이사
TigerGraph, Inc. | +82-10-7134-2596 | jacob.jo@tigergraph.com
Join us for a live demonstration - https://www.tigergraph.com/live-demo/