diff --git a/core/src/main/java/org/apache/druid/math/expr/Function.java b/core/src/main/java/org/apache/druid/math/expr/Function.java index a20863929875..420702fe136d 100644 --- a/core/src/main/java/org/apache/druid/math/expr/Function.java +++ b/core/src/main/java/org/apache/druid/math/expr/Function.java @@ -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 diff --git a/docs/misc/math-expr.md b/docs/misc/math-expr.md index dc356479ad58..d16563722bb9 100644 --- a/docs/misc/math-expr.md +++ b/docs/misc/math-expr.md @@ -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 | +|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|