openCypher icon indicating copy to clipboard operation
openCypher copied to clipboard

Bitwise operators

Open thobe opened this issue 6 years ago • 4 comments

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).

thobe avatar Oct 06 '17 09:10 thobe

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.

thobe avatar Oct 06 '17 09:10 thobe

Is there any action on this topic? This functionality would really help.

Berkla avatar Feb 18 '19 16:02 Berkla

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?

MPasadu avatar Mar 22 '19 14:03 MPasadu

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.

Mats-SX avatar Jul 26 '19 14:07 Mats-SX