UltipaDocs
Try Playground
  • Introduction
  • Terminologies
    • Graphset
    • Schema
    • Property
    • Constraints
    • Insert
    • Overwrite or Insert
    • Upsert
    • Update
    • Delete
    • Find Nodes
    • Find Edges
      • AB
      • Autonet
      • Spread
      • Path Template
      • K-Hop
      • K-Hop Template
    • GROUP BY
    • ORDER BY
    • SKIP
    • LIMIT
    • WHERE
    • RETURN
    • WITH
    • UNCOLLECT
    • UNION
    • UNION ALL
    • CALL
    • All Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Table Functions
    • Null Functions
    • Type Conversion Functions
  • Operators
  • Expressions
    • Index
    • Full-text Index
    • Vector Index
    • Cache
    • Overview
    • Managing HDC Graphs
    • HDC Graph Queries
    • Process
    • Job
    • Execution Plan
    • Alias
    • Filter
    • Values and Types
    • Data Flow in Queries
    • Comments
    • Reserved Words
  • Access Control
  1. Docs
  2. /
  3. UQL
  4. /
  5. HDC Graphs

HDC Graph Queries

Overview

To execute a query on an HDC graph, use the syntax:

Syntax
exec{
  <query>
} on <hdcGraphName>

HDC graphs support queries that retrieve data from the database with enhanced efficiency, but do not allow operations that modify the graph structure or data.

Example Graph

Run the following statements on an empty graph to define its structure and insert data:

UQL
create().node_schema("entity").edge_schema("link");
create().edge_property(@link, "weight", float);
insert().into(@entity).nodes([{_id:"A"},{_id:"B"},{_id:"C"},{_id:"D"}]);
insert().into(@link).edges([{_from:"A", _to:"B", weight:1},{_from:"A", _to:"C", weight:1.5},{_from:"A", _to:"D", weight:0.5},{_from:"B", _to:"C", weight:2},{_from:"C", _to:"D", weight:0.5}]);

Queries on HDC Graphs

To create an HDC graph hdcGraph of the entire graph:

UQL
hdc.graph.create("hdcGraph", {
  nodes: {"*": ["*"]},
  edges: {"*": ["*"]},
  direction: "undirected",
  load_id: true,
  update: "static"
}).to("hdc-server-1")

To run a query on hdcGraph:

UQL
exec{
  n({_id == "A"}).e()[2].n({_id == "C"}) as p
  return p{*}
} on hdcGraph

Result: p

Limited Graph Traversal Direction

If an HDC graph is created with the direction option set to in or out, graph traversal is restricted to incoming or outgoing edges, respectively. Queries attempting to traverse in the missing direction throw errors or yield empty results.

To create an HDC graph hdcGraph_in_edges of the graph with nodes and incoming edges:

UQL
hdc.graph.create("hdcGraph_in_edges", {
  nodes: {"*": ["*"]},
  edges: {"*": ["*"]},
  direction: "in",
  load_id: true,
  update: "static"
}).to("hdc-server-1")

This query attempts to traverse the outgoing edges from node A on hdcGraph_in_edges, but no result will be returned:

UQL
exec{
  n({_id == "A"}).re().n() as p
  return p{*}
} on hdcGraph_in_edges

Exclusion of Node IDs

If an HDC graph is created with the load_id option set to false, it does not contain the _id values for nodes. Queries referencing _id throw errors or yield empty results.

To create an HDC graph hdcGraph_no_id of the graph without nodes' _id values:

UQL
hdc.graph.create("hdcGraph_no_id", {
  nodes: {"*": ["*"]},
  edges: {"*": ["*"]},
  direction: "undirected",
  load_id: false,
  update: "static"
}).to("hdc-server-1")

This query utilizes _id to filter nodes on hdcGraph_no_id, error occurs as the HDC graph lacks nodes' _id:

UQL
exec{
  n({_id == "A"}).e()[2].n({_id == "C"}) as p
  return p{*}
} on hdcGraph_no_id

Exclusion of Properties

If an HDC graph is created without certain properties, queries referencing these properties throw errors or yield empty results.

To create an HDC graph hdcGraph_no_weight of the graph, which includes all node properties but only the system properties of link edges:

UQL
hdc.graph.create("hdcGraph_no_weight", {
  nodes: {"*": ["*"]},
  edges: {"link": []},
  direction: "undirected",
  load_id: true,
  update: "static"
}).to("hdc-server-1")

This query finds the shortest path between two nodes on hdcGraph_no_weight, weighted by the edge property @link.weight. An error occurs because the weight property is missing:

UQL
exec{
  ab().src({_id == "A"}).dest({_id == "C"}).depth(2).shortest(@link.weight) as p
  return p
} on hdcGraph_no_weight