Skip to content

Feature request: Implement bitwise operators & and | #8560

@teyeheimans

Description

@teyeheimans

Description

Currently it is not possible to do a bitwise operator expression. The only way to do this now is by using a javascript function to do the bitwise logic.

I would suggest to build in the bitwise operators & and | to the druid expressions: https://druid.apache.org/docs/latest/misc/math-expr.html

Motivation

In many situations we use a "flags" field, where every bit is a feature which can be enabled or disabled. In this way we can store a lot of boolean fields in just 1 decimal field.

We can then simply check if the specific bit is enabled by doing a bitwise and:

(flags & 16) = 16

In the current situation we solved this by a very complex way using a javascript function like this (replace %BIT_TO_CHECK% with the value to check:

function(v1) { var v2 = %BIT_TO_CHECK%; var hi = 0x80000000; var low = 0x7fffffff; var hi1 = ~~(v1 / hi); var hi2 = ~~(v2 / hi); var low1 = v1 & low; var low2 = v2 & low; var h = hi1 & hi2; var l = low1 & low2; return (h*hi + l) == v2; }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions