Differences between Ladybug and Neo4j
If you’re coming over from Neo4j, you can find the differences from Neo4j’s keywords and syntax in this section. Note that as far as possible, Ladybug tries to follow openCypher’s syntax and semantics.
Schema
Unlike Neo4j, Ladybug requires a schema to be defined before any data can be inserted into the database (we call this the “structured property graph model”). The schema provides a logical grouping of node and relationship tables, along with their associated properties and data types that define the structure of the graph database. See our DDL docs for more information.
Clauses
CREATE and MERGE
We recommend always specifying node and relationship labels explicitly in the CREATE and MERGE clauses.
However, if not specified, Ladybug will try to infer the label by looking at the schema.
FINISH
FINISH is recently introduced in GQL and adopted by Neo4j but not yet supported in Ladybug. You can use RETURN COUNT(*) instead which will only return one record.
FOREACH
FOREACH is not supported. You can use UNWIND instead.
LOAD CSV FROM
Ladybug can scan files not only in the format of CSV, so the LOAD CSV FROM clause is renamed to LOAD FROM.
Semantics
Neo4j adopts a trail semantic (no repeated edge) for pattern within a MATCH clause, whereas Ladybug adopts walk semantic
(allowing repeated edge) for pattern within a MATCH clause.
In Ladybug, you can use is_trail or is_acyclic function to check if a path is a trail or acyclic.
Variable length relationships
Since Ladybug adopts a walk semantic by default, so a variable length relationship needs to have a upper bound to guarantee the query will terminate. If upper bound is not specified, Ladybug will assign a default value of 30.
Ladybug also extends Neo4j’s variable length to support filter inside the variable length relationship.
To run algorithms like (all) shortest path, simply add SHORTEST or ALL SHORTEST between the kleene star and lower bound. For example, MATCH (n)-[r* SHORTEST 1..10]->(m). It is recommended to use SHORTEST if paths are not needed in the use case.
More information can be found in the MATCH documentation page.
REMOVE
REMOVE is not supported. Use SET n.prop = NULL instead.
SET
Properties must be updated in the form of n.prop = expression. Update all properties with map of += operator is not supported. Try to update properties one by one.
USE
USE graph is not supported. For Ladybug, each graph is a database. You can use different graph by opening different databases.
WHERE
Using WHERE inside node or relationship pattern is not supported, e.g. MATCH (n:Person WHERE a.name = 'Andy') RETURN n. You need to write it as MATCH (n:Person) WHERE n.name = 'Andy' RETURN n.
Filter on node or relationship labels is not supported, e.g. MATCH (n) WHERE n:Person RETURN n. You need to write it as MATCH (n:Person) RETURN n, or MATCH (n) WHERE label(n) = 'Person' RETURN n.
Others
Any SHOW XXX clauses become a function call in Ladybug. For example, SHOW FUNCTIONS in Neo4j is equivalent to CALL show_functions() RETURN * in Ladybug. For more information, see the functions page.
Subqueries
Ladybug supports EXISTS and COUNT subquery. See Subqueries for more information.
CALL <subquery> is not supported.
Data Types
Ladybug follows the Postgres typing system. For LIST type, all elements should be of the same type. For MAP type, all keys should be of the same type and all values should be of the same type. For more information, see data types.
Functions
labels()function is namedlabel()instead.- type predicate expression
n.property IS :: INTEGERis supported astypeOf(n.property)=INT64 - internal id function
elementIdis supported asid(). - spatial functions are not supported.
Aggregate functions
percentileCont,percentileDisc,stDevandstDevPare supported.
List functions
- Most list functions have a
list_prefix, e.g.list_concat,list_reverse,list_reduce, etc… tailis supported aslist_slice().headandtailare supported aslist_extract()orlist[].
Casting functions
toXXXfunctions in Neo4j are supported in Ladybug via thecast(input, targetType)function
Mathematical functions
isNaNis not supported.e()is not supported.haversinis not supported.pi()is not supported.
String functions
char_lengthandcharacter_lengthare supported assize.
Temporal functions
date()is supported ascurrent_date().timestamp()is supported ascurrent_timestamp().- local datetime, real time clock, transaction time clock are not supported.
Vector similarity functions
- cosine similarity is named as
ARRAY_COSINE_SIMILARITY() - euclidean distance is named as
ARRAY_DISTANCE()
Indexes and Constraints
Ladybug does not currently support manually creating indexes or constraints on custom properties. Instead, Ladybug creates a primary key index (which also guarantees non-null and uniqueness) the user-specified primary key column of a node table.