A UQL statement is structured and delivered to the Ultipa server, then parsed and optimized before being allocated to the high-performance graph computing engine for graph query. The query result is processed and assembled, and finally returned to user.
This chapter will introduce the query, alias and return mechanism of UQL as a whole, with the purpose of giving a general picture. If user has doubts while reading, please continue to study the following chapters for detailed introduction to each section.
UQL Components
Check an UQL example:
find().nodes() as target
return target.name, target.age limit 10
where:
- find().nodes() initiates a query of node;
- as target defines an alias, the query result of the previous sentence is expressed as alias target;
- return target.name, target.age assembles two values to return to user;
- limit 10 sets the limit of the amount of data to return, here is 10 the maximum.
The green part find().nodes() is the UQL chain query styled as [command].[parameter].[parameter]...
, a complex UQL sentence may contain multiple query statements, and the result of query serves as the input and processing source of subsequent statements. Later in this chapter, the concept and usage of various query commands and their parameters will be introduced in turn.
The orange part return and limit are clause keyword. Clause is used to compute and process the result delivered from the previous statements (functional operation, aggregation, sorting, Cartesian product combination, etc.). Read chapter Data Stream | Clause for a detailed description of clause keyword.
The red part as is the alias keyword that defines alias for the current result so that it can be used in subsequent statements. Alias is link that makes various parts of UQL to work together.
Prefix
Prefix keyword is used at the beginning of a chain query statement or the whole UQL to help enhance the query function or realize operational functions other than query. Below prefixes are supported:
Prefix Keyword | Explanation |
Scope |
---|---|---|
OPTIONAL | Execute current chain query and verify the result of each sub-query. For any sub-query that finds no query result, return a pseudo node/edge/path (see examples of each query command) | Current chain query statement |
EXPLAIN | Analyze and return the operation logic between each chain query and clause without executing the UQL. | The whole UQL statement |
PROFILE | Execute the UQL, return the operation logic between each chain query and clause, as well as and their time_cost. | The whole UQL statement |
DEBUG | Execute the UQL, return the call_time and time_cost of each execution phase | The whole UQL statement |
EXEC TASK | Execute the UQL by sending it to the analytic server (see Task - Analytics Server for detail) | The whole UQL statement |
Prefix keywords are all case insensitive.
- EXPLAIN:
explain n({@movie} as movies).e({@filmedIn}).n({@country.name == "US"}) as paths
group by movies.genre
return movies.genre, count(movies)
- PROFILE:
profile n({@movie} as movies).e({@filmedIn}).n({@country.name == "US"}) as paths
group by movies.genre
return movies.genre, count(movies)
- DEBUG:
debug n({@movie} as movies).e({@filmedIn}).n({@country.name == "US"}) as paths
group by movies.genre
return movies.genre, count(movies)