Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions core/src/main/java/org/apache/druid/math/expr/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,96 @@ protected ExprEval eval(double param)
}
}

class BitwiseAnd extends BivariateMathFunction
{
@Override
public String name()
{
return "bitwiseAnd";
}

@Override
protected ExprEval eval(long x, long y)
{
return ExprEval.of(x & y);
}
}

class BitwiseComplement extends UnivariateMathFunction
{
@Override
public String name()
{
return "bitwiseComplement";
}

@Override
protected ExprEval eval(long param)
{
return ExprEval.of(~param);
}
}

class BitwiseOr extends BivariateMathFunction
{
@Override
public String name()
{
return "bitwiseOr";
}

@Override
protected ExprEval eval(long x, long y)
{
return ExprEval.of(x | y);
}
}

class BitwiseShiftLeft extends BivariateMathFunction
{
@Override
public String name()
{
return "bitwiseShiftLeft";
}

@Override
protected ExprEval eval(long x, long y)
{
return ExprEval.of(x << y);
}
}

class BitwiseShiftRight extends BivariateMathFunction
{
@Override
public String name()
{
return "bitwiseShiftRight";
}

@Override
protected ExprEval eval(long x, long y)
{
return ExprEval.of(x >> y);
}
}

class BitwiseXor extends BivariateMathFunction
{
@Override
public String name()
{
return "bitwiseXor";
}

@Override
protected ExprEval eval(long x, long y)
{
return ExprEval.of(x ^ y);
}
}

class Cbrt extends UnivariateMathFunction
{
@Override
Expand Down
6 changes: 6 additions & 0 deletions docs/misc/math-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ See javadoc of java.lang.Math for detailed explanation for each function.
|acos|acos(x) would return the arc cosine of x|
|asin|asin(x) would return the arc sine of x|
|atan|atan(x) would return the arc tangent of x|
|bitwiseAnd|bitwiseAnd(x,y) would return the result of x & y|
|bitwiseComplement|bitwiseComplement(x) would return the result of ~x|
|bitwiseOr|bitwiseOr(x,y) would return the result of x [PIPE] y |
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added [PIPE] as I had trouble escaping | within the table. Can play with it though if necessary

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&#124; should work (it's done elsewhere in the file, for logical OR).

|bitwiseShiftLeft|bitwiseShiftLeft(x,y) would return the result of x << y|
|bitwiseShiftRight|bitwiseShiftRight(x,y) would return the result of x >> y|
|bitwiseXor|bitwiseXor(x,y) would return the result of x ^ y|
|atan2|atan2(y, x) would return the angle theta from the conversion of rectangular coordinates (x, y) to polar * coordinates (r, theta)|
|cbrt|cbrt(x) would return the cube root of x|
|ceil|ceil(x) would return the smallest (closest to negative infinity) double value that is greater than or equal to x and is equal to a mathematical integer|
Expand Down