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. Querying

CALL

Overview

The CALL statement invokes subqueries, each executed with one record from the imported aliases as input. These subqueries enhance efficiency by managing resources more effectively, particularly when working with large datasets, thereby reducing memory overhead.

Syntax

Syntax
call {
  with <alias_in_1>, <alias_in_2?>, ...
  ...
  return <item1> as <alias_out_1?>, <item2?> as <alias_out_2?>, ...
}

Details

  • The subquery in CALL begins with a WITH to import aliases and concludes with a RETURN to deliver results which are available in the subsequent parts of the query.
  • When the initial WITH statement is omitted, all available aliases from the previous parts of the query are implicitly imported, and any heterologous aliases are combined using a Cartesian product.

Example Graph

To create the graph, execute each of the following UQL queries sequentially in an empty graphset:

UQL
create().node_schema("User").node_schema("Club").edge_schema("Follows").edge_schema("Joins")
create().node_property(@User, "name").edge_property(@Joins, "rates", float)
insert().into(@User).nodes([{_id:"U01", name:"rowlock"},{_id:"U02", name:"Brainy"},{_id:"U03", name:"purplechalk"},{_id:"U04", name:"mochaeach"},{_id:"U05", name:"lionbower"}])
insert().into(@Club).nodes([{_id:"C01"},{_id:"C02"}])
insert().into(@Follows).edges([{_from:"U01", _to:"U02"},{_from:"U02", _to:"U03"},{_from:"U04", _to:"U02"},{_from:"U05", _to:"U03"}])
insert().into(@Joins).edges([{_from:"U02", _to:"C01"},{_from:"U05", _to:"C01"},{_from:"U02", _to:"C02"},{_from:"U04", _to:"C02"}])

Queries

To find the clubs joined by each user:

UQL
find().nodes({@User}) as u
call {
  with u
  n(u).e({@Joins}).n({@Club} as c)
  return c{*}
}
return u.name, c._id

Result:

u.namec._id
mochaeachC02
BrainyC01
BrainyC02
lionbowerC01

Aggregations

To count the number of followers for each user who joins a club:

UQL
n({@User} as u).e({@Joins}).n({@Club} as c)
call {
  with u
  n(u).le({@Follows}).n(as follower)
  return count(follower) as followersNo
}
return u.name, c._id, followersNo

Result:

u.namec._idfollowersNo
mochaeachC020
BrainyC012
BrainyC022
lionbowerC010

Data Modifications

To set values for the property rates of @Joins edges:

UQL
uncollect [1,2,3,4] as score
call {
  with score
  find().edges({@Joins.rates is null}) as e1 limit 1
  update().edges(e1).set({rates: score}) as e2
  return e2{*}
}
return e2{*}

Result: e2

_uuid
_from
_to
_from_uuid
_to_uuid
schema
values
Sys-genU04C02UUID of U04UUID of C02Joins{rates: 1}
Sys-genU02C01UUID of U02UUID of C01Joins{rates: 2}
Sys-genU02C02UUID of U02UUID of C02Joins{rates: 3}
Sys-genU05C01UUID of U05UUID of C01Joins{rates: 4}

Importing Multiple Aliases

To check if any two users connected by a @Follows edge have joined the same club:

UQL
n({@User} as u1).le({@Follows}).n({@User} as u2)
call {
  with u1, u2
  optional n(u1).e().n({@Club}).e().n({_id == u2._id}) as p
  return p
}
return u1.name, u2.name,
       case when p is not null then "Y"
       else "N" end as sameClub

Result:

u1.nameu2.namesameClub
BrainyrowlockN
BrainymochaeachY
purplechalkBrainyN
purplechalklionbowerN

Execution Order of Subqueries

The execution order of a subquery is not fixed. If a specific execution order is desired, the ORDER BY statement should be used before CALL to enforce that sequence.

This query counts the number of followers for each user. The execution order of the subqueries is determined by the ascending order of the users' names:

UQL
find().nodes({@User}) as u
order by u.name
call {
  with u
  n(u).le({@Follows}).n(as follower)
  return count(follower) as followersNo
}
return u.name, followersNo

Result:

u.namefollowersNo
Brainy2
lionbower0
mochaeach0
purplechalk2
rowlock0