[CSHARP-540] Support Bitwise Operators in LINQ (and possibly Query) Created: 27/Jul/12  Updated: 20/Mar/14  Resolved: 30/Jul/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.5
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Alexander Nagy Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All



 Description   

It's a very common use case in SQL databases to want to perform bitwise operations during queries. While there the server doesn't offer these yet (there are open pull requests to add it), it would be useful if such logic could be implemented in the driver.

Couple ways of doing this off the top of my head:
1. Augment the query with MapReduce; many trivial statements like (x & 2) == 2 or (x & 2) != 0 can be emitted pretty easily, same goes for parameter values that get serialized.
2. Could also special case scenarios where the operation is x & <power of 2 - 1>, since that is equivalent to a $mod; i.e. (x & 3) == 3 would be { x :

{ $mod : [4, 3] }

} and (x & 3) != 0 would be { x : { $not:

{ $mod : [4, 0] }

} }
2a. Of particular interest to this optimization is (x & 1) => (x % 2) which is a relative frequent case.

If one really wanted to exceed expectations, translating any sort of simple arithmetic computation to a JavaScript function would be fantastic and provide lasting value (type safe complex data analysis scenarios for one).



 Comments   
Comment by Craig Wilson [ 30/Jul/12 ]

Since we can't support all the operations all the time, I think it would be confusing and frustrating for users if we only implemented the "convertible" operations. For instance, take the user who passes the right-side value from user input: (x & 2) ==

{user supplied value}

. It works for some values the user supplies and throws on others.

While emitting javascript is also possible, map/reduce is slow and not recommended for using in real-time queries. There is potential in the new aggregation framework but it doesn't support bitwise operations either.

Finally, many of these operations can be rewritten in a way that is support by mongodb. So there is a workaround.

I'm going to close this issue for the above reasons as not going to implement.

Generated at Wed Feb 07 21:37:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.