Neo4j / Spark Data Types Reference

This chapter provides a reference to type compatibility issues between Neo4j and Spark

Background

Neo4j and Cypher provide a type system that describes how values are stored in the database, but these types do not always exactly match what Spark provides.

In some cases there are types that Neo4j provides that Spark does not have an equivalent for, and vice versa.

Type Mappings

Table 1. Spark to Neo4j Type Mappings Reference
Neo4j Type Spark Type Notes

String

string

Example: "Hello"

Integer

long

Example: 12345

Float

double

Example: 3.141592

Boolean

boolean

Example: true

Point

struct { type: string, srid: integer, x: double, y: double, z: double }

For more information on spatial types in Neo4j, see Spatial values

Date

date

Example: 2020-09-11

Time

struct { type: string, value: string }

Example: [offset-time, 12:14:08.209Z]

LocalTime

struct { type: string, value: string }

Example: [local-time, 12:18:11.628]

DateTime

timestamp

Example: 2020-09-11 12:17:39.192

LocalDateTime

timestamp

Example: 2020-09-11 12:14:49.081

Duration

struct { type: string, months: long, days: long, seconds: long, nanonseconds: integer, value: string }

See Temporal functions: duration

Node

struct { <id>: long, <labels>: array[string], (PROPERTIES) }

Nodes in Neo4j are represented as property containers; that is they appear as structs with properties corresponding to whatever properties were in the node. For ease of use it is usually better to return individual properties than a node from a query

Relationship

struct { <rel.id>: long, <rel.type>: string, <source.id>: long, <target.id>: long, (PROPERTIES) }

Relationships are returned as maps, identifying the source and target of the relationship, its type, along with properties (if any) of the relationship. For ease of use it is usually better to return individual properties than a relationship from a query

Path

string

Example: path[(322)←[20280:AIRLINE]-(33510)]. _For ease of use it is recommended to use path functions to return individual properties/aspects of a path from a query.

[Array of Same Type]

array[element]

In Neo4j, arrays must be consistently typed (i.e. an array of all Float values). The inner spark type matches the type mapping above.