1

It is mentioned as a feature of Apache AGE that it simultaneously performs the queries for relational data and graph data.

I went through Apache AGE Website and seen this as a feature on Apache-AGE that it is Hybrid query technology which simultaneously performs the queries for relational data and graph data.

Can anyone explain and gives some insights on this feature of Apache AGE?

1 Answers1

3

Hybrid querying is basically a form of using both SQL and Cypher within a single query. I'll illustrate by example:

Suppose we have a graph database in AGE that has a few 'person' nodes with some generic properties (name, age, etc). The Cypher query to display all these nodes would look something like this:

MATCH (p:person)
RETURN p

To replicate this in AGE, we would write the following query:

SELECT *
FROM cypher('graph_name',
$$
    MATCH (p:person)
    RETURN p
$$
) as (p agtype);

This will return us all the nodes in the graph with the label of 'person', with all of their properties. Now imagine that you only want to retrieve the name and age of each person. So rewriting our query, we get:

SELECT *
FROM cypher('graph_name',
$$
    MATCH (p:person)
    RETURN p.name, p.age
$$
) as (name agtype, age agtype);

The results look something like this:

   name    | age 
-----------+-----
 "Alice"   | 38
 "Charlie" | 53
 "Daniel"  | 54
 "Bob"     | 25
 "Eskil"   | 41
           | 61
           | 

Notice that the cypher() function call basically returned a relational table consisting of 2 columns to the FROM clause. Now we can perform regular SQL operations on this table. For example, we could filter out all rows that are older than 50 years and then display the result in ascending order.

SELECT * 
FROM cypher('isEmpty_test',
$$
    MATCH (person)
    RETURN person.name, person.age 
$$               
) as (name agtype, age agtype)
WHERE age < 50
ORDER BY age;

The results:

  name   | age 
---------+-----
 "Bob"   | 25
 "Alice" | 38
 "Eskil" | 41
(3 rows)
moeed865
  • 304
  • 1
  • 6