openCypher
openCypher copied to clipboard
Bitwise operators
CIR-2017-260
Some applications have a need of performing bitwise operations on bit vectors (or fixed-size binary integers). It would be advantageous to be able to perform such operations in Cypher, since query results might depend on such operations. Having the ability to perform bitwise operators in Cypher saves the application from having to request more data than strictly required from the database, and from having to do post-filtering of the returned data.
Request
Add support for bitwise operators in Cypher between some bit-centric data types.
Suggestions
There are two main routes for supporting this feature. Either we introduce a specific sized bit vector type on which we support bitwise operators, along with functions for converting between numbers and bit vectors. Or we introduce machine-sized integer types and support bitwise operators on those values (although mathematical operators on such machine-sized integers would probably need to coerce to mathematical integers in order to avoid overflows).
This has been requested as a feature for Neo4j in neo4j/neo4j#5092, but since it requires additions to the Cypher language, it really should be handled through the openCypher process.
Is there any action on this topic? This functionality would really help.
I also want to know if there is any news on this topic? Or at least is there a suggestion on how to model bits and do bitwise operations in graphs (neo4j) and cypher?
I'd think that adding element-wise AND and OR operators for lists, with general semantics defined as
[true, false, true] opAnd [false, false, true]
=> [true AND false, false AND false, true AND true]
=> [false, false, true]
[true, false, true] opOr [false, false, true]
=> [true OR false, false OR false, true OR true]
=> [true, false, true]
would come a long way of solving most use-cases. This needn't be limited to booleans, although I don't know what AND and OR semantics would be applicable to other types. If indeed there aren't any, opAnd
and opOr
above may indeed just be extended definitions of Cypher's current AND
and OR
operators, where lists of booleans would become accepted operands.