Skip to content

Logical Partition

Users may define logical partitions when executing Cypher queries, which are automatically applied to all nodes and relationships involved in the query operation. Unlike physical data partitioning, logical partitions can be imposed across all columns within the data source.

Usage

Basic Logical Partition with Equal Conditions

USING {
    logicalPartition: { foo: 'value1', bar: 42},
}
MATCH (n:A)-[r:R]->(m:B)
RETURN n, m

This query adds filters to n, r, and m, working the same as:

MATCH (n:A)-[r:R]->(m:B)
WHERE 
  n.foo = 'value1'
  AND n.bar = 42
  AND r.foo = 'value1'
  AND r.bar = 42
  AND m.foo = 'value1'
  AND m.bar = 42
RETURN n, m

Logical partition will also be applied to anonymous nodes / relationships.

USING {
    logicalPartition: { foo: 'value1', bar: 42},
}
MATCH (n:A)-[:R]->(m:B)
RETURN n, m

This query will get the same result as the previous one.

Using Different Comparison Operators

Supported operators include =, <>, >, <, >=, <=, IS NULL, and IS NOT NULL.

USING {
  logicalPartition: [foo IS NOT NULL, bar > 42]  
}
MATCH (n:A)-[r:R]->(m:B)
RETURN n, r, m

This applies filters to n, r, and m, equivalent to:

MATCH (n:A)-[r:R]->(m:B)
WHERE 
  n.foo IS NOT NULL
  AND n.bar > 42
  AND r.foo IS NOT NULL
  AND r.bar > 42
  AND m.foo IS NOT NULL
  AND m.bar > 42
RETURN n, r, m

DATE / DATETIME data

If the value of partition is DATE OR DATETIME, the value should be a valid date/datetime string with format yyyy-MM-dd or yyyy-MM-dd HH:mm:ss

Handling Missing Partition Attributes

By default, all nodes and relationships must have the partition attributes, or an error will be raised. You can change this by enabling allowUnpartitionedElements option.

USING {
  logicalPartition: [foo = 10, bar > 42],
  allowUnpartitionedElements: True
}
MATCH (n:A)-[r:R]->(m:B)
RETURN n, r, m

When allowUnpartitionedElements is enabled, the equivalent query becomes:

MATCH (n:A)-[r:R]->(m:B)
WHERE 
  (n.foo = 10 OR n.foo IS NULL)
  AND (n.bar > 42 OR n.bar IS NULL)
  AND (r.foo = 10 OR r.foo IS NULL)
  AND (r.bar > 42 OR r.bar IS NULL)
  AND (m.foo = 10 OR m.foo IS NULL)
  AND (m.bar > 42 OR m.bar IS NULL)
RETURN n, r, m

Dealing with Inconsistent Data

Logical partition assumes all connected elements belong to the same partition. If some connections cross partitions in your data, you might get wrong results. For accurate results in this case, set logicalPartitionConsistency option to False.

USING {
  logicalPartition: [foo = 10, bar > 42],
  logicalPartitionConsistency: False
}
MATCH (n:A)-[r:R]->(m:B)
RETURN n, r, m