WALEED SHAHID

Posted on

Blog Post 1: Scalar Functions in Apache Age

Scalar functions play an essential role in Apache Age, providing various capabilities to manipulate and retrieve data efficiently. In this blog post, we will explore some commonly used scalar functions in Apache Age and understand their syntax, arguments, and usage.

1. id()

The id() function returns the id of a vertex or edge. It takes an expression that returns a vertex or edge as an argument and returns an agtype integer representing the id.

Syntax: id(expression)

Consider the following query:

``````SELECT *
FROM cypher('graph_name', \$\$
MATCH (a)
RETURN id(a)
\$\$) as (id agtype);
``````

Results:

`````` id
----
1
2
3
``````

The query retrieves the id of all vertices in the graph and returns the results as an agtype integer.

2. start_id()

The start_id() function returns the id of the vertex that is the starting vertex for the edge. It takes an expression that evaluates to an edge as an argument and returns an agtype integer representing the start id.

Syntax: start_id(expression)

Consider the following query:

``````SELECT *
FROM cypher('graph_name', \$\$
MATCH ()-[e]->()
RETURN start_id(e)
\$\$) as (start_id agtype);
``````

Results:

`````` start_id
----------
1
2
1
``````

The query retrieves the start ids of all edges in the graph and returns the results as agtype integers.

3. end_id()

The end_id() function returns the id of the vertex that is the ending vertex for the edge. It takes an expression that evaluates to an edge as an argument and returns an agtype integer representing the end id.

Syntax: end_id(expression)

Consider the following query:

``````SELECT *
FROM cypher('graph_name', \$\$
MATCH ()-[e]->()
RETURN end_id(e)
\$\$) as (end_id agtype);
``````

Results:

`````` end_id
--------
2
3
4
``````

The query retrieves the end ids of all edges in the graph and returns the results as agtype integers.

These scalar functions provide valuable insights into the graph structure by extracting specific information about vertices and edges. They serve as building blocks for more complex graph queries and analytics tasks in Apache Age.

Stay tuned for the next blog post, where we will explore more scalar functions in Apache Age!