- Query
- Solve
- Management
SQL/PGQ
SQL/PGQ can be used to query an existing graph using the supported subset of the Cypher Query Language syntax. A graph query can also be used within a SQL query to join the graph result to a data model.Parameters
<schema name>
<schema name>
Name of the schema containing the graph; if no schema is specified, the graph will be
looked for in the user’s default schema
<graph name>
<graph name>
Name of the graph to query
<match expr>
<match expr>
Any supported Cypher Individual labels, property names, and column names can be double-quoted if needed to avoid
conflicts with the Cypher query syntax:
MATCH expression.For example, to query for relationships with the following criteria:- Starting node can be referred to with
jsin the rest of the graph query - Starting node has both
User&Adminlabels - Starting node has property values of
Joe&Smithfor propertiesfirst_name&last_name, respectively - Ending node is one hop away from the starting node
- Ending node has a label of
User
MATCH expression:| Expression | Description | ||||||
|---|---|---|---|---|---|---|---|
() | Node Matcher Matches any node. | ||||||
(<ref>) | Node Reference Matches any node; matched nodes are able to be referenced as <ref> in the rest of the match statement. | ||||||
(:<label>) | Node Label Matcher Matches any node with a label of <label>; any number of labels can be combined to form a composite restriction:
| ||||||
({<name>: <value>}) | Node Property Matcher Matches any node with a property <name> whose value is <value>; any number of properties can be combined to form a composite restriction requiring a node to have all the specified property values; e.g.: Mutually exclusive with the Node WHERE Clause Matcher | ||||||
(WHERE <expression>) | Node WHERE Clause Matcher Matches any node that meets the restrictions of the given <expression>; this is a standard SQL WHERE clause that can reference a node’s ID, properties, or labels, but cannot include sub-query constructs (ANY/ALL/IN/EXISTS); e.g.: Mutually exclusive with the Node Property Matcher | ||||||
[] | Edge Matcher Matches any edge. | ||||||
[<ref>] | Edge Reference Matches any edge; matched edges are able to be referenced as <ref> in the rest of the match statement. | ||||||
[:<label>] | Edge Label Matcher Matches any edge with a label of <label>; any number of labels can be combined to form a composite restriction:
Each relationship can have only 1 label. | ||||||
({<name>: <value>}) | Edge Property Matcher Matches any edge with a property <name> whose value is <value>; any number of properties can be combined to form a composite restriction requiring an edge to have all the specified property values; e.g.: Mutually exclusive with the Edge WHERE Clause Matcher | ||||||
[WHERE <expression>] | Edge WHERE Clause Matcher Matches any edge that meets the restrictions of the given <expression>; this is a standard SQL WHERE clause that can reference an edge’s label, node IDs, or properties, but cannot include sub-query constructs (ANY/ALL/IN/EXISTS); e.g.: Mutually exclusive with the Edge Property Matcher | ||||||
()-[]->() | Path Matcher Matches any node connected via an edge to another node. Relationships must be specified with a directional arrow indicating the direction of the relationship; however, the direction restriction specified will be ignored if the following hint is given with the query: | ||||||
()-[]->{n[,m]}() | Path Repeater Matches any node connected via n number of edges to another node. If the optional m is specified, the number of edges must be between n and m, inclusive. Any restriction on the edge is in effect for all n to m intermediate edges between the start and end nodes. |
<filter list>
<filter list>
Filter expressions to apply to the entire graph query. The expressions can include columns on
which the graph is based, not just names & labels available in the graph itself.
<return list>
<return list>
Expressions referencing graph names, graph labels, or supporting graph table columns to use as
the result set for the graph query. Each expression must include a unique alias.
<ordering list>
<ordering list>
Ordering expression(s) to apply to the result set. Columns referenced do not have to be present
in the
RETURN clause.<num rows>
<num rows>
Maximum number of records to return in the result set.
Examples
For example, to query for managers in department 6 making more than $150,000:Node Query Example
Edge Query Example
Path Query Example
Variable Hop Path Query Example
SQL/PGQ Query as a Subquery Example
Limitations & Suggestions
- Graph must be created via SQL and must not be altered, either via SQL or a native API.
-
Graph must be created with all nodes having:
- the same identifier combination
- a single column identifier
- the same data type
- the same nullability—when creating a graph with constant values, the
REMOVE_NULLABLEfunction can be used to make the valueNOT NULL
-
Graph should be created with Node & edge
INPUT_TABLESas regular tables or materialized views instead of queries or logical views. This will reduce the complexity of query plans involving joins on the graph source data, and improve the performance of SQL/PGQ queries overall. -
Graph should be created with the
add_table_monitoroption if the data in the graph support tables are expected to change, as those changes would otherwise cause the graph and its tables to go out-of-sync, returning wrong results in SQL/PGQ queries. If the data in the support tables will not change, this option can be omitted. - Querying a graph in this manner generally requires that, when the graph being queried was created, no correlated subqueries were used as part of any input table queries. However, a materialized view can be created containing the query, and then the view can be used in place of the query as an input table.
QUERY_GRAPH
Queries an existing graph using unique query identifiers and combinations. TheQUERY_GRAPH function
can be called either within a SELECT statement as a table function or within
an EXECUTE FUNCTION call.
Parameters
GRAPH
GRAPH
Name of the graph to query
QUERIES
QUERIES
Nodes or edges to be queried specified using the SQL
INPUT_TABLE or INPUT_TABLES function; review
Query Identifiers and Query Identifier Combinations for more information.The input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
ADJACENCY_TABLE
ADJACENCY_TABLE
Name of the table to store the resulting adjacent edges in
[schema_name.]table_name format, using standard
name resolution rules and meeting
table naming criteria; a table storing the resulting matching nodes will also
be created, named <ADJACENCY_TABLE>_nodesOnly applicable when using the
EXECUTE FUNCTION syntaxRINGS
RINGS
Sets the number of rings around (hops from) the queried node(s) to return matching edges & nodes
Only applicable when querying on nodes; e.g., giving
NODE_NAME or NODE_LABELRESTRICTIONS
RESTRICTIONS
Additional restrictions to apply to the nodes/edges of an existing graph specified using the SQL
INPUT_TABLE or INPUT_TABLES function; review Components and Identifiers and Identifier Combinations for more
information.The input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
Only applicable when querying on nodes; e.g., giving
NODE_NAME or NODE_LABELOPTIONS
OPTIONS
Optional indicator that a comma-delimited list of connection option/value assignments will follow.
| Option | Description |
|---|---|
and_labels | If true, the result of the query has entities that satisfy all the target labels instead of any of the labels. The default is false. |
find_common_labels | If true, adds a LABELS column to the output tables specified by ADJACENCY_TABLE. When RINGS is 0, all labels of queried nodes & edges will be listed in this column; otherwise, (for many-to-many queries and multi-level traversals), all common labels between the source & target nodes, as well as common edge labels in each path will be listed. The default is false. |
force_undirected | If true, all inbound & outbound edges relative to the node will be returned. If set to false, only outbound edges relative to the node will be returned. The default is false. Consult Directed Graphs for more details. Only applicable when querying on nodes on a directed graph |
limit | When specified, limits the number of query results. The size of the corresponding node table will also be limited by this value. |
output_charn_length | When specified, limits the size of string columns in the output tables. The default is 64. Valid values are between 1 & 256. |
output_wkt_path | If true, adds a QUERY_EDGE_WKTLINE column to the specified ADJACENCY_TABLE so the solution can be viewed via WMS; for social and non-geospatial solutions, the QUERY_EDGE_WKTLINE column will be populated with spatial coordinates derived from a flattening layout algorithm so the solution can still be viewed. The default is false. |
result_table_index | Indicates which result table to return results from:
Only applicable when using the table function syntax |
server_id | Indicates which graph server(s) to send the request to. Default is to send to the server, amongst those containing the corresponding graph, that has the most computational bandwidth. |
Examples
Using theEXECUTE FUNCTION syntax necessitates the ADJACENCY_TABLE
parameter to store the query results, where using the table function syntax will
return the results directly.
Querying by Hops
Queries can make use of aHOP_ID
identifier to match nodes & edges at a given
distance from the source node or edge.
A graph of movies and their actors & directors can be queried, for instance, to
return the titles & directors of movies in which James Spader has acted. Here,
the query starts with the James Spader actor node and uses HOP_ID filters
to:
- move across
actededges in the 1st hop to all the nodes in which James Spader has acted - find the director nodes connected to those movies in the 2nd hop; note the
-2for theHOP_IDallows one-way edges to be traversed in reverse—thedirectededge connecting directors to the movies they directed is one-way, from director to movie, but the query needs to move from movie to director of that movie, thus the-2designation for the 2nd hop to follow those edges in reverse
Query by Hop ID Example
Querying for Commonalities
Queries can make use of thefind_common_labels option to list labels shared
by both source & target node, as well as labels shared by edges in the result
paths.
A graph of movies and their actors & directors can be queried, for instance, to
return the common occupations within filmmaking between Al Pacino and those who
have directed movies in which he has acted. Here, the query starts with the Al
Pacino actor node, looks within two hops for directors
(Al Pacino->movie->directed by), and returns those directors along with
occupations shared by Al Pacino and each one:
Query for Common Labels Example
Supplementing Queried Graph Data
As graph queries ultimately produce standard SQL result sets, they can be used in larger SQL queries as joins or sub-selects to add data to result sets or to filter data out of them. A graph of movies and their actors & directors can be queried, for instance, to return the actors in Jean Reno movies, and that result can be joined with a table of actor biographical data to also return the ages of those actors. Here, the query starts with the Jean Reno actor node, looks within two hops for actors (Jean Reno->movie->acted in), and returns those actors along with their respective current ages by subtracting their corresponding date of birth (dob column) in the biographical table (person) from the current date:
Supplementing Graph Query Example
MATCH_GRAPH
Matches an existing graph to a dataset using one of the supported solver types and sample points which are defined using unique match identifiers and combinations. TheMATCH_GRAPH function
can be called either within a SELECT statement as a table function or within
an EXECUTE FUNCTION call.
Parameters
GRAPH
GRAPH
Name of the graph to match
SAMPLE_POINTS
SAMPLE_POINTS
Sample points used to match an underlying geospatial graph specified using the SQL
INPUT_TABLE or
INPUT_TABLES function. Sample points are specified as identifiers,
which are grouped into combinations.The input can be either the name of a table with appropriately named columns; or a query, to
use specific columns or other SQL features).
SOLVE_METHOD
SOLVE_METHOD
The type of solve method to use for the operation; review Match Identifier Combinations for more
information.
| Solver | Description | CPU Parallel |
|---|---|---|
MARKOV_CHAIN | Matches sample points to the graph using the Hidden Markov Model (HMM)-based method, which conducts a range-tree closest-edge search to find the best combinations of possible road segments for each sample point to create the best route. The route is secured one point at a time, so the prediction is corrected after each point. This solution type is the most accurate, but also the most computationally intensive. | X |
MATCH_BATCH_SOLVES | Matches each provided sample source and destination pair using the shortest path between the points. | X |
MATCH_CHARGING_STATIONS | Matches a given sample source and destination pair to the optimal recharging stations along the route (for EVs). | X |
MATCH_CLUSTERS | Matches the graph nodes with a cluster index using the Louvain clustering algorithm. Parallel running of this solver is experimental and can be invoked with the parallel_clustering option. | X* |
MATCH_LOOPS | Matches closed loops (Eulerian paths) originating and ending at each graph node between min and max hops (levels). | X |
MATCH_OD_PAIRS | Matches sample points to find the most probable path between origin and destination (OD) pairs with given cost constraints. | X |
MATCH_SIMILARITY | Computes the Jaccard similarity between vertex pairs and N-level intersections within M hops. | X |
MATCH_SUPPLY_DEMAND | Matches sample generic supply depots to generic demand points using abstract transportation (referred to as trucks). Each route is determined by a truck’s ability (size) to service demand at each demand point. | X |
SOLUTION_TABLE
SOLUTION_TABLE
Only applicable when using
EXECUTE FUNCTION syntax. Name of the table to store the solution
in [schema_name.]table_name format, using standard
name resolution rules and meeting
table naming criteriaOPTIONS
OPTIONS
Optional indicator that a comma-delimited list of connection option/value assignments will follow.
| Option | Description |
|---|---|
aggregated_output | For the MATCH_SUPPLY_DEMAND solver only. When set to true (default), each record in the output table shows a particular supplier’s scheduled cumulative round-trip path (MULTILINESTRING) and the corresponding aggregated cost. Otherwise, each record shows a single scheduled supplier route (LINESTRING) towards a particular demand site with its corresponding cost. |
batch_tsm_mode | For the MATCH_SUPPLY_DEMAND solver only. If set to true (non-default), each supplier is limited to drop off 1 unit of supply at each demand site visited per trip, in order to model the traveling salesman problem. |
chain_width | For the MARKOV_CHAIN solver only. Length of the sample points lookahead window within the Markov kernel; the larger the number, the more accurate the solution. The default value is 9. |
charging_candidates | For the MATCH_CHARGING_STATIONS solver only. Solver searches for this many stations closest to each base charging location found by capacity. The default value is 10. |
charging_capacity | For the MATCH_CHARGING_STATIONS solver only. The maximum charging capacity of an EV (distance in meters or time in seconds, depending on the unit of the graph weights). The default value is 300000. |
charging_penalty | For the MATCH_CHARGING_STATIONS solver only. The penalty for fully charging. The default value is 30000. |
cluster_quality_metric | For the MATCH_CLUSTERS solver only. The quality metric for Louvain modularity optimization solver. |
destination | Optional WKT ending point from SAMPLE_POINTS for the solver. The default behavior for the endpoint is to use time to determine the destination point. The default value is POINT NULL. |
enable_reuse | For the MATCH_SUPPLY_DEMAND solver only. If set to true (non-default), all suppliers can be scheduled for additional rounds of supply drop-off from their originating depots. |
filter_folding_paths | For the MARKOV_CHAIN solver only. When set to true (non-default), the paths per sequence combination is checked for folding over patterns and can significantly increase the execution time depending on the chain width and the number of GPS samples. |
gps_noise | GPS noise value (in meters) to remove redundant sample points. Use -1 to disable noise reduction. The default value (5.0) accounts for 95% of point variation (±5 meters) |
intersection_penalty | This will add an additional weight over the edges labeled as intersection if the add_turn option was invoked during graph creation. The default value is 0.0. |
inverse_solve | For the MATCH_BATCH_SOLVES solver only. Solves source-destination pairs using inverse shortest path solver. |
left_turn_penalty | This will add an additional weight over the edges labeled as left_turn if the add_turn option was invoked during graph creation. The default value is 0.0. |
max_combinations | For the MATCH_SUPPLY_DEMAND solver only. This is the cutoff for the number of generated combinations for sequencing the demand locations. The maximum number of combinations is 2000000. The default value is 10000. |
max_hops | For the MATCH_SIMILARITY solver only. Solver searches within this many hops for source and target node pairs to compute the Jaccard scores. The default value is 3. |
max_loop_level | For the MATCH_LOOPS solver only. Finds closed loops around each node deducible not more than this maximal hop (level) deep. |
max_num_clusters | For the MATCH_CLUSTERS solver only. If set, processing terminates when the number of clusters after a cycle is at or below this number; thus, the solution will have at most this many clusters in it. |
max_num_threads | For the MARKOV_CHAIN solver only. If specified value is greater than 0 (default), the maximum number of threads will not be greater than the specified value. It can be lower due to the memory and number of cores available. The default value allows the algorithm to set the optimal number of threads within these constraints. |
max_stops | For the MATCH_SUPPLY_DEMAND solver only. If specified (greater than zero), a supplier can at most have this many stops (demand sites) in one round trip; otherwise, it is unlimited. If enable_reuse is on, this condition will be applied separately at each round-trip use of the same supplier. |
max_supply_combinations | For the MATCH_SUPPLY_DEMAND solver only. This is the cutoff for the number of generated combinations for sequencing the supply locations, when permute_supplies is true. The default value is 10000. |
max_trip_cost | For the MATCH_SUPPLY_DEMAND solver only. If this constraint is greater than 0 (default), then the suppliers will skip traveling from one demand site to another if the cost between them is greater than this number (distance or time). The default value means no check is performed. |
min_loop_level | For the MATCH_LOOPS solver only. Finds closed loops around each node deducible not less than this minimal hop (level) deep. |
num_cycles | For the MATCH_CLUSTERS solver only. If this is greater than 0 (default), then at most this many 2-step clustering exchange cycles will be performed; otherwise, processing will continue until quality does not improve across iterations. |
num_loops_per_cycle | For the MATCH_CLUSTERS solver only. If this is greater than 0 (default), then at most this many best-fit calculations for all nodes will be attempted in the first step of each cycle; otherwise, processing will continue until the overall best-fit quality does not improve beyond a pre-defined epsilon threshold value. |
num_output_clusters | For the MATCH_CLUSTERS solver only. If this is greater than 0 (default), then at most this many of the top clusters will be output after sorting them from most dense to least dense; otherwise, all clusters will be output. |
num_segments | Maximum number of potentially matching road segments for each sample point. The default is 3. |
output_batch_size | For the MATCH_LOOPS solver only. Uses this value as the batch size of the number of loops in flushing (inserting) to the output table. |
output_tracks | For the MATCH_SUPPLY_DEMAND solver only. When it is true (non-default), the output will be in tracks format for all the round trips of each supplier in which the timestamps are populated directly from the edge weights starting from their originating depots. |
paired_similarity | For the MATCH_SIMILARITY solver only. When set to true (default), the Jaccard score will be computed between each pair; otherwise, the Jaccard score will be computed from the intersection set between the source and target nodes. |
partial_loading | For the MATCH_SUPPLY_DEMAND solver only. When false (non-default), suppliers do not off-load at the demand site side if the remainder is less than the site’s demand. |
permute_supplies | For the MATCH_SUPPLY_DEMAND solver only. When true (default), suppliers are permuted for the demand site combinations during the optimization phase. This option increases optimization time significantly—use of max_combinations in tandem is recommended to prevent prohibitively long runs. |
restricted_type | For the MATCH_SUPPLY_DEMAND solver only. If specified, this supplier type will be restricted from routes traversing edges with the MSDO_ODDEVEN_RESTRICTED label. This models restrictions that exist, for example, in Jakarta, Indonesia. Possible values:
|
right_turn_penalty | This will add an additional weight over the edges labeled as right_turn if the add_turn option was invoked during graph creation. The default value is 0.0. |
round_trip | For the MATCH_SUPPLY_DEMAND solver only. When set to true (default), each supplier will have to return to the origination site; otherwise, the route is considered terminated at the final demand site. |
search_limit | For the MATCH_LOOPS solver only. Searches within this limit of nodes per vertex to detect loops. The value zero means there is no limit. |
search_radius | Maximum search radius used when snapping sample points onto potentially matching surrounding segments. The default value (0.001) corresponds to approximately 100 meters. |
server_id | Indicates which graph server(s) to send the request to. Default is to send to the server, among those containing the corresponding graph, that has the most computational bandwidth. |
service_limit | For the MATCH_SUPPLY_DEMAND solver only. If specified, any supplier’s total service cost (distance or time) will be limited by the specified value including multiple rounds of drop-off (if set). The default value is 0.0. |
service_radius | For the MATCH_SUPPLY_DEMAND solver only. If specified, it filters the demands outside this radius, centered around the supplier’s originating location (distance or time). The default value is 0.0. |
sharp_turn_penalty | This will add an additional weight over the edges labeled as sharp_turn or u_turn if the add_turn option was invoked during graph creation. The default value is 0.0. |
source | Optional WKT starting point from SAMPLE_POINTS for the solver. The default behavior for the endpoint is to use time to determine the starting point. The default value is POINT NULL. |
traversal_node_limit | For the MATCH_SIMILARITY solver only. Limits the traversal depth if it reaches this many nodes. The default value is 1000. |
unit_unloading_cost | For the MATCH_SUPPLY_DEMAND solver only. The unit cost per load amount to be delivered. If this value is greater than 0 (default) then the additional cost of this unit load multiplied by the total dropped load will be added over to the trip cost to the demand location. |
Examples
Using theEXECUTE FUNCTION syntax necessitates the SOLUTION_TABLE
parameter to store the match results, where using the table function syntax will
return the results directly.
SOLVE_GRAPH
Solves an existing graph using one of the supported solver types. TheSOLVE GRAPH function can be called either within a SELECT statement as a
table function or within an EXECUTE FUNCTION call.
Parameters
GRAPH
GRAPH
Name of the graph to solve
SOLVER_TYPE
SOLVER_TYPE
The type of solver to use for the operation.
| Solver | Description | CPU Parallel |
|---|---|---|
ALLPATHS | Determines all reasonable paths between a source and destination pair. | X |
BACKHAUL_ROUTING | Determines the optimal routes between remote asset nodes and fixed asset nodes. | X |
CENTRALITY | Calculates the degree of a node to depict how many pairs of individuals that would have to go through the node to reach one another in the minimum number of hops. Also known as betweenness. | X |
CLOSENESS | Calculates the centrality closeness score per node as the sum of the inverse shortest path costs to all nodes in the graph. | X |
INVERSE_SHORTEST_PATH | Determines the shortest path downstream using multiple technician routing. | X |
MULTIPLE_ROUTING | Calculates the shortest possible route between the nodes and returns to the origin node — also known as the traveling salesman. | X |
PAGE_RANK | Calculates how connected the nodes are and determines which nodes are the most important. Weights are not required. | X |
PROBABILITY_RANK | Calculates the probability of a node being connected to another node using hidden Markov chains. | X |
SHORTEST_PATH | Determines the shortest path upstream between given source(s) and destination(s). | X |
STATS_ALL | Calculates graph statistics such as graph diameter, longest pairs, vertex valences, topology numbers, average and max cluster sizes, etc. | X |
SOURCE_NODES
SOURCE_NODES
The node(s) used as the origin point(s) for the solution specified using the SQL
INPUT_TABLE or
INPUT_TABLES function.The input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
SOLUTION_TABLE
SOLUTION_TABLE
Only applicable when using
EXECUTE FUNCTION syntax. Name of the table to store the solution
in [schema_name.]table_name format, using standard name resolution rules
and meeting table naming criteriaDESTINATION_NODES
DESTINATION_NODES
The node(s) used as the destination point(s) for the solution specified using the SQL
INPUT_TABLE or
INPUT_TABLES function.The input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
WEIGHTS_ON_EDGES
WEIGHTS_ON_EDGES
Additional weights to apply to the edges of an existing graph specified using the SQL
INPUT_TABLE or
INPUT_TABLES function; review Components and Identifiers and Identifier Combinations for more information.The input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
RESTRICTIONS
RESTRICTIONS
Additional restrictions to apply to the nodes/edges of an existing graph specified using the SQL
INPUT_TABLE or INPUT_TABLES function; review Components and Identifiers and Identifier Combinations for more
information.The input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
OPTIONS
OPTIONS
Optional indicator that a comma-delimited list of connection option/value assignments will follow.
| Option | Description |
|---|---|
astar_radius | For SHORTEST_PATH, INVERSE_SHORTEST_PATH, ALLPATHS, and MULTIPLE_ROUTING solvers, when solve_heuristic is astar. The shortest path traversal front includes nodes only within this radius (kilometers) as it moves towards the target location. Default is 70. |
convergence_limit | For PAGE_RANK solver only; maximum percent relative threshold on the pagerank scores of each node between consecutive iterations to satisfy convergence. Default value is 1%. |
intersection_penalty | This will add an additional weight over the edges labeled as intersection if the add_turn option was invoked during graph creation. The default value is 0.0. |
left_turn_penalty | This will add an additional weight over the edges labeled as left_turn if the add_turn option was invoked during graph creation. The default value is 0.0. |
max_iterations | For PAGE_RANK solver only; maximum number of pagerank iterations for satisfying convergence. Default value is 100. |
max_num_combinations | For MULTIPLE_ROUTING solver only. Sets the cap on the combinatorial sequence generated. If the default value (2000000) is overridden, it potentially speeds up the solver. |
max_runs | For CENTRALITY solver only. Sets the maximum number of shortest path runs—maximum possible value is the number of nodes in the graph. Default of 0 enables this value to be auto-computed by the solver. |
max_solution_radius | For SHORTEST_PATH, INVERSE_SHORTEST_PATH, & ALLPATHS solvers only. Sets the maximum solution cost radius, which ignores the DESTINATION_NODES list and instead outputs the nodes within the radius sorted by ascending cost. If set to 0.0 (the default), the setting is ignored. |
max_solution_targets | For SHORTEST_PATH, INVERSE_SHORTEST_PATH, & ALLPATHS solvers only. Sets the maximum number of solution targets, which ignores the DESTINATION_NODES list and instead outputs no more than n number of nodes sorted by ascending cost where n is equal to the setting value. If set to 0 (the default), the setting is ignored. |
min_solution_radius | For SHORTEST_PATH, INVERSE_SHORTEST_PATH, & ALLPATHS solvers only. Applicable when max_solution_radius is set. Sets the minimum solution cost radius, which ignores the DESTINATION_NODES list and instead outputs the nodes within the radius sorted by ascending cost. If set to 0.0 (the default), the setting is ignored. |
num_best_paths | For MULTIPLE_ROUTING solver only. Sets the number of shortest paths computed from each node. This is the heuristic criterion. If set to 0 (the default), the number will be determined automatically by the solver. Users may want to override this parameter to speed up the solver. |
output_clusters | For STATS_ALL solver only; the cluster index for each node will be inserted as an additional column in the output. |
output_edge_path | If set to true, concatenated edge IDs will be added as an EDGE_PATH column to the solution table for each source and target pair in the SHORTEST_PATH solves. The default value is false |
output_wkt_path | If set to true, WKT line segments will be added as a WKTROUTE column to the solution table for each source and target pair in SHORTEST_PATH solves. The default value is false. |
right_turn_penalty | This will add an additional weight over the edges labeled as right_turn if the add_turn option was invoked during graph creation. The default value is 0.0. |
server_id | Indicates which graph server(s) to send the request to. Default is to send to the server, amongst those containing the corresponding graph, that has the most computational bandwidth. For SHORTEST_PATH solver, the input is split among the server containing the corresponding graph. |
sharp_turn_penalty | This will add an additional weight over the edges labeled as sharp_turn or u_turn if the add_turn option was invoked during graph creation. The default value is 0.0. |
solve_heuristic | The heuristic search criterion to use, only for geo graphs and SHORTEST_PATH solves towards a single target. Specify astar to use an A-STAR heuristic. The default value is none. |
uniform_weights | When specified, assigns the given value to all the edges in the graph. Note that weights provided using weights_on_edges will override this value. |
Examples
Using theEXECUTE FUNCTION syntax necessitates the SOLUTION_TABLE
parameter to store the solve results, where using the table function syntax will
return the results directly.
CREATE GRAPH
Creates a new graph. The nodes and edges of a graph are optionally weighted and/or restricted to aid in calculating various ways to traverse the graph. Graphs comprise a maximum of four components that each have unique specifications and ways they can be combined to define the graph. Review Components and Identifiers and Identifier Combinations for more information.CREATE GRAPH Syntax
Parameters
OR REPLACE
OR REPLACE
Any existing graph with the same name will be dropped before creating this one
DIRECTED
DIRECTED
Optional keyword used to create the graph as directed
<schema name>
<schema name>
Name of the schema that will contain the created graph; if no schema is specified, the graph will be
created in the calling user’s default schema
<graph name>
<graph name>
Name of the graph, which can be referenced in subsequent commands
EDGES
EDGES
Graph component, provided as table column names, expressions, or constants using the SQL
INPUT_TABLE or
INPUT_TABLES function, to use for identifying the edges of the graph; review Components and Identifiers and
Identifier Combinations for more informationThe input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
NODES
NODES
Optional graph component, provided as column names, expressions, or constants using the SQL
INPUT_TABLE or
INPUT_TABLES function, to use for identifying the nodes of the graph; review Components and Identifiers and
Identifier Combinations for more informationThe input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
WEIGHTS
WEIGHTS
Optional graph component, provided as column names, expressions, or constants using the SQL
INPUT_TABLE or
INPUT_TABLES function, to use for identifying the weights of the graph; review Components and Identifiers and
Identifier Combinations for more informationThe input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
RESTRICTIONS
RESTRICTIONS
Optional graph component, provided as column names, expressions, or constants using the SQL
INPUT_TABLE or
INPUT_TABLES function, to use for identifying the restrictions of the graph; review
Components and Identifiers and Identifier Combinations for more informationThe input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
OPTIONS
OPTIONS
Optional indicator that a list of connection option/value assignments will follow, passed as a comma-delimited
list of key/value pairs to the
KV_PAIRS function| Option | Description |
|---|---|
add_table_monitor | Adds a table monitor to every table used in the creation of the graph; this table monitor will trigger the graph to update dynamically upon inserts to the source table(s). Note that upon database restart, if save_persist is also set to true, the graph will be fully reconstructed and the table monitors will be reattached. For more details on table monitors, see Table Monitors. The default value is false. |
add_turns | Adds dummy “pillowed” edges around intersection nodes where there are more than three edges so that additional weight penalties can be imposed by the solve endpoints (increases the total number of edges). The default value is false. |
allow_multiple_edges | Enables multigraph capability—pairs of nodes can be connected by more than one edge. Without this option, undirected graphs can only have one edge between each pair of nodes, and directed graphs can have one edge in each direction between each pair of nodes—“duplicate” edges are discarded. |
cluster_graph_schema | If export_graph_schema is true, outputs the graph’s schema into a table named <graph_name>_clusters |
export_graph_schema | Exports a graph’s schema in Graphviz DOT format. The schema is a conversion of the graph into a label-based ontology, done by grouping the nodes using the Louvain clustering algorithm. This schema is made available in two ways:
|
graph_table | If specified, the created graph is also created as a table with the given name, in [schema_name.]table_name format, using standard name resolution rules and meeting table naming criteria. The table will have the following identifier columns: EDGE_ID, EDGE_NODE1_ID, EDGE_NODE2_ID. If left blank, no table is created. The default value is blank. |
is_partitioned | If set to true, the graph will be partitioned across the servers specified in server_id; if false, the graph will be replicated across those servers. The default value is false. |
label_delimiter | If specified, the delimiter to use when parsing edge labels. All labels separated by this delimiter will be applied to the corresponding edge. |
merge_tolerance | If node geospatial positions are input (e.g., POINT(X Y)), determines the minimum separation allowed between unique nodes. If nodes are within the tolerance of each other, they will be merged as a single node. The default value is 1.0E-5. |
recreate | If set to true and the graph already exists, the graph is deleted and recreated. The default value is false. |
save_persist | If set to true, the graph will be saved in the persist directory (see the config reference for more information). If set to false, the graph will be removed when the graph server is shutdown. The default value is false. |
schema_edge_labelkeys | If export_graph_schema is true, generates the label-based schema by collapsing edges based on the their label keys; otherwise, schema edges are created from the edge labels. |
schema_node_labelkeys | If export_graph_schema is true, generates the label-based schema by collapsing nodes based on the their label keys; otherwise, schema nodes are created from the node labels. |
server_id | Indicates on which graph server(s) to create the graph. Default is to create on the server with the most available memory. Can be a single server ID, a comma-separated list of IDs, or all for all servers. |
simplify | Simplifies the graph topology at 2-valence by collapsing edge. |
use_rtree | Use a range tree structure to accelerate and improve the accuracy of snapping, especially to edges. |
Examples
ALTER GRAPH
Alters an existing graph.ALTER GRAPH Syntax
Parameters
<schema name>
<schema name>
Name of the schema containing the graph to alter
<graph name>
<graph name>
Name of the graph to alter
EDGES
EDGES
Graph component, provided as column names, expressions, or constants using the SQL
INPUT_TABLE or
INPUT_TABLES function, to use for identifying the edges of the graph; review Components and Identifiers and
Identifier Combinations for more informationThe input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
NODES
NODES
Graph component, provided as column names, expressions, or constants using the SQL
INPUT_TABLE or
INPUT_TABLES function, to use for identifying the nodes of the graph; review Components and Identifiers and
Identifier Combinations for more informationThe input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
WEIGHTS
WEIGHTS
Graph component, provided as column names, expressions, or constants using the SQL
INPUT_TABLE or
INPUT_TABLES function, to use for identifying the weights of the graph; review Components and Identifiers and
Identifier Combinations for more informationThe input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
RESTRICTIONS
RESTRICTIONS
Graph component, provided as column names, expressions, or constants using the SQL
INPUT_TABLE or
INPUT_TABLES function, to use for identifying the restrictions of the graph; review
Components and Identifiers and Identifier Combinations for more informationThe input can be either the name of a table with appropriately named columns; or a query, to use
specific columns or other SQL features).
OPTIONS
OPTIONS
Indicator that a list of connection option/value assignments will follow, passed as a comma-delimited
list of key/value pairs to the
KV_PAIRS function| Option | Description |
|---|---|
add_table_monitor | Adds a table monitor to every table used in the creation of the graph; this table monitor will trigger the graph to update dynamically upon inserts to the source table(s). Note that upon database restart, if save_persist is also set to true, the graph will be fully reconstructed and the table monitors will be reattached. For more details on table monitors, see Table Monitors. The default value is false. |
add_turns | Adds dummy “pillowed” edges around intersection nodes where there are more than three edges so that additional weight penalties can be imposed by the solve endpoints (increases the total number of edges). The default value is false. |
allow_multiple_edges | Enables multigraph capability—pairs of nodes can be connected by more than one edge. Without this option, undirected graphs can only have one edge between each pair of nodes, and directed graphs can have one edge in each direction between each pair of nodes—“duplicate” edges are discarded. The default value is true. |
cluster_graph_schema | If export_graph_schema is true, groups nodes based on the Louvain clustering algorithm, converting the graph into a label-based schema. |
export_graph_schema | Exports a graph’s schema in Graphviz DOT format; this is made available in two ways:
|
graph_table | The graph is created as a table with the given name, in [schema_name.]table_name format, using standard name resolution rules and meeting table naming criteria. The table will have the following identifier columns: EDGE_ID, EDGE_NODE1_ID, EDGE_NODE2_ID. |
label_delimiter | If specified, the delimiter to use when parsing edge labels. All labels separated by this delimiter will be applied to the corresponding edge. |
save_persist | If set to true, the graph will be saved in the persist directory (see the config reference for more information). If set to false, the graph will be removed when the graph server is shutdown. The default value is false. |
schema_edge_labelkeys | If export_graph_schema is true, generates the label-based schema by collapsing edges based on the their label keys; otherwise, schema edges are created from the edge labels. |
schema_node_labelkeys | If export_graph_schema is true, generates the label-based schema by collapsing nodes based on the their label keys; otherwise, schema nodes are created from the node labels. |
simplify | Simplifies the graph topology at 2-valence by collapsing edge. |
use_rtree | Use a range tree structure to accelerate and improve the accuracy of snapping, especially to edges. |
Examples
To alter the weights of a graph and allow it to survive a database restart:ALTER GRAPH Example
DROP GRAPH
Removes an existing graph.DROP GRAPH Syntax
Parameters
<schema name>
<schema name>
Name of the schema containing the graph to remove
<graph name>
<graph name>
Name of the existing graph to drop.
Examples
To drop a graph,big_cities_graph:
DROP GRAPH Example
SHOW GRAPH
Outputs the request used to create one or more existing graphs.Parameters
<schema name>
<schema name>
Name of the schema containing the graph(s) to show
<graph name>
<graph name>
Name of the existing graph for which the creation request will be output
The response to
SHOW GRAPH is a single-column result set
with the creation request in the DDL column. The request shown will
depend on the way in which the graph was created (SQL vs. API/REST):- SQL - output will be the SQL DDL statement used to create the graph
- API/REST - output will be the JSON request, wrapped by the API or sent directly via REST, used to create the graph
Examples
To output the creation request for a graph,big_cities_graph:
SHOW GRAPH Example
DESCRIBE GRAPH
Outputs the configuration of one or more existing graphs.Parameters
<schema name>
<schema name>
Name of the schema containing the graph(s) to describe
<graph name>
<graph name>
Name of the existing graph for which the configuration will be output
Response
The response toDESCRIBE GRAPH is a multi-column result set.
| Output Column | Description |
|---|---|
GRAPH_NAME | Name of the graph |
GRAPH_SERVER_ID | ID of the server on which the graph is hosted |
DIRECTED | Whether the edges of the graph have directionality or are bidirectional |
NUM_NODES | Number of nodes in the graph |
NUM_EDGES | Number of edges in the graph |
NUM_BYTES | Bytes of memory used by the graph |
IS_PERSISTED | Whether the graph will survive a database restart or not |
IS_SYNC_DB | Whether the graph is recreated from its source tables upon database startup |
GRAPH_OWNER_USER_NAME | Name of user who created the graph |
GRAPH_OWNER_RESOURCE_GROUP | Resource group for the graph; the effective resource group of the graph creator at the time it was created |
RESOURCE_CAPACITY | Allocated memory limit for this graph |
IS_PARTITIONED | Whether the graph is distributed across the available graph servers |
HAS_INSERT_TABLE_MONITOR | Whether the graph has an associated insert table monitor or not |
ORIGINAL_REQUEST | Request used to create the graph, similar to what is returned by SHOW GRAPH |
Examples
To show the configuration for a graph,big_cities_graph:
DESCRIBE GRAPH Example