Kinetica provides support for graph creation and management in SQL. Graphs represent topological relationships (both geospatial and non-geospatial) via nodes that are connected by edges.
Graph features accessible via SQL include:
- Query
- Solve
- Management
GraphQL
GraphQL 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 | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| <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> | Name of the graph to query | ||||||||||||||||||||||||||||||||||||
| <match expr> | Any supported Cypher MATCH expression. For example, to query for relationships with the following criteria:
use this MATCH expression: (js:User:Admin {first_name: 'Joe', last_name: 'Smith'})-[]->(:User)
Individual labels, property names, and column names can be double-quoted if needed to avoid conflicts with the Cypher query syntax: (n:"SYSTEM ADMIN":"BUSINESS ANALYST" {"last name": 'Smith'})
| ||||||||||||||||||||||||||||||||||||
| <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> | 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 expression(s) to apply to the result set. Columns referenced do not have to be present in the RETURN clause. | ||||||||||||||||||||||||||||||||||||
| <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:
| |
To query for employees who have had the employee with ID #2 as their manager for three years or more:
| |
To query for employees who work with each other but have different managers:
| |
To query with variable hops to find all managers in the management chain for employee with ID #14 (or at most, 10 levels of managers above the employee):
| |
To use a GraphQL query as a subquery, joining the result with another table:
| |
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_NULLABLE function can be used to make the value NOT NULL
- Graph should be created with Node & edge INPUT_TABLES as 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 GraphQL queries overall.
- Graph should be created with the add_table_monitor option 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 GraphQL 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. The QUERY_GRAPH function can be called either within a SELECT statement as a table function or within an EXECUTE FUNCTION call.
| |
| |
| Parameter | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| GRAPH | Name of the graph to query | ||||||||||||||||||
| 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. Note 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 | 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>_nodes Important Only applicable when using the EXECUTE FUNCTION syntax | ||||||||||||||||||
| RINGS | Sets the number of rings around (hops from) the queried node(s) to return matching edges & nodes Important Only applicable when querying on nodes; e.g., giving NODE_NAME or NODE_LABEL | ||||||||||||||||||
| 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. Note 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). Important Only applicable when querying on nodes; e.g., giving NODE_NAME or NODE_LABEL | ||||||||||||||||||
| OPTIONS | Optional indicator that a comma-delimited list of connection option/value assignments will follow.
|
Examples
Using the EXECUTE 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 a HOP_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 acted edges 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 -2 for the HOP_ID allows one-way edges to be traversed in reverse--the directed edge 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 -2 designation for the 2nd hop to follow those edges in reverse
Since hop-based queries return all edges along the path, the query ends by filtering the James Spader node out of the result set.
| |
Querying for Commonalities
Queries can make use of the find_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:
| |
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:
| |
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. The MATCH_GRAPH function can be called either within a SELECT statement as a table function or within an EXECUTE FUNCTION call.
| |
| |
| Parameter | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| GRAPH | Name of the graph to match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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. Note 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 | The type of solve method to use for the operation; review Match Identifier Combinations for more information.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 criteria | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OPTIONS | Optional indicator that a comma-delimited list of connection option/value assignments will follow.
|
Examples
Using the EXECUTE 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. The SOLVE GRAPH function can be called either within a SELECT statement as a table function or within an EXECUTE FUNCTION call.
| |
| |
| Parameter | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| GRAPH | Name of the graph to solve | ||||||||||||||||||||||||||||||||||||||||
| SOLVER_TYPE | The type of solver to use for the operation.
| ||||||||||||||||||||||||||||||||||||||||
| SOURCE_NODES | The node(s) used as the origin point(s) for the solution specified using the SQL INPUT_TABLE or INPUT_TABLES function. Note 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 | 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 criteria | ||||||||||||||||||||||||||||||||||||||||
| DESTINATION_NODES | The node(s) used as the destination point(s) for the solution specified using the SQL INPUT_TABLE or INPUT_TABLES function. Note 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 | 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. Note 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 | 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. Note 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 | Optional indicator that a comma-delimited list of connection option/value assignments will follow.
|
Examples
Using the EXECUTE 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.
| |
| Parameter | Description | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OR REPLACE | Any existing graph with the same name will be dropped before creating this one | ||||||||||||||||||||||||||||||||||
| DIRECTED | Optional keyword used to create the graph as directed | ||||||||||||||||||||||||||||||||||
| <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> | Name of the graph, which can be referenced in subsequent commands | ||||||||||||||||||||||||||||||||||
| 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 information Note 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). | ||||||||||||||||||||||||||||||||||
| 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 information Note 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 | 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 information Note 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 | 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 information Note 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 | 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
|
Examples
| |
| |
| |
| |
ALTER GRAPH
Alters an existing graph.
| |
| Parameter | Description | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| <schema name> | Name of the schema containing the graph to alter | ||||||||||||||||||||||||||
| <graph name> | Name of the graph to alter | ||||||||||||||||||||||||||
| 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 information Note 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). | ||||||||||||||||||||||||||
| 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 information Note 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 | 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 information Note 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 | 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 information Note 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 | 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
|
To alter the weights of a graph and allow it to survive a database restart:
| |
DROP GRAPH
Removes an existing graph.
| |
| Parameter | Description |
|---|---|
| <schema name> | Name of the schema containing the graph to remove |
| <graph name> | Name of the existing graph to drop. |
To drop a graph, big_cities_graph:
| |
SHOW GRAPH
Outputs the request used to create one or more existing graphs.
| |
| |
| |
| Parameter | Description |
|---|---|
| <schema name> | Name of the schema containing the graph(s) to show |
| <graph name> | Name of the existing graph for which the creation request will be output |
Note
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
For example, to output the creation request for a graph, big_cities_graph:
| |
DESCRIBE GRAPH
Outputs the configuration of one or more existing graphs.
| |
| |
| |
| Parameter | Description |
|---|---|
| <schema name> | Name of the schema containing the graph(s) to describe |
| <graph name> | Name of the existing graph for which the configuration will be output |
The response to DESCRIBE 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 |
To show the configuration for a graph, big_cities_graph:
| |