14.2 Data Types and Collections in the Graph Server (PGX)
This guide provides you the list of the supported data types and collections in the graph server (PGX).
Primitive Data Types
The following section explains the primitive data types supported by the graph server (PGX) and their limitations.
PGX supports the following primitive data types.:
- Numeric Types:
integer
,long
,float
, anddouble
. These types have the same size, range and precision of the corresponding Java primitive data type. - Boolean Type: The
boolean
data type has only two possible values,true
andfalse
. As with Java and C++, its size is not precisely defined. - String:
String
is a primitive data type in PGX. PGX follows the Java conventions for String representation. - Datetime Types:
date
,time
,timestamp
,time with time zone
, andtimestamp with time zone
. These types correspond to the Java types shown in Table 14-2 from the standard library packagejava.util.time
. - Vertex and Edge: The type
vertex
oredge
of the graph itself is a proper type in PGX.
Note:
vertex
andedge
is itself a valid primitive data type. For instance, in a path-finding algorithm, eachvertex
can have a temporary propertypredecessor
that stores which incoming neighbor is the predecessor vertex in the path. Such a property would have the typevertex
.local_date
must be used instead ofdate
in the graph configuration file. See Using Datetime Data Types for more examples on usage of datetime data types.
All properties and scalar variables must be one of the above preceding data types. See Managing Transient Data for more information on handling transient properties and scalar variables.
The following table presents the overview of the supported data types, their integration in different languages and APIs and their minimum and maximum value limitations.
Note:
- For float and double types, the smallest absolute value is included in the table, the minimum value is the negative of maximum value for these types.
- For string values, PGX supports arbitrary long strings.
Table 14-2 Overview of Data types
Data Type | Loading & Storing | PGX Java API | PGQL and Filter Expression | Minimum Value Limitation | Maximum Value Limitation |
---|---|---|---|---|---|
string |
string |
String |
STRING |
- |
- |
int/integer |
int/integer |
int |
INT/INTEGER |
-2147483648 |
2147483647 |
long |
long |
long |
LONG |
-9223372036854775808 |
-9223372036854775807 |
float |
float |
float |
FLOAT |
1.4E-45 |
3.4028235e+38 |
double |
double |
double |
DOUBLE |
4.9E-324 |
1.7976931348623157E308 |
boolean |
boolean |
boolean |
BOOLEAN |
- |
- |
date |
local_date |
LocalDate |
DATE |
-5877641-06-23 |
5881580-07-11 |
time |
time |
LocalTime |
TIME |
00:00:00.000 |
23:59:59.999 |
timestamp |
timestamp |
LocalDateTime |
TIMESTAMP |
-292275055-05-17 00:00:00.000 |
292278994-08-17 07:12:55.807 |
time with time zone |
time_with_timezone |
OffsetTime |
TIME WITH TIME ZONE |
00:00:00.000+18:00 |
23:59:59.999-18:00 |
timestamp with time zone |
timestamp_with_timezone |
OffsetDateTime |
TIMESTAMP WITH TIME ZONE |
-292275055-05-17 00:00:00.000+18:00 |
292278994-08-17 07:12:55.807-18:00 |
vertex |
- |
PgxVertex |
- |
- |
- |
edge |
- |
PgxEdge |
- |
- |
- |
Collections
The graph server (PGX) supports three different collection types: sequence,
set and order
. All of these collections can contain values of the
vertex
type, but each has different semantics regarding
uniqueness and preserving the order of its elements:
- Sequence: a
sequence
works basically like a list. It preserves the order of the elements added to it, and the same element can appear multiple times. - Set: a
set
can contain the same value once at the most. Adding a value that is already in theset
will have no effect.set
does not preserve the order of the elements it contains. - Order: just like the
set
, theorder
collection will contain each element once at the most. But theorder
preserves the order of the elements inserted into it (that is, it is a FIFO data structure).
See Collection Data Types for examples on creation and usage of the different collections.
Immutable Collections
Some operations, like PgxGraph.getVertices()
and PgxGraph.getEdges()
return immutable collections. These collections behave like normal collections, but cannot be modified by operations like addAll
or removeAll
and clear
.
An immutable collection can be transformed into a mutable collection by using the toMutable
method, which returns a mutable copy of the collection. If toMutable
is called on a collection that is already mutable, the method has the same result as the method clone
.
To check if a collection is mutable, use the isMutable
method.
Maps
PGX provides the following two kinds of maps:
- Graph-bound maps can hold mappings between types in
PropertyType
. This is the kind of maps to use if the key or value types are graph-related likeVERTEX
andEDGE
otherwise using session-bound maps is recommended. - Session-bound maps can map between non graph-related types and are directly bound to the session.
See Map Data Types for examples on creation and usage of maps.