diff --git a/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/FunctionRegistry.java b/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/FunctionRegistry.java
index e54027a3313..25915c1a0a8 100644
--- a/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/FunctionRegistry.java
+++ b/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/FunctionRegistry.java
@@ -40,6 +40,7 @@ import org.elasticsearch.xpack.sql.expression.function.scalar.math.Cbrt;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Ceil;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Cos;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Cosh;
+import org.elasticsearch.xpack.sql.expression.function.scalar.math.Cot;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Degrees;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.E;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Exp;
@@ -50,7 +51,9 @@ import org.elasticsearch.xpack.sql.expression.function.scalar.math.Log10;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Pi;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Power;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Radians;
+import org.elasticsearch.xpack.sql.expression.function.scalar.math.Random;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Round;
+import org.elasticsearch.xpack.sql.expression.function.scalar.math.Sign;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Sin;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Sinh;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Sqrt;
@@ -109,9 +112,10 @@ public class FunctionRegistry {
def(ATan.class, ATan::new),
def(ATan2.class, ATan2::new),
def(Cbrt.class, Cbrt::new),
- def(Ceil.class, Ceil::new),
+ def(Ceil.class, Ceil::new, "CEILING"),
def(Cos.class, Cos::new),
def(Cosh.class, Cosh::new),
+ def(Cot.class, Cot::new),
def(Degrees.class, Degrees::new),
def(E.class, E::new),
def(Exp.class, Exp::new),
@@ -124,7 +128,9 @@ public class FunctionRegistry {
def(Pi.class, Pi::new),
def(Power.class, Power::new),
def(Radians.class, Radians::new),
+ def(Random.class, Random::new, "RAND"),
def(Round.class, Round::new),
+ def(Sign.class, Sign::new, "SIGNUM"),
def(Sin.class, Sin::new),
def(Sinh.class, Sinh::new),
def(Sqrt.class, Sqrt::new),
diff --git a/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/math/Cot.java b/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/math/Cot.java
new file mode 100644
index 00000000000..5bb4e0630bb
--- /dev/null
+++ b/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/math/Cot.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+package org.elasticsearch.xpack.sql.expression.function.scalar.math;
+
+import org.elasticsearch.xpack.sql.expression.Expression;
+import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
+import org.elasticsearch.xpack.sql.tree.Location;
+import org.elasticsearch.xpack.sql.tree.NodeInfo;
+
+import java.util.Locale;
+
+import static java.lang.String.format;
+
+/**
+ * Cotangent
+ * function.
+ */
+public class Cot extends MathFunction {
+ public Cot(Location location, Expression field) {
+ super(location, field);
+ }
+
+ @Override
+ protected NodeInfo info() {
+ return NodeInfo.create(this, Cot::new, field());
+ }
+
+ @Override
+ protected Cot replaceChild(Expression newChild) {
+ return new Cot(location(), newChild);
+ }
+
+ @Override
+ protected String formatScript(String template) {
+ return super.formatScript(format(Locale.ROOT, "1.0 / Math.tan(%s)", template));
+ }
+
+ @Override
+ protected MathOperation operation() {
+ return MathOperation.COT;
+ }
+}
diff --git a/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/math/MathProcessor.java b/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/math/MathProcessor.java
index 38889ecb43b..b9bf56f33a4 100644
--- a/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/math/MathProcessor.java
+++ b/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/math/MathProcessor.java
@@ -5,12 +5,14 @@
*/
package org.elasticsearch.xpack.sql.expression.function.scalar.math;
+import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.Processor;
import java.io.IOException;
+import java.util.Random;
import java.util.function.DoubleFunction;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -26,6 +28,7 @@ public class MathProcessor implements Processor {
return Math.abs(((Double) l).doubleValue());
}
long lo = ((Number) l).longValue();
+ //handles the corner-case of Long.MIN_VALUE
return lo >= 0 ? lo : lo == Long.MIN_VALUE ? Long.MAX_VALUE : -lo;
}),
@@ -36,6 +39,7 @@ public class MathProcessor implements Processor {
CEIL(Math::ceil),
COS(Math::cos),
COSH(Math::cosh),
+ COT((Object l) -> 1.0d / Math.tan(((Number) l).doubleValue())),
DEGREES(Math::toDegrees),
E(() -> Math.E),
EXP(Math::exp),
@@ -45,7 +49,11 @@ public class MathProcessor implements Processor {
LOG10(Math::log10),
PI(() -> Math.PI),
RADIANS(Math::toRadians),
+ RANDOM((Object l) -> l != null ?
+ new Random(((Number) l).longValue()).nextDouble() :
+ Randomness.get().nextDouble(), true),
ROUND((DoubleFunction