Composite Data Types is used to store multiple logically related items of Simple Data Types in Apache AGE. This includes Lists and Maps.
List
It is a collection of ordered items. This is similar to list in python.
# query to create a list
SELECT *
FROM cypher('graph', $$
WITH [0, 1, 2, 3, 4, 5] as lis
RETURN lis
$$) AS (lis agtype);
To access an individual element in the list we can use square brackets
like all most other programming languages like C/C++, Python.
# query to create a list
SELECT *
FROM cypher('graph', $$
WITH [0, 1, 2, 3, 4, 5] as lis
RETURN lis[2]
$$) AS (val agtype);
A list can store elements of all Simple Data Types as well as Composite type like list and map.
It can use negative index, which will start counting from the end and index ranges which returns the elements in the given range.
SELECT *
FROM cypher('graph', $$
WITH [0, 1, 2, 3, 4, 5] as lis
RETURN lis[0..3]
$$) AS (val agtype);
Map
A map is a collection of elements where each element is stored as a key-value pair. It is like maps in python.
It can use any data type (Simple or Composite) as key or as value, as shown in the example.
SELECT *
FROM cypher('graph', $$
WITH {int_key: 1, float_key: 1.0, numeric_key: 1::numeric, bool_key: true, string_key: 'Value'} as m
RETURN m
$$) AS (m agtype);
SELECT *
FROM cypher('graph', $$
WITH {int_key: 1, float_key: 1.0, numeric_key: 1::numeric, bool_key: true, string_key: 'Value'} as m
RETURN m
$$) AS (m agtype);
To access the value for a key we can use the dot (.) convention as in the example.
SELECT *
FROM cypher('graph', $$
WITH {int_key: 1, float_key: 1.0, numeric_key: 1::numeric, bool_key: true, string_key: 'Value'} as m
RETURN m.int_key
$$) AS (int_key agtype);
Top comments (0)